use crate::algorithm;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[allow(non_camel_case_types)]
#[repr(u8)]
pub enum Algorithm {
AES128 = 0x25,
AES192 = 0x27,
AES256 = 0x28,
}
impl Algorithm {
pub fn from_u8(tag: u8) -> Result<Self, algorithm::Error> {
Ok(match tag {
0x25 => Algorithm::AES128,
0x27 => Algorithm::AES192,
0x28 => Algorithm::AES256,
_ => fail!(
algorithm::ErrorKind::TagInvalid,
"unknown OTP algorithm ID: 0x{:02x}",
tag
),
})
}
pub fn to_u8(self) -> u8 {
self as u8
}
pub fn key_len(self) -> usize {
match self {
Algorithm::AES128 => 16,
Algorithm::AES192 => 24,
Algorithm::AES256 => 32,
}
}
}
impl_algorithm_serializers!(Algorithm);