use crate::algorithm;
use anomaly::fail;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum Algorithm {
Sha1 = 0x19,
Sha256 = 0x1a,
Sha384 = 0x1b,
Sha512 = 0x1c,
}
impl Algorithm {
pub fn from_u8(tag: u8) -> Result<Self, algorithm::Error> {
Ok(match tag {
0x19 => Algorithm::Sha1,
0x1a => Algorithm::Sha256,
0x1b => Algorithm::Sha384,
0x1c => Algorithm::Sha512,
_ => fail!(
algorithm::ErrorKind::TagInvalid,
"unknown RSA OAEP algorithm ID: 0x{:02x}",
tag
),
})
}
pub fn to_u8(self) -> u8 {
self as u8
}
}
impl_algorithm_serializers!(Algorithm);