use super::{Algorithm, AlgorithmError, AlgorithmErrorKind::TagInvalid};
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[allow(non_camel_case_types)]
#[repr(u8)]
pub enum MgfAlg {
SHA1 = 0x20,
SHA256 = 0x21,
SHA384 = 0x22,
SHA512 = 0x23,
}
impl MgfAlg {
pub fn from_u8(tag: u8) -> Result<Self, AlgorithmError> {
Ok(match tag {
0x20 => MgfAlg::SHA1,
0x21 => MgfAlg::SHA256,
0x22 => MgfAlg::SHA384,
0x23 => MgfAlg::SHA512,
_ => fail!(TagInvalid, "unknown MGF algorithm ID: 0x{:02x}", tag),
})
}
pub fn to_u8(self) -> u8 {
self as u8
}
}
impl From<MgfAlg> for Algorithm {
fn from(alg: MgfAlg) -> Algorithm {
Algorithm::Mgf(alg)
}
}
impl_algorithm_serializers!(MgfAlg);