Skip to content

Commit 1920a49

Browse files
committed
Rename to bytes
1 parent d47e8c0 commit 1920a49

File tree

26 files changed

+145
-149
lines changed

26 files changed

+145
-149
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mod tests {
111111
use std::num::NonZeroU32;
112112

113113
use bitwarden_crypto::{
114-
BitwardenLegacyKeyContentFormat, Kdf, MasterKey, SerializedBytes,
114+
BitwardenLegacyKeyContentFormat, Kdf, MasterKey, Bytes,
115115
SpkiPublicKeyDerContentFormat,
116116
};
117117

@@ -136,7 +136,7 @@ mod tests {
136136
AsymmetricCryptoKey::from_der(&STANDARD.decode(&request.private_key).unwrap().into())
137137
.unwrap();
138138

139-
let secret = SerializedBytes::<BitwardenLegacyKeyContentFormat>::from(secret);
139+
let secret = Bytes::<BitwardenLegacyKeyContentFormat>::from(secret);
140140
let encrypted = UnsignedSharedKey::encapsulate_key_unsigned(
141141
&SymmetricCryptoKey::try_from(&secret).unwrap(),
142142
&private_key.to_public_key(),
@@ -172,7 +172,7 @@ mod tests {
172172

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

crates/bitwarden-core/src/auth/login/access_token.rs

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

33
use base64::{engine::general_purpose::STANDARD, Engine};
44
use bitwarden_crypto::{
5-
BitwardenLegacyKeyContentFormat, EncString, KeyDecryptable, SerializedBytes, SymmetricCryptoKey,
5+
BitwardenLegacyKeyContentFormat, EncString, KeyDecryptable, Bytes, SymmetricCryptoKey,
66
};
77
use chrono::Utc;
88
use schemars::JsonSchema;
@@ -70,7 +70,7 @@ pub(crate) async fn login_access_token(
7070
let payload: Payload = serde_json::from_slice(&decrypted_payload)?;
7171
let encryption_key = STANDARD.decode(&payload.encryption_key)?;
7272
let encryption_key =
73-
SerializedBytes::<BitwardenLegacyKeyContentFormat>::from(encryption_key);
73+
Bytes::<BitwardenLegacyKeyContentFormat>::from(encryption_key);
7474
let encryption_key = SymmetricCryptoKey::try_from(&encryption_key)?;
7575

7676
let access_token_obj: JwtToken = r.access_token.parse()?;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ impl EncryptionSettings {
5858
use crate::key_management::{AsymmetricKeyId, SigningKeyId, SymmetricKeyId};
5959

6060
let private_key = {
61-
use bitwarden_crypto::{Pkcs8PrivateKeyDerContentFormat, SerializedBytes};
61+
use bitwarden_crypto::{Pkcs8PrivateKeyDerContentFormat, Bytes};
6262

6363
let dec: Vec<u8> = private_key.decrypt_with_key(&user_key)?;
64-
let dec: SerializedBytes<Pkcs8PrivateKeyDerContentFormat> = SerializedBytes::from(dec);
64+
let dec: Bytes<Pkcs8PrivateKeyDerContentFormat> = Bytes::from(dec);
6565
// FIXME: [PM-11690] - Temporarily ignore invalid private keys until we have a recovery
6666
// process in place.
6767
AsymmetricCryptoKey::from_der(&dec)
@@ -82,12 +82,12 @@ impl EncryptionSettings {
8282
let mut ctx = store.context_mut();
8383

8484
if let Some(signing_key) = signing_key {
85-
use bitwarden_crypto::SerializedBytes;
85+
use bitwarden_crypto::Bytes;
8686

8787
let dec: Vec<u8> = signing_key
8888
.decrypt_with_key(&user_key)
8989
.map_err(|_| EncryptionSettingsError::InvalidSigningKey)?;
90-
let signing_key = SigningKey::from_cose(&SerializedBytes::from(dec))
90+
let signing_key = SigningKey::from_cose(&Bytes::from(dec))
9191
.map_err(|_| EncryptionSettingsError::InvalidSigningKey)?;
9292
ctx.set_signing_key(SigningKeyId::UserSigningKey, signing_key)?;
9393
}

crates/bitwarden-core/src/key_management/crypto.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use base64::{engine::general_purpose::STANDARD, Engine};
1010
use bitwarden_crypto::{
1111
AsymmetricCryptoKey, CoseSerializable, CryptoError, EncString, Kdf, KeyDecryptable,
1212
KeyEncryptable, MasterKey, Pkcs8PrivateKeyDerContentFormat, PrimitiveEncryptable,
13-
SerializedBytes, SignatureAlgorithm, SignedPublicKey, SigningKey, SymmetricCryptoKey,
13+
Bytes, SignatureAlgorithm, SignedPublicKey, SigningKey, SymmetricCryptoKey,
1414
UnsignedSharedKey, UserKey,
1515
};
1616
use bitwarden_error::bitwarden_error;
@@ -537,8 +537,8 @@ pub(super) fn verify_asymmetric_keys(
537537
.decrypt_with_key(user_key)
538538
.map_err(VerifyError::DecryptFailed)?;
539539

540-
let decrypted_private_key: SerializedBytes<Pkcs8PrivateKeyDerContentFormat> =
541-
SerializedBytes::from(decrypted_private_key);
540+
let decrypted_private_key: Bytes<Pkcs8PrivateKeyDerContentFormat> =
541+
Bytes::from(decrypted_private_key);
542542
let private_key = AsymmetricCryptoKey::from_der(&decrypted_private_key)
543543
.map_err(VerifyError::ParseFailed)?;
544544

@@ -844,7 +844,7 @@ mod tests {
844844

845845
let private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCzLtEUdxfcLxDj84yaGFsVF5hZ8Hjlb08NMQDy1RnBma06I3ZESshLYzVz4r/gegMn9OOltfV/Yxlyvida8oW6qdlfJ7AVz6Oa8pV7BiL40C7b76+oqraQpyYw2HChANB1AhXL9SqWngKmLZwjA7qiCrmcc0kZHeOb4KnKtp9iVvPVs+8veFvKgYO4ba2AAOHKFdR0W55/agXfAy+fWUAkC8mc9ikyJdQWaPV6OZvC2XFkOseBQm9Rynudh3BQpoWiL6w620efe7t5k+02/EyOFJL9f/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LlpMGKha/YBV8c1fvC4LD0NPh/Ynv0gtECgYEAyOZg95/kte0jpgUEgwuMrzkhY/AaUJULFuR5MkyvReEbtSBQwV5tx60+T95PHNiFooWWVXiLMsAgyI2IbkxVR1Pzdri3gWK5CTfqb7kLuaj/B7SGvBa2Sxo478KS5K8tBBBWkITqo+wLC0mn3uZi1dyMWO1zopTA+KtEGF2dtGQ=";
846846
let private_key = STANDARD.decode(private_key).unwrap();
847-
let private_key = SerializedBytes::<Pkcs8PrivateKeyDerContentFormat>::from(private_key);
847+
let private_key = Bytes::<Pkcs8PrivateKeyDerContentFormat>::from(private_key);
848848
let private_key = AsymmetricCryptoKey::from_der(&private_key).unwrap();
849849
let decrypted: SymmetricCryptoKey =
850850
encrypted.decapsulate_key_unsigned(&private_key).unwrap();

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, SerializedBytes, SpkiPublicKeyDerContentFormat};
6+
use bitwarden_crypto::{fingerprint, Bytes, SpkiPublicKeyDerContentFormat};
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 = SerializedBytes::<SpkiPublicKeyDerContentFormat>::from(key);
45+
let key = Bytes::<SpkiPublicKeyDerContentFormat>::from(key);
4646
Ok(fingerprint(&input.fingerprint_material, &key)?)
4747
}
4848

crates/bitwarden-crypto/examples/signature.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! to verify them.
33
44
use bitwarden_crypto::{
5-
CoseSerializable, CoseSign1ContentFormat, SerializedBytes, SigningNamespace,
5+
CoseSerializable, CoseSign1ContentFormat, Bytes, SigningNamespace,
66
};
77
use serde::{Deserialize, Serialize};
88

@@ -45,7 +45,7 @@ fn main() {
4545

4646
// Bob retrieves the signed object from the server
4747
let retrieved_signature =
48-
bitwarden_crypto::Signature::from_cose(&SerializedBytes::<CoseSign1ContentFormat>::from(
48+
bitwarden_crypto::Signature::from_cose(&Bytes::<CoseSign1ContentFormat>::from(
4949
mock_server
5050
.download("signature")
5151
.expect("Failed to download signature")
@@ -93,15 +93,15 @@ fn main() {
9393
.expect("Failed to get content type from signature"),
9494
);
9595
let retrieved_alice_signature =
96-
bitwarden_crypto::Signature::from_cose(&SerializedBytes::<CoseSign1ContentFormat>::from(
96+
bitwarden_crypto::Signature::from_cose(&Bytes::<CoseSign1ContentFormat>::from(
9797
mock_server
9898
.download("signature")
9999
.expect("Failed to download Alice's signature")
100100
.clone(),
101101
))
102102
.expect("Failed to deserialize Alice's signature");
103103
let retrieved_bobs_signature =
104-
bitwarden_crypto::Signature::from_cose(&SerializedBytes::<CoseSign1ContentFormat>::from(
104+
bitwarden_crypto::Signature::from_cose(&Bytes::<CoseSign1ContentFormat>::from(
105105
mock_server
106106
.download("bobs_signature")
107107
.expect("Failed to download Bob's signature")

crates/bitwarden-crypto/examples/signed_object.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This example demonstrates how to sign and verify structs.
22
33
use bitwarden_crypto::{
4-
CoseSerializable, CoseSign1ContentFormat, SerializedBytes, SignedObject, SigningNamespace,
4+
Bytes, CoseSerializable, CoseSign1ContentFormat, SignedObject, SigningNamespace,
55
};
66
use serde::{Deserialize, Serialize};
77

@@ -39,14 +39,13 @@ fn main() {
3939
mock_server.upload("signed_object", signed_object.to_cose().as_ref().to_vec());
4040

4141
// Bob retrieves the signed object from the server
42-
let retrieved_signed_object =
43-
SignedObject::from_cose(&SerializedBytes::<CoseSign1ContentFormat>::from(
44-
mock_server
45-
.download("signed_object")
46-
.expect("Failed to download signed object")
47-
.clone(),
48-
))
49-
.expect("Failed to deserialize signed object");
42+
let retrieved_signed_object = SignedObject::from_cose(&Bytes::<CoseSign1ContentFormat>::from(
43+
mock_server
44+
.download("signed_object")
45+
.expect("Failed to download signed object")
46+
.clone(),
47+
))
48+
.expect("Failed to deserialize signed object");
5049
// Bob verifies the signed object using Alice's verifying key
5150
let verified_message: MessageToBob = retrieved_signed_object
5251
.verify_and_unwrap(&alice_verifying_key, EXAMPLE_NAMESPACE)

crates/bitwarden-crypto/src/content_format.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ pub trait ConstContentFormat {
5353
/// format is used to determine how the bytes should be interpreted when encrypting or decrypting
5454
/// the data.
5555
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
56-
pub struct SerializedBytes<C: ConstContentFormat> {
56+
pub struct Bytes<C: ConstContentFormat> {
5757
inner: Vec<u8>,
5858
_marker: std::marker::PhantomData<C>,
5959
}
6060

61-
impl<C: ConstContentFormat> From<Vec<u8>> for SerializedBytes<C> {
61+
impl<C: ConstContentFormat> From<Vec<u8>> for Bytes<C> {
6262
fn from(inner: Vec<u8>) -> Self {
6363
Self {
6464
inner,
@@ -67,19 +67,19 @@ impl<C: ConstContentFormat> From<Vec<u8>> for SerializedBytes<C> {
6767
}
6868
}
6969

70-
impl<C: ConstContentFormat> From<&[u8]> for SerializedBytes<C> {
70+
impl<C: ConstContentFormat> From<&[u8]> for Bytes<C> {
7171
fn from(inner: &[u8]) -> Self {
7272
Self::from(inner.to_vec())
7373
}
7474
}
7575

76-
impl<C: ConstContentFormat> AsRef<[u8]> for SerializedBytes<C> {
76+
impl<C: ConstContentFormat> AsRef<[u8]> for Bytes<C> {
7777
fn as_ref(&self) -> &[u8] {
7878
&self.inner
7979
}
8080
}
8181

82-
impl<C: ConstContentFormat> SerializedBytes<C> {
82+
impl<C: ConstContentFormat> Bytes<C> {
8383
/// Returns the serialized bytes as a `Vec<u8>`.
8484
pub fn to_vec(&self) -> Vec<u8> {
8585
self.inner.clone()
@@ -156,7 +156,7 @@ impl CoseContentFormat for CoseSign1ContentFormat {}
156156
pub trait CoseContentFormat {}
157157

158158
impl<Ids: KeyIds, T: ConstContentFormat> PrimitiveEncryptable<Ids, Ids::Symmetric, EncString>
159-
for SerializedBytes<T>
159+
for Bytes<T>
160160
{
161161
fn encrypt(
162162
&self,
@@ -167,20 +167,20 @@ impl<Ids: KeyIds, T: ConstContentFormat> PrimitiveEncryptable<Ids, Ids::Symmetri
167167
}
168168
}
169169

170-
impl<T: ConstContentFormat> KeyEncryptable<SymmetricCryptoKey, EncString> for &SerializedBytes<T> {
170+
impl<T: ConstContentFormat> KeyEncryptable<SymmetricCryptoKey, EncString> for &Bytes<T> {
171171
fn encrypt_with_key(self, key: &SymmetricCryptoKey) -> Result<EncString, CryptoError> {
172172
self.as_ref().encrypt_with_key(key, T::content_format())
173173
}
174174
}
175175

176-
impl From<String> for SerializedBytes<Utf8ContentFormat> {
176+
impl From<String> for Bytes<Utf8ContentFormat> {
177177
fn from(val: String) -> Self {
178-
SerializedBytes::from(val.into_bytes())
178+
Bytes::from(val.into_bytes())
179179
}
180180
}
181181

182-
impl From<&str> for SerializedBytes<Utf8ContentFormat> {
182+
impl From<&str> for Bytes<Utf8ContentFormat> {
183183
fn from(val: &str) -> Self {
184-
SerializedBytes::from(val.as_bytes().to_vec())
184+
Bytes::from(val.as_bytes().to_vec())
185185
}
186186
}

crates/bitwarden-crypto/src/cose.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use generic_array::GenericArray;
1111
use typenum::U32;
1212

1313
use crate::{
14-
content_format::{ConstContentFormat, CoseContentFormat, SerializedBytes},
14+
content_format::{ConstContentFormat, CoseContentFormat, Bytes},
1515
error::{EncStringParseError, EncodingError},
1616
xchacha20, ContentFormat, CryptoError, SymmetricCryptoKey, XChaCha20Poly1305Key,
1717
};
@@ -216,9 +216,9 @@ fn should_pad_content(format: &ContentFormat) -> bool {
216216
/// Trait for structs that are serializable to COSE objects.
217217
pub trait CoseSerializable<T: CoseContentFormat + ConstContentFormat> {
218218
/// Serializes the struct to COSE serialization
219-
fn to_cose(&self) -> SerializedBytes<T>;
219+
fn to_cose(&self) -> Bytes<T>;
220220
/// Deserializes a serialized COSE object to a struct
221-
fn from_cose(bytes: &SerializedBytes<T>) -> Result<Self, EncodingError>
221+
fn from_cose(bytes: &Bytes<T>) -> Result<Self, EncodingError>
222222
where
223223
Self: Sized;
224224
}

crates/bitwarden-crypto/src/enc_string/asymmetric.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
rsa::encrypt_rsa2048_oaep_sha1,
1212
util::FromStrVisitor,
1313
AsymmetricCryptoKey, AsymmetricPublicCryptoKey, BitwardenLegacyKeyContentFormat, RawPrivateKey,
14-
RawPublicKey, SerializedBytes, SymmetricCryptoKey,
14+
RawPublicKey, Bytes, SymmetricCryptoKey,
1515
};
1616
// This module is a workaround to avoid deprecated warnings that come from the ZeroizeOnDrop
1717
// macro expansion
@@ -218,7 +218,7 @@ impl UnsignedSharedKey {
218218
}
219219
.map_err(|_| CryptoError::KeyDecrypt)?;
220220
SymmetricCryptoKey::try_from(
221-
&SerializedBytes::<BitwardenLegacyKeyContentFormat>::from(key_data),
221+
&Bytes::<BitwardenLegacyKeyContentFormat>::from(key_data),
222222
)
223223
}
224224
}

0 commit comments

Comments
 (0)