From 7fa811a3ea5e7d20665beae735c67ac81981488b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garci=CC=81a?= Date: Wed, 3 Sep 2025 18:40:34 +0200 Subject: [PATCH 1/2] Rename Error variants --- bitwarden_license/bitwarden-sm/src/error.rs | 12 ++--- crates/bitwarden-collections/src/error.rs | 2 +- .../src/client/encryption_settings.rs | 2 +- crates/bitwarden-core/src/error.rs | 2 +- .../src/key_management/crypto.rs | 2 +- .../src/platform/generate_fingerprint.rs | 2 +- crates/bitwarden-crypto/src/error.rs | 8 +-- crates/bitwarden-crypto/src/rsa.rs | 2 +- .../safe/password_protected_key_envelope.rs | 52 ++++++++----------- crates/bitwarden-exporters/src/cxf/ssh.rs | 2 +- crates/bitwarden-exporters/src/error.rs | 8 +-- crates/bitwarden-fido/src/authenticator.rs | 42 +++++++-------- crates/bitwarden-fido/src/client.rs | 2 +- crates/bitwarden-fido/src/client_fido.rs | 2 +- crates/bitwarden-fido/src/lib.rs | 4 +- crates/bitwarden-fido/src/types.rs | 4 +- crates/bitwarden-generators/src/passphrase.rs | 2 +- crates/bitwarden-ipc/src/ipc_client.rs | 4 +- crates/bitwarden-ipc/src/rpc/error.rs | 8 +-- crates/bitwarden-ipc/src/rpc/exec/handler.rs | 10 ++-- .../bitwarden-ipc/src/rpc/request_message.rs | 2 +- crates/bitwarden-send/src/error.rs | 2 +- crates/bitwarden-send/src/send_client.rs | 4 ++ crates/bitwarden-ssh/src/error.rs | 8 +-- crates/bitwarden-ssh/src/export.rs | 12 ++--- crates/bitwarden-ssh/src/generator.rs | 8 +-- crates/bitwarden-ssh/src/import.rs | 28 +++++----- crates/bitwarden-ssh/src/lib.rs | 2 +- crates/bitwarden-vault/src/cipher/cipher.rs | 6 +-- crates/bitwarden-vault/src/error.rs | 2 +- crates/bitwarden-vault/src/totp.rs | 2 +- 31 files changed, 121 insertions(+), 127 deletions(-) diff --git a/bitwarden_license/bitwarden-sm/src/error.rs b/bitwarden_license/bitwarden-sm/src/error.rs index 76203759b..bc3bcd003 100644 --- a/bitwarden_license/bitwarden-sm/src/error.rs +++ b/bitwarden_license/bitwarden-sm/src/error.rs @@ -6,18 +6,18 @@ use validator::ValidationErrors; #[derive(Debug, thiserror::Error)] pub enum SecretsManagerError { #[error(transparent)] - ValidationError(ValidationError), + Validation(ValidationError), #[error(transparent)] VaultLocked(#[from] bitwarden_core::VaultLockedError), #[error(transparent)] - CryptoError(#[from] bitwarden_crypto::CryptoError), + Crypto(#[from] bitwarden_crypto::CryptoError), #[error(transparent)] Chrono(#[from] chrono::ParseError), #[error(transparent)] - ApiError(#[from] bitwarden_core::ApiError), + Api(#[from] bitwarden_core::ApiError), #[error(transparent)] - MissingFieldError(#[from] bitwarden_core::MissingFieldError), + MissingField(#[from] bitwarden_core::MissingFieldError), } // Validation @@ -80,12 +80,12 @@ impl From for ValidationError { impl From for SecretsManagerError { fn from(e: ValidationErrors) -> Self { - SecretsManagerError::ValidationError(e.into()) + SecretsManagerError::Validation(e.into()) } } impl From> for SecretsManagerError { fn from(e: bitwarden_api_api::apis::Error) -> Self { - SecretsManagerError::ApiError(e.into()) + SecretsManagerError::Api(e.into()) } } diff --git a/crates/bitwarden-collections/src/error.rs b/crates/bitwarden-collections/src/error.rs index c7e921ec7..638aa75b1 100644 --- a/crates/bitwarden-collections/src/error.rs +++ b/crates/bitwarden-collections/src/error.rs @@ -15,5 +15,5 @@ pub enum CollectionsParseError { #[error(transparent)] Crypto(#[from] bitwarden_crypto::CryptoError), #[error(transparent)] - MissingFieldError(#[from] bitwarden_core::MissingFieldError), + MissingField(#[from] bitwarden_core::MissingFieldError), } diff --git a/crates/bitwarden-core/src/client/encryption_settings.rs b/crates/bitwarden-core/src/client/encryption_settings.rs index 2a8ff2c1c..90613454e 100644 --- a/crates/bitwarden-core/src/client/encryption_settings.rs +++ b/crates/bitwarden-core/src/client/encryption_settings.rs @@ -44,7 +44,7 @@ pub enum EncryptionSettingsError { MissingPrivateKey(#[from] MissingPrivateKeyError), #[error(transparent)] - UserIdAlreadySetError(#[from] UserIdAlreadySetError), + UserIdAlreadySet(#[from] UserIdAlreadySetError), #[error("Wrong Pin")] WrongPin, diff --git a/crates/bitwarden-core/src/error.rs b/crates/bitwarden-core/src/error.rs index 996d7d43d..256111e63 100644 --- a/crates/bitwarden-core/src/error.rs +++ b/crates/bitwarden-core/src/error.rs @@ -94,7 +94,7 @@ pub enum StatefulCryptoError { got: u32, }, #[error("Crypto error, {0}")] - CryptoError(#[from] bitwarden_crypto::CryptoError), + Crypto(#[from] bitwarden_crypto::CryptoError), } /// This macro is used to require that a value is present or return an error otherwise. diff --git a/crates/bitwarden-core/src/key_management/crypto.rs b/crates/bitwarden-core/src/key_management/crypto.rs index 4c61279e9..6ab83216c 100644 --- a/crates/bitwarden-core/src/key_management/crypto.rs +++ b/crates/bitwarden-core/src/key_management/crypto.rs @@ -668,7 +668,7 @@ pub(crate) fn make_v2_keys_for_v1_user( // V1 user must have a private key to upgrade. This should be ensured by the client before // calling the upgrade function. if !ctx.has_asymmetric_key(AsymmetricKeyId::UserPrivateKey) { - return Err(StatefulCryptoError::CryptoError(CryptoError::MissingKeyId( + return Err(StatefulCryptoError::Crypto(CryptoError::MissingKeyId( "UserPrivateKey".to_string(), ))); } diff --git a/crates/bitwarden-core/src/platform/generate_fingerprint.rs b/crates/bitwarden-core/src/platform/generate_fingerprint.rs index 8de1702cd..2e930b3bd 100644 --- a/crates/bitwarden-core/src/platform/generate_fingerprint.rs +++ b/crates/bitwarden-core/src/platform/generate_fingerprint.rs @@ -35,7 +35,7 @@ pub struct FingerprintResponse { #[derive(Debug, Error)] pub enum FingerprintError { #[error(transparent)] - CryptoError(#[from] bitwarden_crypto::CryptoError), + Crypto(#[from] bitwarden_crypto::CryptoError), } pub(crate) fn generate_fingerprint(input: &FingerprintRequest) -> Result { diff --git a/crates/bitwarden-crypto/src/error.rs b/crates/bitwarden-crypto/src/error.rs index 18b584da9..34092327a 100644 --- a/crates/bitwarden-crypto/src/error.rs +++ b/crates/bitwarden-crypto/src/error.rs @@ -39,10 +39,10 @@ pub enum CryptoError { EncString(#[from] EncStringParseError), #[error("Rsa error, {0}")] - RsaError(#[from] RsaError), + Rsa(#[from] RsaError), #[error("Fingerprint error, {0}")] - FingerprintError(#[from] FingerprintError), + Fingerprint(#[from] FingerprintError), #[error("Argon2 error, {0}")] ArgonError(#[from] argon2::Error), @@ -66,10 +66,10 @@ pub enum CryptoError { InvalidPadding, #[error("Signature error, {0}")] - SignatureError(#[from] SignatureError), + Signature(#[from] SignatureError), #[error("Encoding error, {0}")] - EncodingError(#[from] EncodingError), + Encoding(#[from] EncodingError), } #[derive(Debug, Error)] diff --git a/crates/bitwarden-crypto/src/rsa.rs b/crates/bitwarden-crypto/src/rsa.rs index 66adc5284..d0b2f5806 100644 --- a/crates/bitwarden-crypto/src/rsa.rs +++ b/crates/bitwarden-crypto/src/rsa.rs @@ -61,5 +61,5 @@ pub(super) fn encrypt_rsa2048_oaep_sha1(public_key: &RsaPublicKey, data: &[u8]) let padding = Oaep::new::(); public_key .encrypt(&mut rng, padding, data) - .map_err(|e| CryptoError::RsaError(e.into())) + .map_err(|e| CryptoError::Rsa(e.into())) } diff --git a/crates/bitwarden-crypto/src/safe/password_protected_key_envelope.rs b/crates/bitwarden-crypto/src/safe/password_protected_key_envelope.rs index 233efeb51..1c21332cd 100644 --- a/crates/bitwarden-crypto/src/safe/password_protected_key_envelope.rs +++ b/crates/bitwarden-crypto/src/safe/password_protected_key_envelope.rs @@ -64,7 +64,7 @@ impl PasswordProtectedKeyEnvelope { #[allow(deprecated)] let key_ref = ctx .dangerous_get_symmetric_key(key_to_seal) - .map_err(|_| PasswordProtectedKeyEnvelopeError::KeyMissingError)?; + .map_err(|_| PasswordProtectedKeyEnvelopeError::KeyMissing)?; Self::seal_ref(key_ref, password) } @@ -97,7 +97,7 @@ impl PasswordProtectedKeyEnvelope { // The envelope key is directly derived from the KDF and used as the key to encrypt the key // that should be sealed. let envelope_key = derive_key(kdf_settings, password) - .map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)?; + .map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)?; let (content_format, key_to_seal_bytes) = match key_to_seal.to_encoded_raw() { EncodedSymmetricKey::BitwardenLegacyKey(key_bytes) => { @@ -145,7 +145,7 @@ impl PasswordProtectedKeyEnvelope { let key = self.unseal_ref(password)?; #[allow(deprecated)] ctx.set_symmetric_key(target_keyslot, key) - .map_err(|_| PasswordProtectedKeyEnvelopeError::KeyStoreError)?; + .map_err(|_| PasswordProtectedKeyEnvelopeError::KeyStore)?; Ok(target_keyslot) } @@ -161,34 +161,32 @@ impl PasswordProtectedKeyEnvelope { .first() .filter(|_| self.cose_encrypt.recipients.len() == 1) .ok_or_else(|| { - PasswordProtectedKeyEnvelopeError::ParsingError( + PasswordProtectedKeyEnvelopeError::Parsing( "Invalid number of recipients".to_string(), ) })?; if recipient.protected.header.alg != Some(coset::Algorithm::PrivateUse(ALG_ARGON2ID13)) { - return Err(PasswordProtectedKeyEnvelopeError::ParsingError( + return Err(PasswordProtectedKeyEnvelopeError::Parsing( "Unknown or unsupported KDF algorithm".to_string(), )); } let kdf_settings: Argon2RawSettings = (&recipient.unprotected).try_into().map_err(|_| { - PasswordProtectedKeyEnvelopeError::ParsingError( + PasswordProtectedKeyEnvelopeError::Parsing( "Invalid or missing KDF parameters".to_string(), ) })?; let envelope_key = derive_key(&kdf_settings, password) - .map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)?; + .map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)?; let nonce: [u8; crate::xchacha20::NONCE_SIZE] = self .cose_encrypt .unprotected .iv .clone() .try_into() - .map_err(|_| { - PasswordProtectedKeyEnvelopeError::ParsingError("Invalid IV".to_string()) - })?; + .map_err(|_| PasswordProtectedKeyEnvelopeError::Parsing("Invalid IV".to_string()))?; let key_bytes = self .cose_encrypt @@ -201,9 +199,7 @@ impl PasswordProtectedKeyEnvelope { SymmetricCryptoKey::try_from( match ContentFormat::try_from(&self.cose_encrypt.protected.header).map_err(|_| { - PasswordProtectedKeyEnvelopeError::ParsingError( - "Invalid content format".to_string(), - ) + PasswordProtectedKeyEnvelopeError::Parsing("Invalid content format".to_string()) })? { ContentFormat::BitwardenLegacyKey => EncodedSymmetricKey::BitwardenLegacyKey( BitwardenLegacyKeyBytes::from(key_bytes), @@ -212,15 +208,13 @@ impl PasswordProtectedKeyEnvelope { EncodedSymmetricKey::CoseKey(CoseKeyBytes::from(key_bytes)) } _ => { - return Err(PasswordProtectedKeyEnvelopeError::ParsingError( + return Err(PasswordProtectedKeyEnvelopeError::Parsing( "Unknown or unsupported content format".to_string(), )); } }, ) - .map_err(|_| { - PasswordProtectedKeyEnvelopeError::ParsingError("Failed to decode key".to_string()) - }) + .map_err(|_| PasswordProtectedKeyEnvelopeError::Parsing("Failed to decode key".to_string())) } /// Re-seals the key with new KDF parameters (updated settings, salt), and a new password @@ -268,12 +262,12 @@ impl FromStr for PasswordProtectedKeyEnvelope { fn from_str(s: &str) -> Result { let data = B64::try_from(s).map_err(|_| { - PasswordProtectedKeyEnvelopeError::ParsingError( + PasswordProtectedKeyEnvelopeError::Parsing( "Invalid PasswordProtectedKeyEnvelope Base64 encoding".to_string(), ) })?; Self::try_from(&data.into_bytes()).map_err(|_| { - PasswordProtectedKeyEnvelopeError::ParsingError( + PasswordProtectedKeyEnvelopeError::Parsing( "Failed to parse PasswordProtectedKeyEnvelope".to_string(), ) }) @@ -373,7 +367,7 @@ impl TryInto for &Argon2RawSettings { self.parallelism, Some(ENVELOPE_ARGON2_OUTPUT_KEY_SIZE), ) - .map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError) + .map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf) } } @@ -388,9 +382,7 @@ impl TryInto for &Header { salt: extract_bytes(self, ARGON2_SALT, "salt")? .try_into() .map_err(|_| { - PasswordProtectedKeyEnvelopeError::ParsingError( - "Invalid Argon2 salt".to_string(), - ) + PasswordProtectedKeyEnvelopeError::Parsing("Invalid Argon2 salt".to_string()) })?, }) } @@ -415,7 +407,7 @@ fn derive_key( argon2_settings.try_into()?, ) .hash_password_into(password.as_bytes(), &argon2_settings.salt, &mut hash) - .map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)?; + .map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)?; Ok(hash) } @@ -428,29 +420,29 @@ pub enum PasswordProtectedKeyEnvelopeError { WrongPassword, /// The envelope could not be parsed correctly, or the KDF parameters are invalid #[error("Parsing error {0}")] - ParsingError(String), + Parsing(String), /// The KDF failed to derive a key, possibly due to invalid parameters or memory allocation /// issues #[error("Kdf error")] - KdfError, + Kdf, /// There is no key for the provided key id in the key store #[error("Key missing error")] - KeyMissingError, + KeyMissing, /// The key store could not be written to, for example due to being read-only #[error("Could not write to key store")] - KeyStoreError, + KeyStore, } impl From for PasswordProtectedKeyEnvelopeError { fn from(err: CoseExtractError) -> Self { let CoseExtractError::MissingValue(label) = err; - PasswordProtectedKeyEnvelopeError::ParsingError(format!("Missing value for {}", label)) + PasswordProtectedKeyEnvelopeError::Parsing(format!("Missing value for {}", label)) } } impl From for PasswordProtectedKeyEnvelopeError { fn from(err: TryFromIntError) -> Self { - PasswordProtectedKeyEnvelopeError::ParsingError(format!("Invalid integer: {}", err)) + PasswordProtectedKeyEnvelopeError::Parsing(format!("Invalid integer: {}", err)) } } diff --git a/crates/bitwarden-exporters/src/cxf/ssh.rs b/crates/bitwarden-exporters/src/cxf/ssh.rs index 232c967cb..305c23948 100644 --- a/crates/bitwarden-exporters/src/cxf/ssh.rs +++ b/crates/bitwarden-exporters/src/cxf/ssh.rs @@ -79,7 +79,7 @@ fn extract_key_type(public_key: &str) -> Result { let key_type = public_key .split_whitespace() .next() - .ok_or(SshKeyExportError::KeyConversionError)?; + .ok_or(SshKeyExportError::KeyConversion)?; Ok(key_type.to_string()) } diff --git a/crates/bitwarden-exporters/src/error.rs b/crates/bitwarden-exporters/src/error.rs index 062d7a9de..e4d1cebec 100644 --- a/crates/bitwarden-exporters/src/error.rs +++ b/crates/bitwarden-exporters/src/error.rs @@ -15,14 +15,14 @@ pub enum ExportError { #[error("CSV error: {0}")] Csv(#[from] crate::csv::CsvError), #[error("Credential Exchange error: {0}")] - CxfError(#[from] crate::cxf::CxfError), + Cxf(#[from] crate::cxf::CxfError), #[error("JSON error: {0}")] Json(#[from] crate::json::JsonError), #[error("Encrypted JSON error: {0}")] - EncryptedJsonError(#[from] crate::encrypted_json::EncryptedJsonError), + EncryptedJson(#[from] crate::encrypted_json::EncryptedJsonError), #[error(transparent)] - BitwardenCryptoError(#[from] bitwarden_crypto::CryptoError), + BitwardenCrypto(#[from] bitwarden_crypto::CryptoError), #[error(transparent)] - CipherError(#[from] bitwarden_vault::CipherError), + Cipher(#[from] bitwarden_vault::CipherError), } diff --git a/crates/bitwarden-fido/src/authenticator.rs b/crates/bitwarden-fido/src/authenticator.rs index ba1972d09..72f6f0009 100644 --- a/crates/bitwarden-fido/src/authenticator.rs +++ b/crates/bitwarden-fido/src/authenticator.rs @@ -33,14 +33,14 @@ pub enum GetSelectedCredentialError { #[error(transparent)] VaultLocked(#[from] VaultLockedError), #[error(transparent)] - CryptoError(#[from] CryptoError), + Crypto(#[from] CryptoError), } #[allow(missing_docs)] #[derive(Debug, Error)] pub enum MakeCredentialError { #[error(transparent)] - PublicKeyCredentialParametersError(#[from] PublicKeyCredentialParametersError), + PublicKeyCredentialParameters(#[from] PublicKeyCredentialParametersError), #[error(transparent)] UnknownEnum(#[from] UnknownEnum), #[error(transparent)] @@ -59,7 +59,7 @@ pub enum GetAssertionError { #[error(transparent)] Serde(#[from] serde_json::Error), #[error(transparent)] - GetSelectedCredentialError(#[from] GetSelectedCredentialError), + GetSelectedCredential(#[from] GetSelectedCredentialError), #[error(transparent)] InvalidGuid(#[from] InvalidGuid), #[error("missing user")] @@ -72,30 +72,30 @@ pub enum GetAssertionError { #[derive(Debug, Error)] pub enum SilentlyDiscoverCredentialsError { #[error(transparent)] - CipherError(#[from] CipherError), + Cipher(#[from] CipherError), #[error(transparent)] VaultLocked(#[from] VaultLockedError), #[error(transparent)] InvalidGuid(#[from] InvalidGuid), #[error(transparent)] - Fido2CallbackError(#[from] Fido2CallbackError), + Fido2Callback(#[from] Fido2CallbackError), #[error(transparent)] - FromCipherViewError(#[from] Fido2CredentialAutofillViewError), + FromCipherView(#[from] Fido2CredentialAutofillViewError), } #[allow(missing_docs)] #[derive(Debug, Error)] pub enum CredentialsForAutofillError { #[error(transparent)] - CipherError(#[from] CipherError), + Cipher(#[from] CipherError), #[error(transparent)] VaultLocked(#[from] VaultLockedError), #[error(transparent)] InvalidGuid(#[from] InvalidGuid), #[error(transparent)] - Fido2CallbackError(#[from] Fido2CallbackError), + Fido2Callback(#[from] Fido2CallbackError), #[error(transparent)] - FromCipherViewError(#[from] Fido2CredentialAutofillViewError), + FromCipherView(#[from] Fido2CredentialAutofillViewError), } #[allow(missing_docs)] @@ -361,11 +361,11 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> { #[error(transparent)] VaultLocked(#[from] VaultLockedError), #[error(transparent)] - CipherError(#[from] CipherError), + Cipher(#[from] CipherError), #[error(transparent)] - CryptoError(#[from] CryptoError), + Crypto(#[from] CryptoError), #[error(transparent)] - Fido2CallbackError(#[from] Fido2CallbackError), + Fido2Callback(#[from] Fido2CallbackError), } // This is just a wrapper around the actual implementation to allow for ? error handling @@ -445,13 +445,13 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> { #[error(transparent)] VaultLocked(#[from] VaultLockedError), #[error(transparent)] - FillCredentialError(#[from] FillCredentialError), + FillCredential(#[from] FillCredentialError), #[error(transparent)] - CipherError(#[from] CipherError), + Cipher(#[from] CipherError), #[error(transparent)] - CryptoError(#[from] CryptoError), + Crypto(#[from] CryptoError), #[error(transparent)] - Fido2CallbackError(#[from] Fido2CallbackError), + Fido2Callback(#[from] Fido2CallbackError), #[error("No selected credential available")] NoSelectedCredential, @@ -527,15 +527,15 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> { #[error("Credential ID does not match selected credential")] CredentialIdMismatch, #[error(transparent)] - FillCredentialError(#[from] FillCredentialError), + FillCredential(#[from] FillCredentialError), #[error(transparent)] - CipherError(#[from] CipherError), + Cipher(#[from] CipherError), #[error(transparent)] - CryptoError(#[from] CryptoError), + Crypto(#[from] CryptoError), #[error(transparent)] - Fido2CallbackError(#[from] Fido2CallbackError), + Fido2Callback(#[from] Fido2CallbackError), #[error(transparent)] - GetSelectedCredentialError(#[from] GetSelectedCredentialError), + GetSelectedCredential(#[from] GetSelectedCredentialError), } // This is just a wrapper around the actual implementation to allow for ? error handling diff --git a/crates/bitwarden-fido/src/client.rs b/crates/bitwarden-fido/src/client.rs index 9ecaf52e8..8913c2292 100644 --- a/crates/bitwarden-fido/src/client.rs +++ b/crates/bitwarden-fido/src/client.rs @@ -21,7 +21,7 @@ pub enum Fido2ClientError { #[error(transparent)] Serde(#[from] serde_json::Error), #[error(transparent)] - GetSelectedCredentialError(#[from] GetSelectedCredentialError), + GetSelectedCredential(#[from] GetSelectedCredentialError), #[error("Webauthn error: {0:?}")] Webauthn(WebauthnError), diff --git a/crates/bitwarden-fido/src/client_fido.rs b/crates/bitwarden-fido/src/client_fido.rs index 49af1d10b..560eac3cb 100644 --- a/crates/bitwarden-fido/src/client_fido.rs +++ b/crates/bitwarden-fido/src/client_fido.rs @@ -19,7 +19,7 @@ pub enum DecryptFido2AutofillCredentialsError { #[error(transparent)] VaultLocked(#[from] bitwarden_core::VaultLockedError), #[error(transparent)] - Fido2CredentialAutofillViewError(#[from] Fido2CredentialAutofillViewError), + Fido2CredentialAutofillView(#[from] Fido2CredentialAutofillViewError), } impl ClientFido2 { diff --git a/crates/bitwarden-fido/src/lib.rs b/crates/bitwarden-fido/src/lib.rs index 52d11b4b2..1f8113eb2 100644 --- a/crates/bitwarden-fido/src/lib.rs +++ b/crates/bitwarden-fido/src/lib.rs @@ -78,7 +78,7 @@ impl CipherViewContainer { #[derive(Debug, Error)] pub enum Fido2Error { #[error(transparent)] - DecodeError(#[from] NotB64UrlEncoded), + Decode(#[from] NotB64UrlEncoded), #[error(transparent)] UnknownEnum(#[from] UnknownEnum), @@ -87,7 +87,7 @@ pub enum Fido2Error { InvalidGuid(#[from] InvalidGuid), #[error(transparent)] - PrivateKeyFromSecretKeyError(#[from] PrivateKeyFromSecretKeyError), + PrivateKeyFromSecretKey(#[from] PrivateKeyFromSecretKeyError), #[error("No Fido2 credentials found")] NoFido2CredentialsFound, diff --git a/crates/bitwarden-fido/src/types.rs b/crates/bitwarden-fido/src/types.rs index 4f62bc167..7cf366b36 100644 --- a/crates/bitwarden-fido/src/types.rs +++ b/crates/bitwarden-fido/src/types.rs @@ -62,10 +62,10 @@ pub enum Fido2CredentialAutofillViewError { InvalidGuid(#[from] InvalidGuid), #[error(transparent)] - CryptoError(#[from] CryptoError), + Crypto(#[from] CryptoError), #[error(transparent)] - Base64DecodeError(#[from] NotB64UrlEncoded), + Base64Decode(#[from] NotB64UrlEncoded), } impl Fido2CredentialAutofillView { diff --git a/crates/bitwarden-generators/src/passphrase.rs b/crates/bitwarden-generators/src/passphrase.rs index c7921c437..e8aba4139 100644 --- a/crates/bitwarden-generators/src/passphrase.rs +++ b/crates/bitwarden-generators/src/passphrase.rs @@ -10,7 +10,7 @@ use tsify::Tsify; use crate::util::capitalize_first_letter; #[allow(missing_docs)] -#[bitwarden_error(flat)] +#[bitwarden_error(full)] #[derive(Debug, Error)] pub enum PassphraseError { #[error("'num_words' must be between {} and {}", minimum, maximum)] diff --git a/crates/bitwarden-ipc/src/ipc_client.rs b/crates/bitwarden-ipc/src/ipc_client.rs index 43f155631..95495deda 100644 --- a/crates/bitwarden-ipc/src/ipc_client.rs +++ b/crates/bitwarden-ipc/src/ipc_client.rs @@ -127,7 +127,7 @@ pub enum RequestError { Send(String), #[error("Error occured on the remote target: {0}")] - RpcError(#[from] RpcError), + Rpc(#[from] RpcError), } impl IpcClient @@ -313,7 +313,7 @@ where } .try_into() .map_err(|e: serde_utils::DeserializeError| { - RequestError::RpcError(RpcError::RequestSerializationError(e.to_string())) + RequestError::Rpc(RpcError::RequestSerialization(e.to_string())) })?; self.send(message) diff --git a/crates/bitwarden-ipc/src/rpc/error.rs b/crates/bitwarden-ipc/src/rpc/error.rs index eb9ebd5e8..4cce428d2 100644 --- a/crates/bitwarden-ipc/src/rpc/error.rs +++ b/crates/bitwarden-ipc/src/rpc/error.rs @@ -6,16 +6,16 @@ use crate::serde_utils; #[derive(Debug, Error, Clone, Serialize, Deserialize, PartialEq, Eq)] pub enum RpcError { #[error("Failed to read request: {0}")] - RequestDeserializationError(String), + RequestDeserialization(String), #[error("Failed to serialize request: {0}")] - RequestSerializationError(String), + RequestSerialization(String), #[error("Failed to read response: {0}")] - ResponseDeserializationError(String), + ResponseDeserialization(String), #[error("Failed to serialize response: {0}")] - ResponseSerializationError(String), + ResponseSerialization(String), #[error("Request could not be completed because no handler has been registered for")] NoHandlerFound, diff --git a/crates/bitwarden-ipc/src/rpc/exec/handler.rs b/crates/bitwarden-ipc/src/rpc/exec/handler.rs index 5c5410588..d9c04c679 100644 --- a/crates/bitwarden-ipc/src/rpc/exec/handler.rs +++ b/crates/bitwarden-ipc/src/rpc/exec/handler.rs @@ -46,21 +46,19 @@ where type Request = T::Request; fn serialize_request(&self, request: Self::Request) -> Result, RpcError> { - serde_utils::to_vec(&request) - .map_err(|e| RpcError::RequestSerializationError(e.to_string())) + serde_utils::to_vec(&request).map_err(|e| RpcError::RequestSerialization(e.to_string())) } fn deserialize_request(&self, request: Vec) -> Result { serde_utils::from_slice(&request) - .map_err(|e| RpcError::RequestDeserializationError(e.to_string())) + .map_err(|e| RpcError::RequestDeserialization(e.to_string())) } fn serialize_response( &self, request: ::Response, ) -> Result, RpcError> { - serde_utils::to_vec(&request) - .map_err(|e| RpcError::ResponseSerializationError(e.to_string())) + serde_utils::to_vec(&request).map_err(|e| RpcError::ResponseSerialization(e.to_string())) } fn deserialize_response( @@ -68,7 +66,7 @@ where request: Vec, ) -> Result<::Response, RpcError> { serde_utils::from_slice(&request) - .map_err(|e| RpcError::ResponseDeserializationError(e.to_string())) + .map_err(|e| RpcError::ResponseDeserialization(e.to_string())) } } diff --git a/crates/bitwarden-ipc/src/rpc/request_message.rs b/crates/bitwarden-ipc/src/rpc/request_message.rs index 8fe4dd07c..3f7c147b6 100644 --- a/crates/bitwarden-ipc/src/rpc/request_message.rs +++ b/crates/bitwarden-ipc/src/rpc/request_message.rs @@ -37,7 +37,7 @@ impl RpcRequestPayload { T: RpcRequest, { serde_utils::from_slice(&self.data) - .map_err(|e| RpcError::RequestDeserializationError(e.to_string())) + .map_err(|e| RpcError::RequestDeserialization(e.to_string())) } } diff --git a/crates/bitwarden-send/src/error.rs b/crates/bitwarden-send/src/error.rs index 6c9ef9788..d224a82ad 100644 --- a/crates/bitwarden-send/src/error.rs +++ b/crates/bitwarden-send/src/error.rs @@ -8,5 +8,5 @@ pub enum SendParseError { #[error(transparent)] Crypto(#[from] bitwarden_crypto::CryptoError), #[error(transparent)] - MissingFieldError(#[from] bitwarden_core::MissingFieldError), + MissingField(#[from] bitwarden_core::MissingFieldError), } diff --git a/crates/bitwarden-send/src/send_client.rs b/crates/bitwarden-send/src/send_client.rs index f703f47f4..f9e413d84 100644 --- a/crates/bitwarden-send/src/send_client.rs +++ b/crates/bitwarden-send/src/send_client.rs @@ -11,6 +11,7 @@ use crate::{Send, SendListView, SendView}; /// Generic error type for send encryption errors. #[allow(missing_docs)] #[derive(Debug, Error)] +#[cfg_attr(feature = "uniffi", derive(uniffi::Error), uniffi(flat_error))] pub enum SendEncryptError { #[error(transparent)] Crypto(#[from] bitwarden_crypto::CryptoError), @@ -21,6 +22,7 @@ pub enum SendEncryptError { /// Generic error type for send decryption errors #[allow(missing_docs)] #[derive(Debug, Error)] +#[cfg_attr(feature = "uniffi", derive(uniffi::Error), uniffi(flat_error))] pub enum SendDecryptError { #[error(transparent)] Crypto(#[from] bitwarden_crypto::CryptoError), @@ -31,6 +33,7 @@ pub enum SendDecryptError { /// Generic error type for send encryption errors. #[allow(missing_docs)] #[derive(Debug, Error)] +#[cfg_attr(feature = "uniffi", derive(uniffi::Error), uniffi(flat_error))] pub enum SendEncryptFileError { #[error(transparent)] Encrypt(#[from] SendEncryptError), @@ -41,6 +44,7 @@ pub enum SendEncryptFileError { /// Generic error type for send decryption errors #[allow(missing_docs)] #[derive(Debug, Error)] +#[cfg_attr(feature = "uniffi", derive(uniffi::Error), uniffi(flat_error))] pub enum SendDecryptFileError { #[error(transparent)] Decrypt(#[from] SendDecryptError), diff --git a/crates/bitwarden-ssh/src/error.rs b/crates/bitwarden-ssh/src/error.rs index 635b7da10..8fb457993 100644 --- a/crates/bitwarden-ssh/src/error.rs +++ b/crates/bitwarden-ssh/src/error.rs @@ -6,9 +6,9 @@ use thiserror::Error; #[derive(Error, Debug)] pub enum KeyGenerationError { #[error("Failed to generate key: {0}")] - KeyGenerationError(ssh_key::Error), + KeyGeneration(ssh_key::Error), #[error("Failed to convert key")] - KeyConversionError, + KeyConversion, } #[allow(missing_docs)] @@ -16,7 +16,7 @@ pub enum KeyGenerationError { #[derive(Error, Debug, PartialEq)] pub enum SshKeyImportError { #[error("Failed to parse key")] - ParsingError, + Parsing, #[error("Password required")] PasswordRequired, #[error("Wrong password")] @@ -30,5 +30,5 @@ pub enum SshKeyImportError { #[derive(Error, Debug, PartialEq)] pub enum SshKeyExportError { #[error("Failed to convert key")] - KeyConversionError, + KeyConversion, } diff --git a/crates/bitwarden-ssh/src/export.rs b/crates/bitwarden-ssh/src/export.rs index 0c4170760..44c0bc3b7 100644 --- a/crates/bitwarden-ssh/src/export.rs +++ b/crates/bitwarden-ssh/src/export.rs @@ -26,27 +26,27 @@ fn convert_rsa_keypair(keypair: &RsaKeypair) -> Result Result, SshKeyExportError> { // Parse the OpenSSH private key let private_key = - PrivateKey::from_openssh(private_key).map_err(|_| SshKeyExportError::KeyConversionError)?; + PrivateKey::from_openssh(private_key).map_err(|_| SshKeyExportError::KeyConversion)?; match private_key.key_data() { ssh_key::private::KeypairData::Ed25519(keypair) => { let sk: ed25519_dalek::SigningKey = keypair .try_into() - .map_err(|_| SshKeyExportError::KeyConversionError)?; + .map_err(|_| SshKeyExportError::KeyConversion)?; Ok(sk .to_pkcs8_der() - .map_err(|_| SshKeyExportError::KeyConversionError)? + .map_err(|_| SshKeyExportError::KeyConversion)? .as_bytes() .to_vec()) } ssh_key::private::KeypairData::Rsa(keypair) => Ok(convert_rsa_keypair(keypair) - .map_err(|_| SshKeyExportError::KeyConversionError)? + .map_err(|_| SshKeyExportError::KeyConversion)? .to_pkcs8_der() - .map_err(|_| SshKeyExportError::KeyConversionError)? + .map_err(|_| SshKeyExportError::KeyConversion)? .as_bytes() .to_vec()), - _ => Err(SshKeyExportError::KeyConversionError), + _ => Err(SshKeyExportError::KeyConversion), } } diff --git a/crates/bitwarden-ssh/src/generator.rs b/crates/bitwarden-ssh/src/generator.rs index 1a95b13bb..fcd16980b 100644 --- a/crates/bitwarden-ssh/src/generator.rs +++ b/crates/bitwarden-ssh/src/generator.rs @@ -36,12 +36,12 @@ fn generate_sshkey_internal( ) -> Result { let private_key = match key_algorithm { KeyAlgorithm::Ed25519 => ssh_key::PrivateKey::random(&mut rng, Algorithm::Ed25519) - .map_err(KeyGenerationError::KeyGenerationError), + .map_err(KeyGenerationError::KeyGeneration), KeyAlgorithm::Rsa3072 => create_rsa_key(&mut rng, 3072), KeyAlgorithm::Rsa4096 => create_rsa_key(&mut rng, 4096), }?; - ssh_private_key_to_view(private_key).map_err(|_| KeyGenerationError::KeyConversionError) + ssh_private_key_to_view(private_key).map_err(|_| KeyGenerationError::KeyConversion) } fn create_rsa_key( @@ -49,10 +49,10 @@ fn create_rsa_key( bits: usize, ) -> Result { let rsa_keypair = ssh_key::private::RsaKeypair::random(&mut rng, bits) - .map_err(KeyGenerationError::KeyGenerationError)?; + .map_err(KeyGenerationError::KeyGeneration)?; let private_key = ssh_key::PrivateKey::new(ssh_key::private::KeypairData::from(rsa_keypair), "") - .map_err(KeyGenerationError::KeyGenerationError)?; + .map_err(KeyGenerationError::KeyGeneration)?; Ok(private_key) } diff --git a/crates/bitwarden-ssh/src/import.rs b/crates/bitwarden-ssh/src/import.rs index e586eb99e..df51dbd72 100644 --- a/crates/bitwarden-ssh/src/import.rs +++ b/crates/bitwarden-ssh/src/import.rs @@ -13,13 +13,13 @@ use crate::{error::SshKeyImportError, ssh_private_key_to_view}; /// - [SshKeyImportError::PasswordRequired] if the key is encrypted and no password is provided /// - [SshKeyImportError::WrongPassword] if the password provided is incorrect /// - [SshKeyImportError::UnsupportedKeyType] if the key type is not supported -/// - [SshKeyImportError::ParsingError] if the key is otherwise malformed and cannot be parsed +/// - [SshKeyImportError::Parsing] if the key is otherwise malformed and cannot be parsed pub fn import_key( encoded_key: String, password: Option, ) -> Result { let label = pem_rfc7468::decode_label(encoded_key.as_bytes()) - .map_err(|_| SshKeyImportError::ParsingError)?; + .map_err(|_| SshKeyImportError::Parsing)?; match label { pkcs8::PrivateKeyInfo::PEM_LABEL => import_pkcs8_key(encoded_key, None), @@ -42,11 +42,11 @@ fn import_pkcs8_key( pkcs8::Error::EncryptedPrivateKey(pkcs5::Error::DecryptFailed) => { SshKeyImportError::WrongPassword } - _ => SshKeyImportError::ParsingError, + _ => SshKeyImportError::Parsing, }, )? } else { - SecretDocument::from_pkcs8_pem(&encoded_key).map_err(|_| SshKeyImportError::ParsingError)? + SecretDocument::from_pkcs8_pem(&encoded_key).map_err(|_| SshKeyImportError::Parsing)? }; import_pkcs8_der_key(doc.as_bytes()) @@ -56,29 +56,29 @@ fn import_pkcs8_key( /// importing SSH keys from other Credential Managers through Credential Exchange. pub fn import_pkcs8_der_key(encoded_key: &[u8]) -> Result { let private_key_info = - PrivateKeyInfo::from_der(encoded_key).map_err(|_| SshKeyImportError::ParsingError)?; + PrivateKeyInfo::from_der(encoded_key).map_err(|_| SshKeyImportError::Parsing)?; let private_key = match private_key_info.algorithm.oid { ed25519::pkcs8::ALGORITHM_OID => { let private_key: ed25519::KeypairBytes = private_key_info .try_into() - .map_err(|_| SshKeyImportError::ParsingError)?; + .map_err(|_| SshKeyImportError::Parsing)?; ssh_key::private::PrivateKey::from(Ed25519Keypair::from(&private_key.secret_key.into())) } rsa::pkcs1::ALGORITHM_OID => { let private_key: rsa::RsaPrivateKey = private_key_info .try_into() - .map_err(|_| SshKeyImportError::ParsingError)?; + .map_err(|_| SshKeyImportError::Parsing)?; ssh_key::private::PrivateKey::from( - RsaKeypair::try_from(private_key).map_err(|_| SshKeyImportError::ParsingError)?, + RsaKeypair::try_from(private_key).map_err(|_| SshKeyImportError::Parsing)?, ) } _ => return Err(SshKeyImportError::UnsupportedKeyType), }; - ssh_private_key_to_view(private_key).map_err(|_| SshKeyImportError::ParsingError) + ssh_private_key_to_view(private_key).map_err(|_| SshKeyImportError::Parsing) } fn import_openssh_key( @@ -90,7 +90,7 @@ fn import_openssh_key( ssh_key::Error::AlgorithmUnknown | ssh_key::Error::AlgorithmUnsupported { .. } => { SshKeyImportError::UnsupportedKeyType } - _ => SshKeyImportError::ParsingError, + _ => SshKeyImportError::Parsing, })?; let private_key = if private_key.is_encrypted() { @@ -102,7 +102,7 @@ fn import_openssh_key( private_key }; - ssh_private_key_to_view(private_key).map_err(|_| SshKeyImportError::ParsingError) + ssh_private_key_to_view(private_key).map_err(|_| SshKeyImportError::Parsing) } #[cfg(test)] @@ -182,7 +182,7 @@ mod tests { #[test] fn import_non_key_error() { let result = import_key("not a key".to_string(), Some("".to_string())); - assert_eq!(result.unwrap_err(), SshKeyImportError::ParsingError); + assert_eq!(result.unwrap_err(), SshKeyImportError::Parsing); } #[test] @@ -207,7 +207,7 @@ mod tests { fn import_key_ed25519_putty() { let private_key = include_str!("../resources/import/ed25519_putty_openssh_unencrypted"); let result = import_key(private_key.to_string(), Some("".to_string())); - assert_eq!(result.unwrap_err(), SshKeyImportError::ParsingError); + assert_eq!(result.unwrap_err(), SshKeyImportError::Parsing); } // Putty-exported keys should be supported, but are not due to a parser incompatibility. @@ -218,7 +218,7 @@ mod tests { fn import_key_rsa_openssh_putty() { let private_key = include_str!("../resources/import/rsa_putty_openssh_unencrypted"); let result = import_key(private_key.to_string(), Some("".to_string())); - assert_eq!(result.unwrap_err(), SshKeyImportError::ParsingError); + assert_eq!(result.unwrap_err(), SshKeyImportError::Parsing); } #[test] diff --git a/crates/bitwarden-ssh/src/lib.rs b/crates/bitwarden-ssh/src/lib.rs index febbf0498..92a9629c5 100644 --- a/crates/bitwarden-ssh/src/lib.rs +++ b/crates/bitwarden-ssh/src/lib.rs @@ -20,7 +20,7 @@ uniffi::setup_scaffolding!(); fn ssh_private_key_to_view(value: PrivateKey) -> Result { let private_key_openssh = value .to_openssh(LineEnding::LF) - .map_err(|_| SshKeyExportError::KeyConversionError)?; + .map_err(|_| SshKeyExportError::KeyConversion)?; Ok(SshKeyView { private_key: private_key_openssh.to_string(), diff --git a/crates/bitwarden-vault/src/cipher/cipher.rs b/crates/bitwarden-vault/src/cipher/cipher.rs index c3cd40ee9..37d5603cc 100644 --- a/crates/bitwarden-vault/src/cipher/cipher.rs +++ b/crates/bitwarden-vault/src/cipher/cipher.rs @@ -40,13 +40,13 @@ uuid_newtype!(pub CipherId); #[derive(Debug, Error)] pub enum CipherError { #[error(transparent)] - MissingFieldError(#[from] MissingFieldError), + MissingField(#[from] MissingFieldError), #[error(transparent)] VaultLocked(#[from] VaultLockedError), #[error(transparent)] - CryptoError(#[from] CryptoError), + Crypto(#[from] CryptoError), #[error(transparent)] - EncryptError(#[from] EncryptError), + Encrypt(#[from] EncryptError), #[error("This cipher contains attachments without keys. Those attachments will need to be reuploaded to complete the operation")] AttachmentsWithoutKeys, } diff --git a/crates/bitwarden-vault/src/error.rs b/crates/bitwarden-vault/src/error.rs index e014da04a..cf4b63177 100644 --- a/crates/bitwarden-vault/src/error.rs +++ b/crates/bitwarden-vault/src/error.rs @@ -33,5 +33,5 @@ pub enum VaultParseError { #[error(transparent)] Crypto(#[from] bitwarden_crypto::CryptoError), #[error(transparent)] - MissingFieldError(#[from] bitwarden_core::MissingFieldError), + MissingField(#[from] bitwarden_core::MissingFieldError), } diff --git a/crates/bitwarden-vault/src/totp.rs b/crates/bitwarden-vault/src/totp.rs index 446379631..a2becc837 100644 --- a/crates/bitwarden-vault/src/totp.rs +++ b/crates/bitwarden-vault/src/totp.rs @@ -40,7 +40,7 @@ pub enum TotpError { MissingSecret, #[error(transparent)] - CryptoError(#[from] CryptoError), + Crypto(#[from] CryptoError), #[error(transparent)] VaultLocked(#[from] VaultLockedError), } From cc44546fd37c355c42f4d5113a9a2dec7cd2e724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garci=CC=81a?= Date: Mon, 15 Sep 2025 17:52:18 +0200 Subject: [PATCH 2/2] Remove accidental copies --- crates/bitwarden-generators/src/passphrase.rs | 2 +- crates/bitwarden-send/src/send_client.rs | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/bitwarden-generators/src/passphrase.rs b/crates/bitwarden-generators/src/passphrase.rs index e8aba4139..c7921c437 100644 --- a/crates/bitwarden-generators/src/passphrase.rs +++ b/crates/bitwarden-generators/src/passphrase.rs @@ -10,7 +10,7 @@ use tsify::Tsify; use crate::util::capitalize_first_letter; #[allow(missing_docs)] -#[bitwarden_error(full)] +#[bitwarden_error(flat)] #[derive(Debug, Error)] pub enum PassphraseError { #[error("'num_words' must be between {} and {}", minimum, maximum)] diff --git a/crates/bitwarden-send/src/send_client.rs b/crates/bitwarden-send/src/send_client.rs index 546d422eb..1cd7edbe6 100644 --- a/crates/bitwarden-send/src/send_client.rs +++ b/crates/bitwarden-send/src/send_client.rs @@ -11,7 +11,6 @@ use crate::{Send, SendListView, SendView}; /// Generic error type for send encryption errors. #[allow(missing_docs)] #[derive(Debug, Error)] -#[cfg_attr(feature = "uniffi", derive(uniffi::Error), uniffi(flat_error))] pub enum SendEncryptError { #[error(transparent)] Crypto(#[from] bitwarden_crypto::CryptoError), @@ -20,7 +19,6 @@ pub enum SendEncryptError { /// Generic error type for send decryption errors #[allow(missing_docs)] #[derive(Debug, Error)] -#[cfg_attr(feature = "uniffi", derive(uniffi::Error), uniffi(flat_error))] pub enum SendDecryptError { #[error(transparent)] Crypto(#[from] bitwarden_crypto::CryptoError), @@ -29,7 +27,6 @@ pub enum SendDecryptError { /// Generic error type for send encryption errors. #[allow(missing_docs)] #[derive(Debug, Error)] -#[cfg_attr(feature = "uniffi", derive(uniffi::Error), uniffi(flat_error))] pub enum SendEncryptFileError { #[error(transparent)] Encrypt(#[from] SendEncryptError), @@ -40,7 +37,6 @@ pub enum SendEncryptFileError { /// Generic error type for send decryption errors #[allow(missing_docs)] #[derive(Debug, Error)] -#[cfg_attr(feature = "uniffi", derive(uniffi::Error), uniffi(flat_error))] pub enum SendDecryptFileError { #[error(transparent)] Decrypt(#[from] SendDecryptError),