bitwarden_crypto/traits/
mod.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
34
35
36
37
38
39
40
41
mod encryptable;
pub use encryptable::Encryptable;
mod decryptable;
pub use decryptable::Decryptable;

pub(crate) mod key_id;
pub use key_id::{KeyId, KeyIds};

/// Types implementing [IdentifyKey] are capable of knowing which cryptographic key is
/// needed to encrypt/decrypt them.
pub trait IdentifyKey<Key: KeyId> {
    fn key_identifier(&self) -> Key;
}

#[cfg(test)]
pub(crate) mod tests {
    use crate::key_ids;
    key_ids! {
        #[symmetric]
        pub enum TestSymmKey {
            A(u8),

            // We only support one variant value,
            // but that value can be a tuple
            B((u8, u8)),

            #[local]
            C(u8),
        }

        #[asymmetric]
        pub enum TestAsymmKey {
            A(u8),
            B,
            #[local]
            C(&'static str),
        }

       pub TestIds => TestSymmKey, TestAsymmKey;
    }
}