use crate::algorithm;
use anomaly::fail;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum Algorithm {
Sha1 = 0x01,
Sha256 = 0x02,
Sha384 = 0x03,
Sha512 = 0x04,
}
impl Algorithm {
pub fn from_u8(tag: u8) -> Result<Self, algorithm::Error> {
Ok(match tag {
0x01 => Algorithm::Sha1,
0x02 => Algorithm::Sha256,
0x03 => Algorithm::Sha384,
0x04 => Algorithm::Sha512,
_ => fail!(
algorithm::ErrorKind::TagInvalid,
"unknown RSASSA-PKCS#1v1.5 algorithm ID: 0x{:02x}",
tag
),
})
}
pub fn to_u8(self) -> u8 {
self as u8
}
}
impl_algorithm_serializers!(Algorithm);