Skip to content

Commit 41bb1ad

Browse files
committed
Replace non type aliased Bytes references with type aliases
1 parent 1953ba3 commit 41bb1ad

File tree

9 files changed

+41
-50
lines changed

9 files changed

+41
-50
lines changed

crates/bitwarden-core/src/auth/auth_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ mod tests {
171171

172172
// Verify fingerprint
173173
let pubkey = STANDARD.decode(public_key).unwrap();
174-
let pubkey = Bytes::<SpkiPublicKeyDerContentFormat>::from(pubkey.clone());
174+
let pubkey = SpkiPublicKeyBytes::from(pubkey.clone());
175175
let fingerprint = fingerprint("[email protected]", &pubkey).unwrap();
176176
assert_eq!(fingerprint, "childless-unfair-prowler-dropbox-designate");
177177

crates/bitwarden-core/src/platform/generate_fingerprint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This module contains the logic for generating fingerprints.
44
55
use base64::{engine::general_purpose::STANDARD, Engine};
6-
use bitwarden_crypto::{fingerprint, Bytes, SpkiPublicKeyDerContentFormat};
6+
use bitwarden_crypto::{fingerprint, SpkiPublicKeyBytes};
77
use serde::{Deserialize, Serialize};
88
use thiserror::Error;
99

@@ -42,7 +42,7 @@ pub enum FingerprintError {
4242

4343
pub(crate) fn generate_fingerprint(input: &FingerprintRequest) -> Result<String, FingerprintError> {
4444
let key = STANDARD.decode(&input.public_key)?;
45-
let key = Bytes::<SpkiPublicKeyDerContentFormat>::from(key);
45+
let key = SpkiPublicKeyBytes::from(key);
4646
Ok(fingerprint(&input.fingerprint_material, &key)?)
4747
}
4848

crates/bitwarden-crypto/examples/signature.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ fn main() {
4242
mock_server.upload("serialized_message", serialized_message.as_bytes().to_vec());
4343

4444
// Bob retrieves the signed object from the server
45-
let retrieved_signature =
46-
bitwarden_crypto::Signature::from_cose(&Bytes::<CoseSign1ContentFormat>::from(
47-
mock_server
48-
.download("signature")
49-
.expect("Failed to download signature")
50-
.clone(),
51-
))
52-
.expect("Failed to deserialize signature");
45+
let retrieved_signature = bitwarden_crypto::Signature::from_cose(&CoseSign1Bytes::from(
46+
mock_server
47+
.download("signature")
48+
.expect("Failed to download signature")
49+
.clone(),
50+
))
51+
.expect("Failed to deserialize signature");
5352
let retrieved_serialized_message = bitwarden_crypto::SerializedMessage::from_bytes(
5453
mock_server
5554
.download("serialized_message")
@@ -90,22 +89,20 @@ fn main() {
9089
.content_type()
9190
.expect("Failed to get content type from signature"),
9291
);
93-
let retrieved_alice_signature =
94-
bitwarden_crypto::Signature::from_cose(&Bytes::<CoseSign1ContentFormat>::from(
95-
mock_server
96-
.download("signature")
97-
.expect("Failed to download Alice's signature")
98-
.clone(),
99-
))
100-
.expect("Failed to deserialize Alice's signature");
101-
let retrieved_bobs_signature =
102-
bitwarden_crypto::Signature::from_cose(&Bytes::<CoseSign1ContentFormat>::from(
103-
mock_server
104-
.download("bobs_signature")
105-
.expect("Failed to download Bob's signature")
106-
.clone(),
107-
))
108-
.expect("Failed to deserialize Bob's signature");
92+
let retrieved_alice_signature = bitwarden_crypto::Signature::from_cose(&CoseSign1Bytes::from(
93+
mock_server
94+
.download("signature")
95+
.expect("Failed to download Alice's signature")
96+
.clone(),
97+
))
98+
.expect("Failed to deserialize Alice's signature");
99+
let retrieved_bobs_signature = bitwarden_crypto::Signature::from_cose(&CoseSign1Bytes::from(
100+
mock_server
101+
.download("bobs_signature")
102+
.expect("Failed to download Bob's signature")
103+
.clone(),
104+
))
105+
.expect("Failed to deserialize Bob's signature");
109106

110107
// Charlie verifies Alice's signature
111108
if !retrieved_alice_signature.verify(

crates/bitwarden-crypto/examples/signed_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn main() {
3939
mock_server.upload("signed_object", signed_object.to_cose().to_vec());
4040

4141
// Bob retrieves the signed object from the server
42-
let retrieved_signed_object = SignedObject::from_cose(&Bytes::<CoseSign1ContentFormat>::from(
42+
let retrieved_signed_object = SignedObject::from_cose(&CoseSign1Bytes::from(
4343
mock_server
4444
.download("signed_object")
4545
.expect("Failed to download signed object")

crates/bitwarden-crypto/src/fingerprint.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@ use num_bigint::BigUint;
88
use num_traits::cast::ToPrimitive;
99
use thiserror::Error;
1010

11-
use crate::{
12-
content_format::SpkiPublicKeyDerContentFormat, error::Result, wordlist::EFF_LONG_WORD_LIST,
13-
Bytes, CryptoError,
14-
};
11+
use crate::{error::Result, wordlist::EFF_LONG_WORD_LIST, CryptoError, SpkiPublicKeyBytes};
1512

1613
/// Computes a fingerprint of the given `fingerprint_material` using the given `public_key`.
1714
///
1815
/// This is commonly used for account fingerprints. With the following arguments:
1916
/// - `fingerprint_material`: user's id.
2017
/// - `public_key`: user's public key.
21-
pub fn fingerprint(
22-
fingerprint_material: &str,
23-
public_key: &Bytes<SpkiPublicKeyDerContentFormat>,
24-
) -> Result<String> {
18+
pub fn fingerprint(fingerprint_material: &str, public_key: &SpkiPublicKeyBytes) -> Result<String> {
2519
let hkdf = hkdf::Hkdf::<sha2::Sha256>::from_prk(public_key.as_ref())
2620
.map_err(|_| CryptoError::InvalidKeyLen)?;
2721

@@ -93,7 +87,7 @@ mod tests {
9387
197, 3, 219, 56, 77, 109, 47, 72, 251, 131, 36, 240, 96, 169, 31, 82, 93, 166, 242, 3,
9488
33, 213, 2, 3, 1, 0, 1,
9589
];
96-
let key: Bytes<SpkiPublicKeyDerContentFormat> = Bytes::from(key.to_vec());
90+
let key: SpkiPublicKeyBytes = Bytes::from(key.to_vec());
9791
assert_eq!(
9892
"turban-deftly-anime-chatroom-unselfish",
9993
fingerprint(user_id, &key).unwrap()

crates/bitwarden-crypto/src/keys/asymmetric_crypto_key.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use serde_repr::{Deserialize_repr, Serialize_repr};
55

66
use super::key_encryptable::CryptoKey;
77
use crate::{
8-
content_format::{Bytes, SpkiPublicKeyDerContentFormat},
98
error::{CryptoError, Result},
10-
Pkcs8PrivateKeyBytes,
9+
Pkcs8PrivateKeyBytes, SpkiPublicKeyBytes,
1110
};
1211

1312
/// Algorithm / public key encryption scheme used for encryption/decryption.
@@ -45,7 +44,7 @@ impl AsymmetricPublicCryptoKey {
4544
}
4645

4746
/// Makes a SubjectPublicKeyInfo DER serialized version of the public key.
48-
pub fn to_der(&self) -> Result<Bytes<SpkiPublicKeyDerContentFormat>> {
47+
pub fn to_der(&self) -> Result<SpkiPublicKeyBytes> {
4948
use rsa::pkcs8::EncodePublicKey;
5049
match &self.inner {
5150
RawPublicKey::RsaOaepSha1(public_key) => Ok(public_key
@@ -167,7 +166,8 @@ mod tests {
167166

168167
use crate::{
169168
content_format::{Bytes, Pkcs8PrivateKeyDerContentFormat},
170-
AsymmetricCryptoKey, AsymmetricPublicCryptoKey, SymmetricCryptoKey, UnsignedSharedKey,
169+
AsymmetricCryptoKey, AsymmetricPublicCryptoKey, Pkcs8PrivateKeyBytes, SymmetricCryptoKey,
170+
UnsignedSharedKey,
171171
};
172172

173173
#[test]
@@ -261,7 +261,7 @@ DnqOsltgPomWZ7xVfMkm9niL2OA=
261261
))
262262
.unwrap();
263263

264-
let private_key = Bytes::<Pkcs8PrivateKeyDerContentFormat>::from(private_key);
264+
let private_key = Pkcs8PrivateKeyBytes::from(private_key);
265265
let private_key = AsymmetricCryptoKey::from_der(&private_key).unwrap();
266266
let public_key = AsymmetricPublicCryptoKey::from_der(&public_key).unwrap();
267267

crates/bitwarden-send/src/send.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use bitwarden_core::{
88
require,
99
};
1010
use bitwarden_crypto::{
11-
generate_random_bytes, Bytes, CompositeEncryptable, CryptoError, Decryptable, EncString,
12-
IdentifyKey, KeyStoreContext, OctetStreamContentFormat, PrimitiveEncryptable,
11+
generate_random_bytes, CompositeEncryptable, CryptoError, Decryptable, EncString, IdentifyKey,
12+
KeyStoreContext, OctetStreamBytes, PrimitiveEncryptable,
1313
};
1414
use chrono::{DateTime, Utc};
1515
use serde::{Deserialize, Serialize};
@@ -331,7 +331,7 @@ impl CompositeEncryptable<KeyIds, SymmetricKeyId, Send> for SendView {
331331

332332
name: self.name.encrypt(ctx, send_key)?,
333333
notes: self.notes.encrypt(ctx, send_key)?,
334-
key: Bytes::<OctetStreamContentFormat>::from(k.clone()).encrypt(ctx, key)?,
334+
key: OctetStreamBytes::from(k.clone()).encrypt(ctx, key)?,
335335
password: self.new_password.as_ref().map(|password| {
336336
let password = bitwarden_crypto::pbkdf2(password.as_bytes(), &k, SEND_ITERATIONS);
337337
STANDARD.encode(password)

crates/bitwarden-send/src/send_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::path::Path;
22

33
use bitwarden_core::Client;
44
use bitwarden_crypto::{
5-
Bytes, Decryptable, EncString, IdentifyKey, OctetStreamContentFormat, PrimitiveEncryptable,
5+
Decryptable, EncString, IdentifyKey, OctetStreamBytes, PrimitiveEncryptable,
66
};
77
use thiserror::Error;
88

@@ -129,7 +129,7 @@ impl SendClient {
129129

130130
let key = Send::get_key(&mut ctx, &send.key, send.key_identifier())?;
131131

132-
let encrypted = Bytes::<OctetStreamContentFormat>::from(buffer).encrypt(&mut ctx, key)?;
132+
let encrypted = OctetStreamBytes::from(buffer).encrypt(&mut ctx, key)?;
133133
Ok(encrypted.to_buffer()?)
134134
}
135135
}

crates/bitwarden-vault/src/cipher/attachment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bitwarden_core::key_management::{KeyIds, SymmetricKeyId};
22
use bitwarden_crypto::{
3-
Bytes, CompositeEncryptable, CryptoError, Decryptable, EncString, IdentifyKey, KeyStoreContext,
4-
OctetStreamContentFormat, PrimitiveEncryptable,
3+
CompositeEncryptable, CryptoError, Decryptable, EncString, IdentifyKey, KeyStoreContext,
4+
OctetStreamBytes, PrimitiveEncryptable,
55
};
66
use serde::{Deserialize, Serialize};
77
#[cfg(feature = "wasm")]
@@ -95,7 +95,7 @@ impl CompositeEncryptable<KeyIds, SymmetricKeyId, AttachmentEncryptResult>
9595
// with it, and then encrypt the key with the cipher key
9696
let attachment_key = ctx.generate_symmetric_key(ATTACHMENT_KEY)?;
9797
let encrypted_contents =
98-
Bytes::<OctetStreamContentFormat>::from(self.contents).encrypt(ctx, attachment_key)?;
98+
OctetStreamBytes::from(self.contents).encrypt(ctx, attachment_key)?;
9999
attachment.key = Some(ctx.wrap_symmetric_key(ciphers_key, attachment_key)?);
100100

101101
let contents = encrypted_contents.to_buffer()?;

0 commit comments

Comments
 (0)