yubihsm/authentication/
algorithm.rs1use crate::algorithm;
4
5#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
7#[repr(u8)]
8pub enum Algorithm {
9 #[default]
11 YubicoAes = 0x26,
12}
13
14impl Algorithm {
15 pub fn from_u8(tag: u8) -> Result<Self, algorithm::Error> {
17 Ok(match tag {
18 0x26 => Algorithm::YubicoAes,
19 _ => fail!(
20 algorithm::ErrorKind::TagInvalid,
21 "unknown auth algorithm ID: 0x{:02x}",
22 tag
23 ),
24 })
25 }
26
27 pub fn to_u8(self) -> u8 {
29 self as u8
30 }
31
32 pub fn key_len(self) -> usize {
34 match self {
35 Algorithm::YubicoAes => 32,
36 }
37 }
38}
39
40impl_algorithm_serializers!(Algorithm);