1
1
use super :: {
2
2
kdf:: { Kdf , KdfDerivedKeyMaterial } ,
3
- master_key:: { decrypt_user_key, encrypt_user_key } ,
3
+ master_key:: decrypt_user_key,
4
4
utils:: stretch_key,
5
5
} ;
6
6
use crate :: {
7
- keys:: key_encryptable:: CryptoKey , ContentFormat , EncString , KeyEncryptable ,
8
- KeyEncryptableWithContentType , Result , SymmetricCryptoKey ,
7
+ keys:: key_encryptable:: CryptoKey , EncString , KeyEncryptable , Result , SymmetricCryptoKey ,
9
8
} ;
10
9
11
10
/// Pin Key.
@@ -21,7 +20,7 @@ impl PinKey {
21
20
22
21
/// Encrypt the users user key
23
22
pub fn encrypt_user_key ( & self , user_key : & SymmetricCryptoKey ) -> Result < EncString > {
24
- encrypt_user_key ( & self . 0 . 0 , user_key )
23
+ user_key . encrypt_with_key ( & self )
25
24
}
26
25
27
26
/// Decrypt the users user key
@@ -32,15 +31,18 @@ impl PinKey {
32
31
33
32
impl CryptoKey for PinKey { }
34
33
35
- impl KeyEncryptableWithContentType < PinKey , EncString > for & [ u8 ] {
36
- fn encrypt_with_key ( self , key : & PinKey , content_format : ContentFormat ) -> Result < EncString > {
34
+ impl KeyEncryptable < PinKey , EncString > for & SymmetricCryptoKey {
35
+ fn encrypt_with_key ( self , key : & PinKey ) -> Result < EncString > {
37
36
let stretched_key = SymmetricCryptoKey :: Aes256CbcHmacKey ( stretch_key ( & key. 0 . 0 ) ?) ;
38
- self . encrypt_with_key ( & stretched_key, content_format)
37
+ // The (stretched) pin key is currently always an AES-256-CBC-HMAC key, and wraps a bitwarden legacy encoded symmetric key
38
+ self . to_encoded ( ) . encrypt_with_key ( & stretched_key)
39
39
}
40
40
}
41
41
42
42
impl KeyEncryptable < PinKey , EncString > for String {
43
43
fn encrypt_with_key ( self , key : & PinKey ) -> Result < EncString > {
44
- self . as_bytes ( ) . encrypt_with_key ( key, ContentFormat :: Utf8 )
44
+ self . encrypt_with_key ( & SymmetricCryptoKey :: Aes256CbcHmacKey ( stretch_key (
45
+ & key. 0 . 0 ,
46
+ ) ?) )
45
47
}
46
48
}
0 commit comments