Skip to content

Commit

Permalink
Deny unused async (#838)
Browse files Browse the repository at this point in the history
We currently use async on several methods that don't actually require
it. This PR enables the clippy rule which will warn if any async is
unnecessary. It also resolves all existing usages.
  • Loading branch information
Hinton authored Jun 13, 2024
1 parent 3f56e58 commit 6c18348
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 234 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bitwarden-generators = { path = "crates/bitwarden-generators", version = "=0.5.0
bitwarden-vault = { path = "crates/bitwarden-vault", version = "=0.5.0" }

[workspace.lints.clippy]
unused_async = "deny"
unwrap_used = "deny"

# Compile all dependencies with some optimizations when building this crate on debug
Expand Down
2 changes: 0 additions & 2 deletions crates/bitwarden-uniffi/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl ClientAuth {
.await
.auth()
.password_strength(password, email, additional_inputs)
.await
}

/// Evaluate if the provided password satisfies the provided policy
Expand All @@ -42,7 +41,6 @@ impl ClientAuth {
.await
.auth()
.satisfies_policy(password, strength, &policy)
.await
}

/// Hash the user password
Expand Down
8 changes: 3 additions & 5 deletions crates/bitwarden-uniffi/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ impl ClientCrypto {
.write()
.await
.crypto()
.update_password(new_password)
.await?)
.update_password(new_password)?)
}

/// Generates a PIN protected user key from the provided PIN. The result can be stored and later
/// used to initialize another client instance by using the PIN and the PIN key with
/// `initialize_user_crypto`.
pub async fn derive_pin_key(&self, pin: String) -> Result<DerivePinKeyResponse> {
Ok(self.0 .0.write().await.crypto().derive_pin_key(pin).await?)
Ok(self.0 .0.write().await.crypto().derive_pin_key(pin)?)
}

/// Derives the pin protected user key from encrypted pin. Used when pin requires master
Expand All @@ -80,8 +79,7 @@ impl ClientCrypto {
.write()
.await
.crypto()
.derive_pin_user_key(encrypted_pin)
.await?)
.derive_pin_user_key(encrypted_pin)?)
}

pub async fn enroll_admin_password_reset(
Expand Down
24 changes: 4 additions & 20 deletions crates/bitwarden-uniffi/src/tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,12 @@ pub struct ClientGenerators(pub(crate) Arc<Client>);
impl ClientGenerators {
/// **API Draft:** Generate Password
pub async fn password(&self, settings: PasswordGeneratorRequest) -> Result<String> {
Ok(self
.0
.0
.read()
.await
.generator()
.password(settings)
.await?)
Ok(self.0 .0.read().await.generator().password(settings)?)
}

/// **API Draft:** Generate Passphrase
pub async fn passphrase(&self, settings: PassphraseGeneratorRequest) -> Result<String> {
Ok(self
.0
.0
.read()
.await
.generator()
.passphrase(settings)
.await?)
Ok(self.0 .0.read().await.generator().passphrase(settings)?)
}

/// **API Draft:** Generate Username
Expand Down Expand Up @@ -71,8 +57,7 @@ impl ClientExporters {
.read()
.await
.exporters()
.export_vault(folders, ciphers, format)
.await?)
.export_vault(folders, ciphers, format)?)
}

/// **API Draft:** Export organization vault
Expand All @@ -88,7 +73,6 @@ impl ClientExporters {
.read()
.await
.exporters()
.export_organization_vault(collections, ciphers, format)
.await?)
.export_organization_vault(collections, ciphers, format)?)
}
}
46 changes: 15 additions & 31 deletions crates/bitwarden-uniffi/src/tool/sends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct ClientSends(pub Arc<Client>);
impl ClientSends {
/// Encrypt send
pub async fn encrypt(&self, send: SendView) -> Result<Send> {
Ok(self.0 .0.write().await.sends().encrypt(send).await?)
Ok(self.0 .0.write().await.sends().encrypt(send)?)
}

/// Encrypt a send file in memory
Expand All @@ -22,8 +22,7 @@ impl ClientSends {
.write()
.await
.sends()
.encrypt_buffer(send, &buffer)
.await?)
.encrypt_buffer(send, &buffer)?)
}

/// Encrypt a send file located in the file system
Expand All @@ -33,28 +32,21 @@ impl ClientSends {
decrypted_file_path: String,
encrypted_file_path: String,
) -> Result<()> {
Ok(self
.0
.0
.write()
.await
.sends()
.encrypt_file(
send,
Path::new(&decrypted_file_path),
Path::new(&encrypted_file_path),
)
.await?)
Ok(self.0 .0.write().await.sends().encrypt_file(
send,
Path::new(&decrypted_file_path),
Path::new(&encrypted_file_path),
)?)
}

/// Decrypt send
pub async fn decrypt(&self, send: Send) -> Result<SendView> {
Ok(self.0 .0.write().await.sends().decrypt(send).await?)
Ok(self.0 .0.write().await.sends().decrypt(send)?)
}

/// Decrypt send list
pub async fn decrypt_list(&self, sends: Vec<Send>) -> Result<Vec<SendListView>> {
Ok(self.0 .0.write().await.sends().decrypt_list(sends).await?)
Ok(self.0 .0.write().await.sends().decrypt_list(sends)?)
}

/// Decrypt a send file in memory
Expand All @@ -65,8 +57,7 @@ impl ClientSends {
.write()
.await
.sends()
.decrypt_buffer(send, &buffer)
.await?)
.decrypt_buffer(send, &buffer)?)
}

/// Decrypt a send file located in the file system
Expand All @@ -76,17 +67,10 @@ impl ClientSends {
encrypted_file_path: String,
decrypted_file_path: String,
) -> Result<()> {
Ok(self
.0
.0
.write()
.await
.sends()
.decrypt_file(
send,
Path::new(&encrypted_file_path),
Path::new(&decrypted_file_path),
)
.await?)
Ok(self.0 .0.write().await.sends().decrypt_file(
send,
Path::new(&encrypted_file_path),
Path::new(&decrypted_file_path),
)?)
}
}
46 changes: 14 additions & 32 deletions crates/bitwarden-uniffi/src/vault/attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ impl ClientAttachments {
.await
.vault()
.attachments()
.encrypt_buffer(cipher, attachment, &buffer)
.await?)
.encrypt_buffer(cipher, attachment, &buffer)?)
}

/// Encrypt an attachment file located in the file system
Expand All @@ -35,20 +34,12 @@ impl ClientAttachments {
decrypted_file_path: String,
encrypted_file_path: String,
) -> Result<Attachment> {
Ok(self
.0
.0
.write()
.await
.vault()
.attachments()
.encrypt_file(
cipher,
attachment,
Path::new(&decrypted_file_path),
Path::new(&encrypted_file_path),
)
.await?)
Ok(self.0 .0.write().await.vault().attachments().encrypt_file(
cipher,
attachment,
Path::new(&decrypted_file_path),
Path::new(&encrypted_file_path),
)?)
}
/// Decrypt an attachment file in memory
pub async fn decrypt_buffer(
Expand All @@ -64,8 +55,7 @@ impl ClientAttachments {
.await
.vault()
.attachments()
.decrypt_buffer(cipher, attachment, &buffer)
.await?)
.decrypt_buffer(cipher, attachment, &buffer)?)
}

/// Decrypt an attachment file located in the file system
Expand All @@ -76,19 +66,11 @@ impl ClientAttachments {
encrypted_file_path: String,
decrypted_file_path: String,
) -> Result<()> {
Ok(self
.0
.0
.write()
.await
.vault()
.attachments()
.decrypt_file(
cipher,
attachment,
Path::new(&encrypted_file_path),
Path::new(&decrypted_file_path),
)
.await?)
Ok(self.0 .0.write().await.vault().attachments().decrypt_file(
cipher,
attachment,
Path::new(&encrypted_file_path),
Path::new(&decrypted_file_path),
)?)
}
}
19 changes: 4 additions & 15 deletions crates/bitwarden-uniffi/src/vault/ciphers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,12 @@ impl ClientCiphers {
.await
.vault()
.ciphers()
.encrypt(cipher_view)
.await?)
.encrypt(cipher_view)?)
}

/// Decrypt cipher
pub async fn decrypt(&self, cipher: Cipher) -> Result<CipherView> {
Ok(self
.0
.0
.write()
.await
.vault()
.ciphers()
.decrypt(cipher)
.await?)
Ok(self.0 .0.write().await.vault().ciphers().decrypt(cipher)?)
}

/// Decrypt cipher list
Expand All @@ -45,8 +36,7 @@ impl ClientCiphers {
.await
.vault()
.ciphers()
.decrypt_list(ciphers)
.await?)
.decrypt_list(ciphers)?)
}

/// Move a cipher to an organization, reencrypting the cipher key if necessary
Expand All @@ -62,7 +52,6 @@ impl ClientCiphers {
.await
.vault()
.ciphers()
.move_to_organization(cipher, organization_id)
.await?)
.move_to_organization(cipher, organization_id)?)
}
}
6 changes: 2 additions & 4 deletions crates/bitwarden-uniffi/src/vault/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ impl ClientCollections {
.await
.vault()
.collections()
.decrypt(collection)
.await?)
.decrypt(collection)?)
}

/// Decrypt collection list
Expand All @@ -31,7 +30,6 @@ impl ClientCollections {
.await
.vault()
.collections()
.decrypt_list(collections)
.await?)
.decrypt_list(collections)?)
}
}
23 changes: 3 additions & 20 deletions crates/bitwarden-uniffi/src/vault/folders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,12 @@ pub struct ClientFolders(pub Arc<Client>);
impl ClientFolders {
/// Encrypt folder
pub async fn encrypt(&self, folder: FolderView) -> Result<Folder> {
Ok(self
.0
.0
.write()
.await
.vault()
.folders()
.encrypt(folder)
.await?)
Ok(self.0 .0.write().await.vault().folders().encrypt(folder)?)
}

/// Decrypt folder
pub async fn decrypt(&self, folder: Folder) -> Result<FolderView> {
Ok(self
.0
.0
.write()
.await
.vault()
.folders()
.decrypt(folder)
.await?)
Ok(self.0 .0.write().await.vault().folders().decrypt(folder)?)
}

/// Decrypt folder list
Expand All @@ -44,7 +28,6 @@ impl ClientFolders {
.await
.vault()
.folders()
.decrypt_list(folders)
.await?)
.decrypt_list(folders)?)
}
}
6 changes: 2 additions & 4 deletions crates/bitwarden-uniffi/src/vault/password_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ impl ClientPasswordHistory {
.await
.vault()
.password_history()
.encrypt(password_history)
.await?)
.encrypt(password_history)?)
}

/// Decrypt password history
Expand All @@ -34,7 +33,6 @@ impl ClientPasswordHistory {
.await
.vault()
.password_history()
.decrypt_list(list)
.await?)
.decrypt_list(list)?)
}
}
4 changes: 2 additions & 2 deletions crates/bitwarden/src/auth/client_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'a> ClientAuth<'a> {

#[cfg(feature = "internal")]
impl<'a> ClientAuth<'a> {
pub async fn password_strength(
pub fn password_strength(
&self,
password: String,
email: String,
Expand All @@ -55,7 +55,7 @@ impl<'a> ClientAuth<'a> {
password_strength(password, email, additional_inputs)
}

pub async fn satisfies_policy(
pub fn satisfies_policy(
&self,
password: String,
strength: u8,
Expand Down
Loading

0 comments on commit 6c18348

Please sign in to comment.