use super::{Algorithm, AlgorithmError, AlgorithmErrorKind::TagInvalid};
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[allow(non_camel_case_types)]
#[repr(u8)]
pub enum OtpAlg {
AES128 = 0x25,
AES192 = 0x27,
AES256 = 0x28,
}
impl OtpAlg {
pub fn from_u8(tag: u8) -> Result<Self, AlgorithmError> {
Ok(match tag {
0x25 => OtpAlg::AES128,
0x27 => OtpAlg::AES192,
0x28 => OtpAlg::AES256,
_ => fail!(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 {
OtpAlg::AES128 => 16,
OtpAlg::AES192 => 24,
OtpAlg::AES256 => 32,
}
}
}
impl From<OtpAlg> for Algorithm {
fn from(alg: OtpAlg) -> Algorithm {
Algorithm::Otp(alg)
}
}
impl_algorithm_serializers!(OtpAlg);