envelop/
lib.rs

1mod envelop {
2    use std::error::Error;
3    use std::str::FromStr;
4
5    struct Key {
6        identifier: String,
7        bytes: Vec<u8>,
8    }
9
10    struct ServiceIdentifier(String);
11    struct ParentKeyIdentifier(String);
12    struct KeyIdentifier(String);
13
14    enum Keys {
15        HSMKey(ServiceIdentifier, KeyIdentifier),
16        MasterKey(ServiceIdentifier, ParentKeyIdentifier),
17        KeyReference(KeyIdentifier, ParentKeyIdentifier),
18        DataKey(ParentKeyIdentifier)
19    }
20
21    trait Payload {
22    }
23
24    trait HSMService {
25    }
26
27    enum Services {
28        AWS
29    }
30
31    impl HSMService for Services {
32    }
33
34    trait EnvelopError: Error {
35    }
36
37    struct EncryptionResult {
38    }
39
40    fn create_hsm_protected_key<Service: HSMService>(hsm_service: Service) -> Result<Key, Box<dyn EnvelopError>>  {
41        return Ok(Key { identifier: String::from_str("").unwrap(), bytes: Vec::new() })
42    }
43
44    fn create_wrapping_key() -> Key {
45        return Key { identifier: String::from_str("").unwrap(),bytes: Vec::new() }
46    }
47
48    fn encrypt<Data: Payload>(key: Key, payload: Data) -> Result<EncryptionResult, Box<dyn EnvelopError>> {
49        return Ok(EncryptionResult {})
50    }
51
52    fn decrypt(encrypted_data: EncryptionResult) -> Result<Vec<u8>, Box<dyn EnvelopError>> {
53        return Ok(Vec::new())
54    }
55}
56
57
58#[cfg(test)]
59mod tests {
60    #[test]
61    fn it_works() {
62        assert_eq!(2 + 2, 4);
63    }
64}