Skip to content

Commit f8cb804

Browse files
committed
Apply cargo fmt
1 parent 9440825 commit f8cb804

File tree

20 files changed

+94
-164
lines changed

20 files changed

+94
-164
lines changed

bitwarden_license/bitwarden-sm/src/secrets/create.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,8 @@ pub(crate) async fn create_secret(
4040
let secret = {
4141
let mut ctx = key_store.context();
4242
Some(SecretCreateRequestModel {
43-
key: input
44-
.key
45-
.clone()
46-
.trim()
47-
.encrypt(&mut ctx, key)?
48-
.to_string(),
49-
value: input
50-
.value
51-
.clone()
52-
.encrypt(&mut ctx, key)?
53-
.to_string(),
43+
key: input.key.clone().trim().encrypt(&mut ctx, key)?.to_string(),
44+
value: input.value.clone().encrypt(&mut ctx, key)?.to_string(),
5445
note: input
5546
.note
5647
.clone()

bitwarden_license/bitwarden-sm/src/secrets/update.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,8 @@ pub(crate) async fn update_secret(
3939
let secret = {
4040
let mut ctx = key_store.context();
4141
Some(SecretUpdateRequestModel {
42-
key: input
43-
.key
44-
.clone()
45-
.trim()
46-
.encrypt(&mut ctx, key)?
47-
.to_string(),
48-
value: input
49-
.value
50-
.clone()
51-
.encrypt(&mut ctx, key)?
52-
.to_string(),
42+
key: input.key.clone().trim().encrypt(&mut ctx, key)?.to_string(),
43+
value: input.value.clone().encrypt(&mut ctx, key)?.to_string(),
5344
note: input
5445
.note
5546
.clone()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::collections::HashMap;
88

99
use base64::{engine::general_purpose::STANDARD, Engine};
1010
use bitwarden_crypto::{
11-
AsymmetricCryptoKey, ContentFormat, CryptoError, EncString, Kdf, KeyDecryptable, KeyEncryptable, MasterKey, SymmetricCryptoKey, UnsignedSharedKey, UserKey
11+
AsymmetricCryptoKey, ContentFormat, CryptoError, EncString, Kdf, KeyDecryptable,
12+
KeyEncryptable, MasterKey, SymmetricCryptoKey, UnsignedSharedKey, UserKey,
1213
};
1314
use serde::{Deserialize, Serialize};
1415
#[cfg(feature = "wasm")]

crates/bitwarden-crypto/src/cose.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ pub(crate) const XCHACHA20_POLY1305: i64 = -70000;
2424
const XCHACHA20_TEXT_PAD_BLOCK_SIZE: usize = 32;
2525
const CONTENT_TYPE_PADDED_UTF8: &str = "application/utf8-padded";
2626

27-
/// The content format describes the format of the contained bytes. Message encryption always happens on the byte level, and this
28-
/// allows determining what format the contained data has. For instance, an `EncString` in most cases contains UTF-8 encoded
29-
/// text. In some cases it may contain a Pkcs8 private key, or a COSE key. Specifically, for COSE keys, this allows distinguishing between
30-
/// the old symmetric key format, represented as `ContentFormat::OctetStream`, and the new COSE key format, represented as `ContentFormat::CoseKey`.
27+
/// The content format describes the format of the contained bytes. Message encryption always
28+
/// happens on the byte level, and this allows determining what format the contained data has. For
29+
/// instance, an `EncString` in most cases contains UTF-8 encoded text. In some cases it may contain
30+
/// a Pkcs8 private key, or a COSE key. Specifically, for COSE keys, this allows distinguishing
31+
/// between the old symmetric key format, represented as `ContentFormat::OctetStream`, and the new
32+
/// COSE key format, represented as `ContentFormat::CoseKey`.
3133
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3234
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
3335
pub enum ContentFormat {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
2-
error::Result, AsymmetricCryptoKey, ContentFormat, CryptoError, EncString, KeyDecryptable, KeyEncryptable, SymmetricCryptoKey, UnsignedSharedKey
2+
error::Result, AsymmetricCryptoKey, ContentFormat, CryptoError, EncString, KeyDecryptable,
3+
KeyEncryptable, SymmetricCryptoKey, UnsignedSharedKey,
34
};
45

56
/// Device Key

crates/bitwarden-crypto/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ mod cose;
3434
mod traits;
3535
pub use cose::ContentFormat;
3636
mod xchacha20;
37-
pub use traits::{Decryptable, Encryptable, CompositeEncryptable, TypedEncryptable, IdentifyKey, KeyId, KeyIds};
37+
pub use traits::{
38+
CompositeEncryptable, Decryptable, Encryptable, IdentifyKey, KeyId, KeyIds, TypedEncryptable,
39+
};
3840
pub use zeroizing_alloc::ZeroAlloc as ZeroizingAllocator;
3941

4042
#[cfg(feature = "uniffi")]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ mod tests {
385385
store::{
386386
tests::{Data, DataView},
387387
KeyStore,
388-
}, traits::tests::{TestIds, TestSymmKey}, CompositeEncryptable, Decryptable, SymmetricCryptoKey
388+
},
389+
traits::tests::{TestIds, TestSymmKey},
390+
CompositeEncryptable, Decryptable, SymmetricCryptoKey,
389391
};
390392

391393
#[test]
@@ -445,9 +447,7 @@ mod tests {
445447
// with one and decrypt with the other
446448

447449
let data = DataView("Hello, World!".to_string(), key_2_id);
448-
let encrypted = data
449-
.encrypt_composite(&mut ctx, key_2_id)
450-
.unwrap();
450+
let encrypted = data.encrypt_composite(&mut ctx, key_2_id).unwrap();
451451

452452
let decrypted1 = encrypted.decrypt(&mut ctx, key_2_id).unwrap();
453453
let decrypted2 = encrypted.decrypt(&mut ctx, new_key_id).unwrap();

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ impl<Ids: KeyIds> KeyStore<Ids> {
209209
/// already be present in the store, otherwise this will return an error.
210210
/// This method is not parallelized, and is meant for single item encryption.
211211
/// If you need to encrypt multiple items, use `encrypt_list` instead.
212-
pub fn encrypt<Key: KeyId, Data: CompositeEncryptable<Ids, Key, Output> + IdentifyKey<Key>, Output>(
212+
pub fn encrypt<
213+
Key: KeyId,
214+
Data: CompositeEncryptable<Ids, Key, Output> + IdentifyKey<Key>,
215+
Output,
216+
>(
213217
&self,
214218
data: Data,
215219
) -> Result<Output, crate::CryptoError> {
@@ -304,7 +308,9 @@ fn batch_chunk_size(len: usize) -> usize {
304308
#[cfg(test)]
305309
pub(crate) mod tests {
306310
use crate::{
307-
store::{KeyStore, KeyStoreContext}, traits::tests::{TestIds, TestSymmKey}, EncString, Encryptable, SymmetricCryptoKey, TypedEncryptable
311+
store::{KeyStore, KeyStoreContext},
312+
traits::tests::{TestIds, TestSymmKey},
313+
EncString, Encryptable, SymmetricCryptoKey, TypedEncryptable,
308314
};
309315

310316
pub struct DataView(pub String, pub TestSymmKey);

crates/bitwarden-crypto/src/traits/encryptable.rs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<Ids: KeyIds, Key: KeyId, T: CompositeEncryptable<Ids, Key, Output>, Output>
2727
}
2828
}
2929

30-
impl <Ids: KeyIds, Key: KeyId, T: CompositeEncryptable<Ids, Key, Output>, Output>
30+
impl<Ids: KeyIds, Key: KeyId, T: CompositeEncryptable<Ids, Key, Output>, Output>
3131
CompositeEncryptable<Ids, Key, Vec<Output>> for Vec<T>
3232
{
3333
fn encrypt_composite(
@@ -41,14 +41,10 @@ impl <Ids: KeyIds, Key: KeyId, T: CompositeEncryptable<Ids, Key, Output>, Output
4141
}
4242
}
4343

44-
/// An encryption operation that takes the input value - a primitive such as `String` and encrypts it into the output value.
45-
/// The implementation decides the content format.
44+
/// An encryption operation that takes the input value - a primitive such as `String` and encrypts
45+
/// it into the output value. The implementation decides the content format.
4646
pub trait TypedEncryptable<Ids: KeyIds, Key: KeyId, Output> {
47-
fn encrypt(
48-
&self,
49-
ctx: &mut KeyStoreContext<Ids>,
50-
key: Key,
51-
) -> Result<Output, CryptoError>;
47+
fn encrypt(&self, ctx: &mut KeyStoreContext<Ids>, key: Key) -> Result<Output, CryptoError>;
5248
}
5349

5450
impl<Ids: KeyIds, Key: KeyId, T: TypedEncryptable<Ids, Key, Output>, Output>
@@ -65,8 +61,7 @@ impl<Ids: KeyIds, Key: KeyId, T: TypedEncryptable<Ids, Key, Output>, Output>
6561
}
6662
}
6763

68-
impl<Ids: KeyIds> TypedEncryptable<Ids, Ids::Symmetric, EncString> for &str
69-
{
64+
impl<Ids: KeyIds> TypedEncryptable<Ids, Ids::Symmetric, EncString> for &str {
7065
fn encrypt(
7166
&self,
7267
ctx: &mut KeyStoreContext<Ids>,
@@ -76,8 +71,7 @@ impl<Ids: KeyIds> TypedEncryptable<Ids, Ids::Symmetric, EncString> for &str
7671
}
7772
}
7873

79-
impl<Ids: KeyIds> TypedEncryptable<Ids, Ids::Symmetric, EncString> for String
80-
{
74+
impl<Ids: KeyIds> TypedEncryptable<Ids, Ids::Symmetric, EncString> for String {
8175
fn encrypt(
8276
&self,
8377
ctx: &mut KeyStoreContext<Ids>,
@@ -87,7 +81,8 @@ impl<Ids: KeyIds> TypedEncryptable<Ids, Ids::Symmetric, EncString> for String
8781
}
8882
}
8983

90-
/// An encryption operation that takes the input value - a primitive such as `Vec<u8>` - and encrypts it into the output value.
84+
/// An encryption operation that takes the input value - a primitive such as `Vec<u8>` - and
85+
/// encrypts it into the output value.
9186
pub trait Encryptable<Ids: KeyIds, Key: KeyId, Output> {
9287
fn encrypt(
9388
&self,
@@ -152,7 +147,8 @@ impl<Ids: KeyIds, Key: KeyId, T: Encryptable<Ids, Key, Output>, Output>
152147
#[cfg(test)]
153148
mod tests {
154149
use crate::{
155-
cose::ContentFormat, traits::tests::*, AsymmetricCryptoKey, Decryptable, Encryptable, KeyStore, SymmetricCryptoKey, TypedEncryptable
150+
cose::ContentFormat, traits::tests::*, AsymmetricCryptoKey, Decryptable, Encryptable,
151+
KeyStore, SymmetricCryptoKey, TypedEncryptable,
156152
};
157153

158154
fn test_store() -> KeyStore<TestIds> {
@@ -207,12 +203,8 @@ mod tests {
207203
let string_data = "Hello, World!".to_string();
208204
let str_data: &str = string_data.as_str();
209205

210-
let string_encrypted = string_data
211-
.encrypt(&mut ctx, key)
212-
.unwrap();
213-
let str_encrypted = str_data
214-
.encrypt(&mut ctx, key)
215-
.unwrap();
206+
let string_encrypted = string_data.encrypt(&mut ctx, key).unwrap();
207+
let str_encrypted = str_data.encrypt(&mut ctx, key).unwrap();
216208

217209
let string_decrypted: String = string_encrypted.decrypt(&mut ctx, key).unwrap();
218210
let str_decrypted: String = str_encrypted.decrypt(&mut ctx, key).unwrap();
@@ -229,9 +221,7 @@ mod tests {
229221

230222
let string_data = Some("Hello, World!".to_string());
231223

232-
let string_encrypted = string_data
233-
.encrypt(&mut ctx, key)
234-
.unwrap();
224+
let string_encrypted = string_data.encrypt(&mut ctx, key).unwrap();
235225

236226
let string_decrypted: Option<String> = string_encrypted.decrypt(&mut ctx, key).unwrap();
237227

@@ -245,17 +235,13 @@ mod tests {
245235

246236
let key = TestSymmKey::A(0);
247237
let none_data: Option<String> = None;
248-
let string_encrypted = none_data
249-
.encrypt(&mut ctx, key)
250-
.unwrap();
238+
let string_encrypted = none_data.encrypt(&mut ctx, key).unwrap();
251239
assert_eq!(string_encrypted, None);
252240

253241
// The None implementation will not do any decrypt operations, so it won't fail even if the
254242
// key doesn't exist
255243
let bad_key = TestSymmKey::B((0, 1));
256-
let string_encrypted_bad = none_data
257-
.encrypt(&mut ctx, bad_key)
258-
.unwrap();
244+
let string_encrypted_bad = none_data.encrypt(&mut ctx, bad_key).unwrap();
259245
assert_eq!(string_encrypted_bad, None);
260246
}
261247
}

crates/bitwarden-exporters/src/export.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ fn encrypt_import(
8080
view.set_new_fido2_credentials(ctx, passkeys)?;
8181
}
8282

83-
let new_cipher = view.encrypt_composite(
84-
ctx,
85-
view.key_identifier(),
86-
)?;
83+
let new_cipher = view.encrypt_composite(ctx, view.key_identifier())?;
8784

8885
Ok(new_cipher)
8986
}

crates/bitwarden-send/src/send.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use bitwarden_core::{
88
require,
99
};
1010
use bitwarden_crypto::{
11-
generate_random_bytes, CompositeEncryptable, ContentFormat, CryptoError, Decryptable, EncString, Encryptable, IdentifyKey, KeyStoreContext, TypedEncryptable
11+
generate_random_bytes, CompositeEncryptable, ContentFormat, CryptoError, Decryptable,
12+
EncString, Encryptable, IdentifyKey, KeyStoreContext, TypedEncryptable,
1213
};
1314
use chrono::{DateTime, Utc};
1415
use serde::{Deserialize, Serialize};

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bitwarden_core::key_management::{KeyIds, SymmetricKeyId};
22
use bitwarden_crypto::{
3-
CompositeEncryptable, ContentFormat, CryptoError, Decryptable, EncString, Encryptable, IdentifyKey, KeyStoreContext, TypedEncryptable
3+
CompositeEncryptable, ContentFormat, CryptoError, Decryptable, EncString, Encryptable,
4+
IdentifyKey, KeyStoreContext, TypedEncryptable,
45
};
56
use serde::{Deserialize, Serialize};
67
#[cfg(feature = "wasm")]
@@ -73,7 +74,9 @@ impl IdentifyKey<SymmetricKeyId> for AttachmentFile {
7374
}
7475
}
7576

76-
impl CompositeEncryptable<KeyIds, SymmetricKeyId, AttachmentEncryptResult> for AttachmentFileView<'_> {
77+
impl CompositeEncryptable<KeyIds, SymmetricKeyId, AttachmentEncryptResult>
78+
for AttachmentFileView<'_>
79+
{
7780
fn encrypt_composite(
7881
&self,
7982
ctx: &mut KeyStoreContext<KeyIds>,

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use bitwarden_api_api::models::CipherCardModel;
22
use bitwarden_core::key_management::{KeyIds, SymmetricKeyId};
33
use bitwarden_crypto::{
4-
CompositeEncryptable, CryptoError, Decryptable, EncString, Encryptable, KeyStoreContext, TypedEncryptable
4+
CompositeEncryptable, CryptoError, Decryptable, EncString, Encryptable, KeyStoreContext,
5+
TypedEncryptable,
56
};
67
use serde::{Deserialize, Serialize};
78
#[cfg(feature = "wasm")]
@@ -59,9 +60,7 @@ impl CompositeEncryptable<KeyIds, SymmetricKeyId, Card> for CardView {
5960
key: SymmetricKeyId,
6061
) -> Result<Card, CryptoError> {
6162
Ok(Card {
62-
cardholder_name: self
63-
.cardholder_name
64-
.encrypt(ctx, key)?,
63+
cardholder_name: self.cardholder_name.encrypt(ctx, key)?,
6564
exp_month: self.exp_month.encrypt(ctx, key)?,
6665
exp_year: self.exp_year.encrypt(ctx, key)?,
6766
code: self.code.encrypt(ctx, key)?,

0 commit comments

Comments
 (0)