Skip to content

Commit 9d39345

Browse files
committed
Fix tests
1 parent 6357c36 commit 9d39345

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

crates/bitwarden-crypto/src/key_rotation/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct RotatedUserKeys {
1919

2020
/// Re-encrypts the user's keys with the provided symmetric key for a v2 user.
2121
pub(crate) fn get_v2_rotated_account_keys<Ids: crate::KeyIds>(
22-
new_user_key: SymmetricCryptoKey,
22+
new_user_key: &SymmetricCryptoKey,
2323
current_user_private_key_id: Ids::Asymmetric,
2424
current_user_signing_key_id: Ids::Signing,
2525
ctx: &KeyStoreContext<Ids>,

crates/bitwarden-crypto/src/store/context.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<Ids: KeyIds> KeyStoreContext<'_, Ids> {
519519
/// Re-encrypts the user's keys with the provided symmetric key for a v2 user.
520520
pub fn dangerous_get_v2_rotated_account_keys(
521521
&self,
522-
new_user_key: SymmetricCryptoKey,
522+
new_user_key: &SymmetricCryptoKey,
523523
current_user_private_key_id: Ids::Asymmetric,
524524
current_user_signing_key_id: Ids::Signing,
525525
) -> Result<RotatedUserKeys> {
@@ -544,7 +544,7 @@ mod tests {
544544
},
545545
traits::tests::{TestAsymmKey, TestIds, TestSigningKey, TestSymmKey},
546546
AsymmetricCryptoKey, AsymmetricPublicCryptoKey, CompositeEncryptable, CoseKeyBytes,
547-
CoseSerializable, Decryptable, KeyDecryptable, Pkcs8PrivateKeyBytes,
547+
CoseSerializable, CryptoError, Decryptable, KeyDecryptable, Pkcs8PrivateKeyBytes,
548548
PublicKeyEncryptionAlgorithm, SignatureAlgorithm, SignedPublicKey, SigningKey,
549549
SigningNamespace, SpkiPublicKeyBytes, SymmetricCryptoKey,
550550
};
@@ -759,23 +759,23 @@ mod tests {
759759
// Get the rotated account keys
760760
let rotated_keys = ctx
761761
.dangerous_get_v2_rotated_account_keys(
762-
new_user_key,
762+
&new_user_key,
763763
current_user_private_key_id,
764764
current_user_signing_key_id,
765765
)
766766
.unwrap();
767767

768-
let user_key = ctx.get_symmetric_key(TestSymmKey::A(0)).unwrap();
769-
770768
// Public/Private key
771769
assert_eq!(
772770
AsymmetricPublicCryptoKey::from_der(&rotated_keys.public_key).unwrap(),
773771
ctx.get_asymmetric_key(current_user_private_key_id)
774772
.unwrap()
775773
.to_public_key(),
776774
);
777-
let decrypted_private_key: Vec<u8> =
778-
rotated_keys.private_key.decrypt_with_key(user_key).unwrap();
775+
let decrypted_private_key: Vec<u8> = rotated_keys
776+
.private_key
777+
.decrypt_with_key(&new_user_key)
778+
.unwrap();
779779
let private_key =
780780
AsymmetricCryptoKey::from_der(&Pkcs8PrivateKeyBytes::from(decrypted_private_key))
781781
.unwrap();
@@ -788,8 +788,10 @@ mod tests {
788788
);
789789

790790
// Signing Key
791-
let decrypted_signing_key: Vec<u8> =
792-
rotated_keys.signing_key.decrypt_with_key(user_key).unwrap();
791+
let decrypted_signing_key: Vec<u8> = rotated_keys
792+
.signing_key
793+
.decrypt_with_key(&new_user_key)
794+
.unwrap();
793795
let signing_key =
794796
SigningKey::from_cose(&CoseKeyBytes::from(decrypted_signing_key)).unwrap();
795797
assert_eq!(

0 commit comments

Comments
 (0)