Skip to content

Commit e04b781

Browse files
committed
Cargo fmt
1 parent 4e0d585 commit e04b781

File tree

14 files changed

+75
-38
lines changed

14 files changed

+75
-38
lines changed

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, CryptoError, EncString, Kdf, KeyDecryptable, KeyEncryptable, MasterKey, SymmetricCryptoKey, UnsignedSharedKey, UserKey
11+
AsymmetricCryptoKey, CryptoError, EncString, Kdf, KeyDecryptable, KeyEncryptable, MasterKey,
12+
SymmetricCryptoKey, UnsignedSharedKey, UserKey,
1213
};
1314
use serde::{Deserialize, Serialize};
1415
#[cfg(feature = "wasm")]

crates/bitwarden-crypto/src/cose.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,35 @@
33
//! unless there is a a clear benefit, such as a clear cryptographic benefit, which MUST
44
//! be documented publicly.
55
6-
use coset::{iana::{self, CoapContentFormat}, CborSerializable, Label};
6+
use coset::{
7+
iana::{self, CoapContentFormat},
8+
CborSerializable, Label,
9+
};
710
use generic_array::GenericArray;
11+
use serde::{Deserialize, Serialize};
12+
#[cfg(feature = "wasm")]
13+
use tsify_next::Tsify;
814
use typenum::U32;
915

1016
use crate::{
1117
error::EncStringParseError, xchacha20, CryptoError, SymmetricCryptoKey, XChaCha20Poly1305Key,
1218
};
1319

14-
use serde::{Deserialize, Serialize};
15-
#[cfg(feature = "wasm")]
16-
use tsify_next::Tsify;
17-
1820
/// XChaCha20 <https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha-03> is used over ChaCha20
1921
/// to be able to randomly generate nonces, and to not have to worry about key wearout. Since
2022
/// the draft was never published as an RFC, we use a private-use value for the algorithm.
2123
pub(crate) const XCHACHA20_POLY1305: i64 = -70000;
2224
const XCHACHA20_TEXT_PAD_BLOCK_SIZE: usize = 32;
2325

24-
2526
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
2627
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
2728
pub enum ContentFormat {
2829
Utf8,
2930
Pkcs8,
3031
CoseKey,
3132
OctetStream,
32-
/// Domain object should never be serialized. It is used to indicate when we call an encrypt operation
33-
/// on a complex object that consists of multiple, individually encrypted fields
33+
/// Domain object should never be serialized. It is used to indicate when we call an encrypt
34+
/// operation on a complex object that consists of multiple, individually encrypted fields
3435
DomainObject,
3536
}
3637

@@ -49,11 +50,14 @@ pub(crate) fn encrypt_xchacha20_poly1305(
4950
) -> Result<Vec<u8>, CryptoError> {
5051
let protected_header = coset::HeaderBuilder::new();
5152
let protected_header = match content_format {
52-
// UTF-8 directly would leak the plaintext size. This is not acceptable for certain data (passwords).
53+
// UTF-8 directly would leak the plaintext size. This is not acceptable for certain data
54+
// (passwords).
5355
ContentFormat::Utf8 => protected_header.content_type("application/utf8-padded".to_string()),
5456
ContentFormat::Pkcs8 => protected_header.content_format(CoapContentFormat::Pkcs8),
5557
ContentFormat::CoseKey => protected_header.content_format(CoapContentFormat::CoseKey),
56-
ContentFormat::OctetStream => protected_header.content_format(CoapContentFormat::OctetStream),
58+
ContentFormat::OctetStream => {
59+
protected_header.content_format(CoapContentFormat::OctetStream)
60+
}
5761
// This should panic, and should never be implemented to be reachable!
5862
ContentFormat::DomainObject => unreachable!(),
5963
};
@@ -170,7 +174,8 @@ mod test {
170174
};
171175

172176
let plaintext = b"Hello, world!";
173-
let encrypted = encrypt_xchacha20_poly1305(plaintext, key, &ContentFormat::OctetStream).unwrap();
177+
let encrypted =
178+
encrypt_xchacha20_poly1305(plaintext, key, &ContentFormat::OctetStream).unwrap();
174179
let decrypted = decrypt_xchacha20_poly1305(&encrypted, key).unwrap();
175180
assert_eq!(decrypted, plaintext);
176181
}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use serde::Deserialize;
66

77
use super::{check_length, from_b64, from_b64_vec, split_enc_string};
88
use crate::{
9-
error::{CryptoError, EncStringParseError, Result, UnsupportedOperation}, Aes256CbcHmacKey, ContentFormat, KeyDecryptable, KeyEncryptable, SymmetricCryptoKey, XChaCha20Poly1305Key
9+
error::{CryptoError, EncStringParseError, Result, UnsupportedOperation},
10+
Aes256CbcHmacKey, ContentFormat, KeyDecryptable, KeyEncryptable, SymmetricCryptoKey,
11+
XChaCha20Poly1305Key,
1012
};
1113

1214
#[cfg(feature = "wasm")]
@@ -349,7 +351,8 @@ mod tests {
349351

350352
use super::EncString;
351353
use crate::{
352-
derive_symmetric_key, ContentFormat, CryptoError, KeyDecryptable, KeyEncryptable, SymmetricCryptoKey, KEY_ID_SIZE
354+
derive_symmetric_key, ContentFormat, CryptoError, KeyDecryptable, KeyEncryptable,
355+
SymmetricCryptoKey, KEY_ID_SIZE,
353356
};
354357

355358
#[test]
@@ -362,7 +365,10 @@ mod tests {
362365
});
363366

364367
let test_string = "encrypted_test_string";
365-
let cipher = test_string.to_owned().encrypt_with_key(&key, &ContentFormat::Utf8).unwrap();
368+
let cipher = test_string
369+
.to_owned()
370+
.encrypt_with_key(&key, &ContentFormat::Utf8)
371+
.unwrap();
366372
let decrypted_str: String = cipher.decrypt_with_key(&key).unwrap();
367373
assert_eq!(decrypted_str, test_string);
368374
}
@@ -372,7 +378,10 @@ mod tests {
372378
let key = SymmetricCryptoKey::Aes256CbcHmacKey(derive_symmetric_key("test"));
373379

374380
let test_string = "encrypted_test_string";
375-
let cipher = test_string.to_string().encrypt_with_key(&key, &ContentFormat::Utf8).unwrap();
381+
let cipher = test_string
382+
.to_string()
383+
.encrypt_with_key(&key, &ContentFormat::Utf8)
384+
.unwrap();
376385

377386
let decrypted_str: String = cipher.decrypt_with_key(&key).unwrap();
378387
assert_eq!(decrypted_str, test_string);
@@ -383,7 +392,10 @@ mod tests {
383392
let key = SymmetricCryptoKey::Aes256CbcHmacKey(derive_symmetric_key("test"));
384393

385394
let test_string: &'static str = "encrypted_test_string";
386-
let cipher = test_string.to_string().encrypt_with_key(&key, &ContentFormat::Utf8).unwrap();
395+
let cipher = test_string
396+
.to_string()
397+
.encrypt_with_key(&key, &ContentFormat::Utf8)
398+
.unwrap();
387399

388400
let decrypted_str: String = cipher.decrypt_with_key(&key).unwrap();
389401
assert_eq!(decrypted_str, test_string);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
mod key_encryptable;
2-
pub use key_encryptable::{
3-
CryptoKey, KeyContainer, KeyDecryptable, KeyEncryptable,
4-
};
2+
pub use key_encryptable::{CryptoKey, KeyContainer, KeyDecryptable, KeyEncryptable};
53
mod master_key;
64
pub use master_key::{HashPurpose, MasterKey};
75
mod shareable_key;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use super::{
44
utils::stretch_key,
55
};
66
use crate::{
7-
keys::key_encryptable::CryptoKey, ContentFormat, EncString, KeyEncryptable, Result, SymmetricCryptoKey
7+
keys::key_encryptable::CryptoKey, ContentFormat, EncString, KeyEncryptable, Result,
8+
SymmetricCryptoKey,
89
};
910

1011
/// Pin Key.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use zeroize::Zeroizing;
77

88
use super::KeyStoreInner;
99
use crate::{
10-
derive_shareable_key, error::UnsupportedOperation, store::backend::StoreBackend, AsymmetricCryptoKey, ContentFormat, CryptoError, EncString, KeyId, KeyIds, Result, SymmetricCryptoKey, UnsignedSharedKey
10+
derive_shareable_key, error::UnsupportedOperation, store::backend::StoreBackend,
11+
AsymmetricCryptoKey, ContentFormat, CryptoError, EncString, KeyId, KeyIds, Result,
12+
SymmetricCryptoKey, UnsignedSharedKey,
1113
};
1214

1315
/// The context of a crypto operation using [super::KeyStore]
@@ -180,7 +182,7 @@ impl<Ids: KeyIds> KeyStoreContext<'_, Ids> {
180182
.encrypt_data_with_symmetric_key(
181183
wrapping_key,
182184
key_to_wrap_instance.to_encoded().as_slice(),
183-
ContentFormat::OctetStream
185+
ContentFormat::OctetStream,
184186
),
185187
_ => Err(CryptoError::OperationNotSupported(
186188
UnsupportedOperation::EncryptionNotImplementedForKey,

crates/bitwarden-exporters/src/encrypted_json.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ pub(crate) fn export_encrypted_json(
5757
kdf_iterations,
5858
kdf_memory,
5959
kdf_parallelism,
60-
enc_key_validation: enc_key_validation.encrypt_with_key(&key, &ContentFormat::Utf8)?.to_string(),
61-
data: decrypted_export.encrypt_with_key(&key, &ContentFormat::Utf8)?.to_string(),
60+
enc_key_validation: enc_key_validation
61+
.encrypt_with_key(&key, &ContentFormat::Utf8)?
62+
.to_string(),
63+
data: decrypted_export
64+
.encrypt_with_key(&key, &ContentFormat::Utf8)?
65+
.to_string(),
6266
};
6367

6468
Ok(serde_json::to_string_pretty(&encrypted_export)?)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bitwarden_core::key_management::{KeyIds, SymmetricKeyId};
22
use bitwarden_crypto::{
3-
ContentFormat, CryptoError, Decryptable, EncString, Encryptable, IdentifyKey, KeyStoreContext
3+
ContentFormat, CryptoError, Decryptable, EncString, Encryptable, IdentifyKey, KeyStoreContext,
44
};
55
use serde::{Deserialize, Serialize};
66
#[cfg(feature = "wasm")]

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use bitwarden_api_api::models::CipherCardModel;
22
use bitwarden_core::key_management::{KeyIds, SymmetricKeyId};
3-
use bitwarden_crypto::{ContentFormat, CryptoError, Decryptable, EncString, Encryptable, KeyStoreContext};
3+
use bitwarden_crypto::{
4+
ContentFormat, CryptoError, Decryptable, EncString, Encryptable, KeyStoreContext,
5+
};
46
use serde::{Deserialize, Serialize};
57
#[cfg(feature = "wasm")]
68
use tsify_next::Tsify;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bitwarden_core::{
44
require, MissingFieldError, VaultLockedError,
55
};
66
use bitwarden_crypto::{
7-
ContentFormat, CryptoError, Decryptable, EncString, Encryptable, IdentifyKey, KeyStoreContext
7+
ContentFormat, CryptoError, Decryptable, EncString, Encryptable, IdentifyKey, KeyStoreContext,
88
};
99
use bitwarden_error::bitwarden_error;
1010
use chrono::{DateTime, Utc};

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use bitwarden_core::{
33
key_management::{KeyIds, SymmetricKeyId},
44
require,
55
};
6-
use bitwarden_crypto::{ContentFormat, CryptoError, Decryptable, EncString, Encryptable, KeyStoreContext};
6+
use bitwarden_crypto::{
7+
ContentFormat, CryptoError, Decryptable, EncString, Encryptable, KeyStoreContext,
8+
};
79
use serde::{Deserialize, Serialize};
810
use serde_repr::{Deserialize_repr, Serialize_repr};
911
#[cfg(feature = "wasm")]

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use bitwarden_api_api::models::CipherIdentityModel;
22
use bitwarden_core::key_management::{KeyIds, SymmetricKeyId};
3-
use bitwarden_crypto::{ContentFormat, CryptoError, Decryptable, EncString, Encryptable, KeyStoreContext};
3+
use bitwarden_crypto::{
4+
ContentFormat, CryptoError, Decryptable, EncString, Encryptable, KeyStoreContext,
5+
};
46
use serde::{Deserialize, Serialize};
57
#[cfg(feature = "wasm")]
68
use tsify_next::Tsify;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use bitwarden_core::key_management::{KeyIds, SymmetricKeyId};
2-
use bitwarden_crypto::{ContentFormat, CryptoError, Decryptable, EncString, Encryptable, KeyStoreContext};
2+
use bitwarden_crypto::{
3+
ContentFormat, CryptoError, Decryptable, EncString, Encryptable, KeyStoreContext,
4+
};
35
use serde::{Deserialize, Serialize};
46
#[cfg(feature = "wasm")]
57
use tsify_next::Tsify;

crates/bitwarden-wasm-internal/src/pure_crypto.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::str::FromStr;
22

33
use bitwarden_crypto::{
4-
ContentFormat, CryptoError, EncString, Kdf, KeyDecryptable, KeyEncryptable, MasterKey, SymmetricCryptoKey,
4+
ContentFormat, CryptoError, EncString, Kdf, KeyDecryptable, KeyEncryptable, MasterKey,
5+
SymmetricCryptoKey,
56
};
67
use wasm_bindgen::prelude::*;
78

@@ -52,15 +53,17 @@ impl PureCrypto {
5253
}
5354

5455
pub fn symmetric_encrypt_string(plain: String, key: Vec<u8>) -> Result<String, CryptoError> {
55-
plain.encrypt_with_key(
56-
&SymmetricCryptoKey::try_from(key)?,
57-
&ContentFormat::Utf8
58-
).map(|enc| enc.to_string())
56+
plain
57+
.encrypt_with_key(&SymmetricCryptoKey::try_from(key)?, &ContentFormat::Utf8)
58+
.map(|enc| enc.to_string())
5959
}
6060

6161
pub fn symmetric_encrypt_bytes(plain: Vec<u8>, key: Vec<u8>) -> Result<String, CryptoError> {
6262
plain
63-
.encrypt_with_key(&SymmetricCryptoKey::try_from(key)?, &ContentFormat::OctetStream)
63+
.encrypt_with_key(
64+
&SymmetricCryptoKey::try_from(key)?,
65+
&ContentFormat::OctetStream,
66+
)
6467
.map(|enc| enc.to_string())
6568
}
6669

@@ -69,7 +72,10 @@ impl PureCrypto {
6972
key: Vec<u8>,
7073
) -> Result<Vec<u8>, CryptoError> {
7174
plain
72-
.encrypt_with_key(&SymmetricCryptoKey::try_from(key)?, &ContentFormat::OctetStream)?
75+
.encrypt_with_key(
76+
&SymmetricCryptoKey::try_from(key)?,
77+
&ContentFormat::OctetStream,
78+
)?
7379
.to_buffer()
7480
}
7581

0 commit comments

Comments
 (0)