Skip to content

Commit

Permalink
SM-837: Removed redundant to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
mzieniukbw committed Jun 24, 2024
1 parent b1651e3 commit b9b0c61
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 42 deletions.
6 changes: 6 additions & 0 deletions crates/bitwarden-crypto/src/enc_string/symmetric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ impl KeyEncryptable<SymmetricCryptoKey, EncString> for String {
}
}

impl KeyEncryptable<SymmetricCryptoKey, EncString> for &str {
fn encrypt_with_key(self, key: &SymmetricCryptoKey) -> Result<EncString> {
self.as_bytes().encrypt_with_key(key)
}

Check warning on line 272 in crates/bitwarden-crypto/src/enc_string/symmetric.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-crypto/src/enc_string/symmetric.rs#L270-L272

Added lines #L270 - L272 were not covered by tests
}

impl KeyDecryptable<SymmetricCryptoKey, String> for EncString {
fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result<String> {
let dec: Vec<u8> = self.decrypt_with_key(key)?;
Expand Down
8 changes: 1 addition & 7 deletions crates/bitwarden/src/secrets_manager/projects/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ pub(crate) async fn create_project(
.ok_or(VaultLocked)?;

let project = Some(ProjectCreateRequestModel {
name: input
.name
.trim()
.to_string()
.clone()
.encrypt_with_key(key)?
.to_string(),
name: input.name.clone().trim().encrypt_with_key(key)?.to_string(),

Check warning on line 36 in crates/bitwarden/src/secrets_manager/projects/create.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/secrets_manager/projects/create.rs#L36

Added line #L36 was not covered by tests
});

let config = client.get_api_configurations().await;
Expand Down
8 changes: 1 addition & 7 deletions crates/bitwarden/src/secrets_manager/projects/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ pub(crate) async fn update_project(
.ok_or(VaultLocked)?;

let project = Some(ProjectUpdateRequestModel {
name: input
.name
.trim()
.to_string()
.clone()
.encrypt_with_key(key)?
.to_string(),
name: input.name.clone().trim().encrypt_with_key(key)?.to_string(),

Check warning on line 38 in crates/bitwarden/src/secrets_manager/projects/update.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/secrets_manager/projects/update.rs#L38

Added line #L38 was not covered by tests
});

let config = client.get_api_configurations().await;
Expand Down
16 changes: 2 additions & 14 deletions crates/bitwarden/src/secrets_manager/secrets/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,9 @@ pub(crate) async fn create_secret(
.ok_or(VaultLocked)?;

let secret = Some(SecretCreateRequestModel {
key: input
.key
.trim()
.to_string()
.clone()
.encrypt_with_key(key)?
.to_string(),
key: input.key.clone().trim().encrypt_with_key(key)?.to_string(),

Check warning on line 44 in crates/bitwarden/src/secrets_manager/secrets/create.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/secrets_manager/secrets/create.rs#L44

Added line #L44 was not covered by tests
value: input.value.clone().encrypt_with_key(key)?.to_string(),
note: input
.note
.trim()
.to_string()
.clone()
.encrypt_with_key(key)?
.to_string(),
note: input.note.clone().trim().encrypt_with_key(key)?.to_string(),

Check warning on line 46 in crates/bitwarden/src/secrets_manager/secrets/create.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/secrets_manager/secrets/create.rs#L46

Added line #L46 was not covered by tests
project_ids: input.project_ids.clone(),
});

Expand Down
16 changes: 2 additions & 14 deletions crates/bitwarden/src/secrets_manager/secrets/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,9 @@ pub(crate) async fn update_secret(
.ok_or(VaultLocked)?;

let secret = Some(SecretUpdateRequestModel {
key: input
.key
.trim()
.to_string()
.clone()
.encrypt_with_key(key)?
.to_string(),
key: input.key.clone().trim().encrypt_with_key(key)?.to_string(),

Check warning on line 43 in crates/bitwarden/src/secrets_manager/secrets/update.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/secrets_manager/secrets/update.rs#L43

Added line #L43 was not covered by tests
value: input.value.clone().encrypt_with_key(key)?.to_string(),
note: input
.note
.trim()
.to_string()
.clone()
.encrypt_with_key(key)?
.to_string(),
note: input.note.clone().trim().encrypt_with_key(key)?.to_string(),

Check warning on line 45 in crates/bitwarden/src/secrets_manager/secrets/update.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/secrets_manager/secrets/update.rs#L45

Added line #L45 was not covered by tests
project_ids: input.project_ids.clone(),
});

Expand Down

0 comments on commit b9b0c61

Please sign in to comment.