Skip to content

Commit f145eb3

Browse files
committed
Fix clippy errors
1 parent 02cc7b3 commit f145eb3

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

crates/bitwarden-core/src/client/encryption_settings.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub enum EncryptionSettingsError {
2727
#[error("Invalid private key")]
2828
InvalidPrivateKey,
2929

30+
#[error("Invalid signing key")]
31+
InvalidSigningKey,
32+
3033
#[error(transparent)]
3134
MissingPrivateKey(#[from] MissingPrivateKeyError),
3235

@@ -72,26 +75,26 @@ impl EncryptionSettings {
7275
// .map_err(|_| EncryptionSettingsError::InvalidPrivateKey)?,
7376
// )
7477
};
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-
});
8278

8379
// FIXME: [PM-18098] When this is part of crypto we won't need to use deprecated methods
8480
#[allow(deprecated)]
8581
{
8682
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-
}
9183

9284
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)?;
9390
ctx.set_signing_key(SigningKeyId::UserSigningKey, signing_key)?;
9491
}
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)?;
9598
}
9699

97100
Ok(())

0 commit comments

Comments
 (0)