@@ -27,6 +27,9 @@ pub enum EncryptionSettingsError {
27
27
#[ error( "Invalid private key" ) ]
28
28
InvalidPrivateKey ,
29
29
30
+ #[ error( "Invalid signing key" ) ]
31
+ InvalidSigningKey ,
32
+
30
33
#[ error( transparent) ]
31
34
MissingPrivateKey ( #[ from] MissingPrivateKeyError ) ,
32
35
@@ -72,26 +75,26 @@ impl EncryptionSettings {
72
75
// .map_err(|_| EncryptionSettingsError::InvalidPrivateKey)?,
73
76
// )
74
77
} ;
75
- let signing_key = signing_key. map ( |key| {
76
- use bitwarden_crypto:: { CoseKeyContentFormat , SerializedBytes } ;
77
-
78
- let dec: Vec < u8 > = key. decrypt_with_key ( & user_key) . unwrap ( ) ;
79
- let dec: SerializedBytes < CoseKeyContentFormat > = SerializedBytes :: from ( dec) ;
80
- SigningKey :: from_cose ( & dec) . unwrap ( )
81
- } ) ;
82
78
83
79
// FIXME: [PM-18098] When this is part of crypto we won't need to use deprecated methods
84
80
#[ allow( deprecated) ]
85
81
{
86
82
let mut ctx = store. context_mut ( ) ;
87
- ctx. set_symmetric_key ( SymmetricKeyId :: User , user_key) ?;
88
- if let Some ( private_key) = private_key {
89
- ctx. set_asymmetric_key ( AsymmetricKeyId :: UserPrivateKey , private_key) ?;
90
- }
91
83
92
84
if let Some ( signing_key) = signing_key {
85
+ use bitwarden_crypto:: SerializedBytes ;
86
+
87
+ let dec: Vec < u8 > = signing_key. decrypt_with_key ( & user_key) . unwrap ( ) ;
88
+ let signing_key = SigningKey :: from_cose ( & SerializedBytes :: from ( dec) )
89
+ . map_err ( |_| EncryptionSettingsError :: InvalidSigningKey ) ?;
93
90
ctx. set_signing_key ( SigningKeyId :: UserSigningKey , signing_key) ?;
94
91
}
92
+
93
+ if let Some ( private_key) = private_key {
94
+ ctx. set_asymmetric_key ( AsymmetricKeyId :: UserPrivateKey , private_key) ?;
95
+ }
96
+
97
+ ctx. set_symmetric_key ( SymmetricKeyId :: User , user_key) ?;
95
98
}
96
99
97
100
Ok ( ( ) )
0 commit comments