ipmi_rs_core/app/auth/
algorithms.rs

1#![allow(missing_docs)]
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
4pub enum AuthenticationAlgorithm {
5    RakpNone,
6    RakpHmacSha1,
7    RakpHmacMd5,
8    RakpHmacSha256,
9}
10
11impl From<AuthenticationAlgorithm> for u8 {
12    fn from(value: AuthenticationAlgorithm) -> Self {
13        match value {
14            AuthenticationAlgorithm::RakpNone => 0x00,
15            AuthenticationAlgorithm::RakpHmacSha1 => 0x01,
16            AuthenticationAlgorithm::RakpHmacMd5 => 0x02,
17            AuthenticationAlgorithm::RakpHmacSha256 => 0x03,
18        }
19    }
20}
21
22impl TryFrom<u8> for AuthenticationAlgorithm {
23    type Error = ();
24
25    fn try_from(value: u8) -> Result<Self, Self::Error> {
26        let value = match value {
27            0x00 => Self::RakpNone,
28            0x01 => Self::RakpHmacSha1,
29            0x02 => Self::RakpHmacMd5,
30            0x03 => Self::RakpHmacSha256,
31            _ => return Err(()),
32        };
33
34        Ok(value)
35    }
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
39pub enum ConfidentialityAlgorithm {
40    None,
41    AesCbc128,
42    Xrc4_128,
43    Xrc4_40,
44}
45
46impl TryFrom<u8> for ConfidentialityAlgorithm {
47    type Error = ();
48
49    fn try_from(value: u8) -> Result<Self, Self::Error> {
50        let value = match value {
51            0x00 => Self::None,
52            0x01 => Self::AesCbc128,
53            0x02 => Self::Xrc4_128,
54            0x03 => Self::Xrc4_40,
55            _ => return Err(()),
56        };
57
58        Ok(value)
59    }
60}
61
62impl From<ConfidentialityAlgorithm> for u8 {
63    fn from(value: ConfidentialityAlgorithm) -> Self {
64        match value {
65            ConfidentialityAlgorithm::None => 0x00,
66            ConfidentialityAlgorithm::AesCbc128 => 0x01,
67            ConfidentialityAlgorithm::Xrc4_128 => 0x02,
68            ConfidentialityAlgorithm::Xrc4_40 => 0x03,
69        }
70    }
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
74pub enum IntegrityAlgorithm {
75    None,
76    HmacSha1_96,
77    HmacMd5_128,
78    Md5_128,
79    HmacSha256_128,
80}
81
82impl TryFrom<u8> for IntegrityAlgorithm {
83    type Error = ();
84
85    fn try_from(value: u8) -> Result<Self, Self::Error> {
86        let value = match value {
87            0x00 => Self::None,
88            0x01 => Self::HmacSha1_96,
89            0x02 => Self::HmacMd5_128,
90            0x03 => Self::Md5_128,
91            0x04 => Self::HmacSha256_128,
92            _ => return Err(()),
93        };
94
95        Ok(value)
96    }
97}
98
99impl From<IntegrityAlgorithm> for u8 {
100    fn from(value: IntegrityAlgorithm) -> Self {
101        match value {
102            IntegrityAlgorithm::None => 0x00,
103            IntegrityAlgorithm::HmacSha1_96 => 0x01,
104            IntegrityAlgorithm::HmacMd5_128 => 0x02,
105            IntegrityAlgorithm::Md5_128 => 0x03,
106            IntegrityAlgorithm::HmacSha256_128 => 0x04,
107        }
108    }
109}