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
34
35
36
37
38
39
40
41
42
/// ProtectionProfile specifies Cipher and AuthTag details, similar to TLS cipher suite
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum ProtectionProfile {
    Aes128CmHmacSha1_80 = 0x0001,
    AeadAes128Gcm = 0x0007,
}

impl Default for ProtectionProfile {
    fn default() -> Self {
        ProtectionProfile::Aes128CmHmacSha1_80
    }
}

impl ProtectionProfile {
    pub(crate) fn key_len(&self) -> usize {
        match *self {
            ProtectionProfile::Aes128CmHmacSha1_80 | ProtectionProfile::AeadAes128Gcm => 16,
        }
    }

    pub(crate) fn salt_len(&self) -> usize {
        match *self {
            ProtectionProfile::Aes128CmHmacSha1_80 => 14,
            ProtectionProfile::AeadAes128Gcm => 12,
        }
    }

    pub(crate) fn auth_tag_len(&self) -> usize {
        match *self {
            ProtectionProfile::Aes128CmHmacSha1_80 => 10, //CIPHER_AES_CM_HMAC_SHA1AUTH_TAG_LEN,
            ProtectionProfile::AeadAes128Gcm => 16,       //CIPHER_AEAD_AES_GCM_AUTH_TAG_LEN,
        }
    }

    pub(crate) fn auth_key_len(&self) -> usize {
        match *self {
            ProtectionProfile::Aes128CmHmacSha1_80 => 20,
            ProtectionProfile::AeadAes128Gcm => 0,
        }
    }
}