quantcrypt/kdf/common/
kdf_type.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::kdf::common::config::oids::Oid;
use strum::IntoEnumIterator;
use strum_macros::EnumIter;

/// Define the KDF types
#[derive(Clone, Debug, PartialEq, EnumIter)]
pub enum KdfType {
    /// Hkdf with SHA-256
    HkdfWithSha256,
    /// Hkdf with SHA-512
    HkdfWithSha384,
    /// Hkdf with SHA-512
    HkdfWithSha512,
    /// Kmac with 128-bit key
    Kmac128,
    /// Kmac with 256-bit key
    Kmac256,
}

impl KdfType {
    /// Get all KDF types
    pub fn all() -> Vec<KdfType> {
        KdfType::iter().collect()
    }

    /// Get the OID of the KDF
    pub fn from_oid(oid: &str) -> Option<KdfType> {
        let all_kdf_types = KdfType::all();
        all_kdf_types
            .into_iter()
            .find(|kdf_type| kdf_type.get_oid() == oid)
    }
}