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