use crate::algorithm;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[allow(non_camel_case_types)]
#[repr(u8)]
pub enum Algorithm {
PKCS1_SHA1 = 0x01,
PKCS1_SHA256 = 0x02,
PKCS1_SHA384 = 0x03,
PKCS1_SHA512 = 0x04,
PSS_SHA1 = 0x05,
PSS_SHA256 = 0x06,
PSS_SHA384 = 0x07,
PSS_SHA512 = 0x08,
OAEP_SHA1 = 0x19,
OAEP_SHA256 = 0x1a,
OAEP_SHA384 = 0x1b,
OAEP_SHA512 = 0x1c,
}
impl Algorithm {
pub fn from_u8(tag: u8) -> Result<Self, algorithm::Error> {
Ok(match tag {
0x01 => Algorithm::PKCS1_SHA1,
0x02 => Algorithm::PKCS1_SHA256,
0x03 => Algorithm::PKCS1_SHA384,
0x04 => Algorithm::PKCS1_SHA512,
0x05 => Algorithm::PSS_SHA1,
0x06 => Algorithm::PSS_SHA256,
0x07 => Algorithm::PSS_SHA384,
0x08 => Algorithm::PSS_SHA512,
0x19 => Algorithm::OAEP_SHA1,
0x1a => Algorithm::OAEP_SHA256,
0x1b => Algorithm::OAEP_SHA384,
0x1c => Algorithm::OAEP_SHA512,
_ => fail!(
algorithm::ErrorKind::TagInvalid,
"unknown RSA algorithm ID: 0x{:02x}",
tag
),
})
}
pub fn to_u8(self) -> u8 {
self as u8
}
}
impl_algorithm_serializers!(Algorithm);