hmac_serialiser/
algorithm.rs1#[cfg(feature = "ring")]
2use ring::{hkdf, hmac};
3
4#[derive(Default, Clone, Debug)]
5pub enum Algorithm {
6 SHA1,
7 #[default]
8 SHA256,
9 SHA384,
10 SHA512,
11}
12
13impl Algorithm {
14 #[inline]
15 pub fn output_length(&self) -> usize {
16 match self {
17 Algorithm::SHA1 => 20,
18 Algorithm::SHA256 => 32,
19 Algorithm::SHA384 => 48,
20 Algorithm::SHA512 => 64,
21 }
22 }
23
24 #[cfg(feature = "ring")]
25 pub fn to_hmac(&self) -> hmac::Algorithm {
26 match self {
27 Algorithm::SHA1 => hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY,
28 Algorithm::SHA256 => hmac::HMAC_SHA256,
29 Algorithm::SHA384 => hmac::HMAC_SHA384,
30 Algorithm::SHA512 => hmac::HMAC_SHA512,
31 }
32 }
33
34 #[cfg(feature = "ring")]
35 pub fn to_hkdf(&self) -> hkdf::Algorithm {
36 match self {
37 Algorithm::SHA1 => hkdf::HKDF_SHA1_FOR_LEGACY_USE_ONLY,
38 Algorithm::SHA256 => hkdf::HKDF_SHA256,
39 Algorithm::SHA384 => hkdf::HKDF_SHA384,
40 Algorithm::SHA512 => hkdf::HKDF_SHA512,
41 }
42 }
43}