Skip to content

Commit 7fa811a

Browse files
committed
Rename Error variants
1 parent fa0e024 commit 7fa811a

File tree

31 files changed

+121
-127
lines changed

31 files changed

+121
-127
lines changed

bitwarden_license/bitwarden-sm/src/error.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ use validator::ValidationErrors;
66
#[derive(Debug, thiserror::Error)]
77
pub enum SecretsManagerError {
88
#[error(transparent)]
9-
ValidationError(ValidationError),
9+
Validation(ValidationError),
1010
#[error(transparent)]
1111
VaultLocked(#[from] bitwarden_core::VaultLockedError),
1212
#[error(transparent)]
13-
CryptoError(#[from] bitwarden_crypto::CryptoError),
13+
Crypto(#[from] bitwarden_crypto::CryptoError),
1414
#[error(transparent)]
1515
Chrono(#[from] chrono::ParseError),
1616

1717
#[error(transparent)]
18-
ApiError(#[from] bitwarden_core::ApiError),
18+
Api(#[from] bitwarden_core::ApiError),
1919
#[error(transparent)]
20-
MissingFieldError(#[from] bitwarden_core::MissingFieldError),
20+
MissingField(#[from] bitwarden_core::MissingFieldError),
2121
}
2222

2323
// Validation
@@ -80,12 +80,12 @@ impl From<ValidationErrors> for ValidationError {
8080

8181
impl From<ValidationErrors> for SecretsManagerError {
8282
fn from(e: ValidationErrors) -> Self {
83-
SecretsManagerError::ValidationError(e.into())
83+
SecretsManagerError::Validation(e.into())
8484
}
8585
}
8686

8787
impl<T> From<ApiApisError<T>> for SecretsManagerError {
8888
fn from(e: bitwarden_api_api::apis::Error<T>) -> Self {
89-
SecretsManagerError::ApiError(e.into())
89+
SecretsManagerError::Api(e.into())
9090
}
9191
}

crates/bitwarden-collections/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ pub enum CollectionsParseError {
1515
#[error(transparent)]
1616
Crypto(#[from] bitwarden_crypto::CryptoError),
1717
#[error(transparent)]
18-
MissingFieldError(#[from] bitwarden_core::MissingFieldError),
18+
MissingField(#[from] bitwarden_core::MissingFieldError),
1919
}

crates/bitwarden-core/src/client/encryption_settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum EncryptionSettingsError {
4444
MissingPrivateKey(#[from] MissingPrivateKeyError),
4545

4646
#[error(transparent)]
47-
UserIdAlreadySetError(#[from] UserIdAlreadySetError),
47+
UserIdAlreadySet(#[from] UserIdAlreadySetError),
4848

4949
#[error("Wrong Pin")]
5050
WrongPin,

crates/bitwarden-core/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub enum StatefulCryptoError {
9494
got: u32,
9595
},
9696
#[error("Crypto error, {0}")]
97-
CryptoError(#[from] bitwarden_crypto::CryptoError),
97+
Crypto(#[from] bitwarden_crypto::CryptoError),
9898
}
9999

100100
/// This macro is used to require that a value is present or return an error otherwise.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ pub(crate) fn make_v2_keys_for_v1_user(
668668
// V1 user must have a private key to upgrade. This should be ensured by the client before
669669
// calling the upgrade function.
670670
if !ctx.has_asymmetric_key(AsymmetricKeyId::UserPrivateKey) {
671-
return Err(StatefulCryptoError::CryptoError(CryptoError::MissingKeyId(
671+
return Err(StatefulCryptoError::Crypto(CryptoError::MissingKeyId(
672672
"UserPrivateKey".to_string(),
673673
)));
674674
}

crates/bitwarden-core/src/platform/generate_fingerprint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct FingerprintResponse {
3535
#[derive(Debug, Error)]
3636
pub enum FingerprintError {
3737
#[error(transparent)]
38-
CryptoError(#[from] bitwarden_crypto::CryptoError),
38+
Crypto(#[from] bitwarden_crypto::CryptoError),
3939
}
4040

4141
pub(crate) fn generate_fingerprint(input: &FingerprintRequest) -> Result<String, FingerprintError> {

crates/bitwarden-crypto/src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ pub enum CryptoError {
3939
EncString(#[from] EncStringParseError),
4040

4141
#[error("Rsa error, {0}")]
42-
RsaError(#[from] RsaError),
42+
Rsa(#[from] RsaError),
4343

4444
#[error("Fingerprint error, {0}")]
45-
FingerprintError(#[from] FingerprintError),
45+
Fingerprint(#[from] FingerprintError),
4646

4747
#[error("Argon2 error, {0}")]
4848
ArgonError(#[from] argon2::Error),
@@ -66,10 +66,10 @@ pub enum CryptoError {
6666
InvalidPadding,
6767

6868
#[error("Signature error, {0}")]
69-
SignatureError(#[from] SignatureError),
69+
Signature(#[from] SignatureError),
7070

7171
#[error("Encoding error, {0}")]
72-
EncodingError(#[from] EncodingError),
72+
Encoding(#[from] EncodingError),
7373
}
7474

7575
#[derive(Debug, Error)]

crates/bitwarden-crypto/src/rsa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ pub(super) fn encrypt_rsa2048_oaep_sha1(public_key: &RsaPublicKey, data: &[u8])
6161
let padding = Oaep::new::<Sha1>();
6262
public_key
6363
.encrypt(&mut rng, padding, data)
64-
.map_err(|e| CryptoError::RsaError(e.into()))
64+
.map_err(|e| CryptoError::Rsa(e.into()))
6565
}

crates/bitwarden-crypto/src/safe/password_protected_key_envelope.rs

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
6464
#[allow(deprecated)]
6565
let key_ref = ctx
6666
.dangerous_get_symmetric_key(key_to_seal)
67-
.map_err(|_| PasswordProtectedKeyEnvelopeError::KeyMissingError)?;
67+
.map_err(|_| PasswordProtectedKeyEnvelopeError::KeyMissing)?;
6868
Self::seal_ref(key_ref, password)
6969
}
7070

@@ -97,7 +97,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
9797
// The envelope key is directly derived from the KDF and used as the key to encrypt the key
9898
// that should be sealed.
9999
let envelope_key = derive_key(kdf_settings, password)
100-
.map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)?;
100+
.map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)?;
101101

102102
let (content_format, key_to_seal_bytes) = match key_to_seal.to_encoded_raw() {
103103
EncodedSymmetricKey::BitwardenLegacyKey(key_bytes) => {
@@ -145,7 +145,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
145145
let key = self.unseal_ref(password)?;
146146
#[allow(deprecated)]
147147
ctx.set_symmetric_key(target_keyslot, key)
148-
.map_err(|_| PasswordProtectedKeyEnvelopeError::KeyStoreError)?;
148+
.map_err(|_| PasswordProtectedKeyEnvelopeError::KeyStore)?;
149149
Ok(target_keyslot)
150150
}
151151

@@ -161,34 +161,32 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
161161
.first()
162162
.filter(|_| self.cose_encrypt.recipients.len() == 1)
163163
.ok_or_else(|| {
164-
PasswordProtectedKeyEnvelopeError::ParsingError(
164+
PasswordProtectedKeyEnvelopeError::Parsing(
165165
"Invalid number of recipients".to_string(),
166166
)
167167
})?;
168168

169169
if recipient.protected.header.alg != Some(coset::Algorithm::PrivateUse(ALG_ARGON2ID13)) {
170-
return Err(PasswordProtectedKeyEnvelopeError::ParsingError(
170+
return Err(PasswordProtectedKeyEnvelopeError::Parsing(
171171
"Unknown or unsupported KDF algorithm".to_string(),
172172
));
173173
}
174174

175175
let kdf_settings: Argon2RawSettings =
176176
(&recipient.unprotected).try_into().map_err(|_| {
177-
PasswordProtectedKeyEnvelopeError::ParsingError(
177+
PasswordProtectedKeyEnvelopeError::Parsing(
178178
"Invalid or missing KDF parameters".to_string(),
179179
)
180180
})?;
181181
let envelope_key = derive_key(&kdf_settings, password)
182-
.map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)?;
182+
.map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)?;
183183
let nonce: [u8; crate::xchacha20::NONCE_SIZE] = self
184184
.cose_encrypt
185185
.unprotected
186186
.iv
187187
.clone()
188188
.try_into()
189-
.map_err(|_| {
190-
PasswordProtectedKeyEnvelopeError::ParsingError("Invalid IV".to_string())
191-
})?;
189+
.map_err(|_| PasswordProtectedKeyEnvelopeError::Parsing("Invalid IV".to_string()))?;
192190

193191
let key_bytes = self
194192
.cose_encrypt
@@ -201,9 +199,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
201199

202200
SymmetricCryptoKey::try_from(
203201
match ContentFormat::try_from(&self.cose_encrypt.protected.header).map_err(|_| {
204-
PasswordProtectedKeyEnvelopeError::ParsingError(
205-
"Invalid content format".to_string(),
206-
)
202+
PasswordProtectedKeyEnvelopeError::Parsing("Invalid content format".to_string())
207203
})? {
208204
ContentFormat::BitwardenLegacyKey => EncodedSymmetricKey::BitwardenLegacyKey(
209205
BitwardenLegacyKeyBytes::from(key_bytes),
@@ -212,15 +208,13 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
212208
EncodedSymmetricKey::CoseKey(CoseKeyBytes::from(key_bytes))
213209
}
214210
_ => {
215-
return Err(PasswordProtectedKeyEnvelopeError::ParsingError(
211+
return Err(PasswordProtectedKeyEnvelopeError::Parsing(
216212
"Unknown or unsupported content format".to_string(),
217213
));
218214
}
219215
},
220216
)
221-
.map_err(|_| {
222-
PasswordProtectedKeyEnvelopeError::ParsingError("Failed to decode key".to_string())
223-
})
217+
.map_err(|_| PasswordProtectedKeyEnvelopeError::Parsing("Failed to decode key".to_string()))
224218
}
225219

226220
/// Re-seals the key with new KDF parameters (updated settings, salt), and a new password
@@ -268,12 +262,12 @@ impl<Ids: KeyIds> FromStr for PasswordProtectedKeyEnvelope<Ids> {
268262

269263
fn from_str(s: &str) -> Result<Self, Self::Err> {
270264
let data = B64::try_from(s).map_err(|_| {
271-
PasswordProtectedKeyEnvelopeError::ParsingError(
265+
PasswordProtectedKeyEnvelopeError::Parsing(
272266
"Invalid PasswordProtectedKeyEnvelope Base64 encoding".to_string(),
273267
)
274268
})?;
275269
Self::try_from(&data.into_bytes()).map_err(|_| {
276-
PasswordProtectedKeyEnvelopeError::ParsingError(
270+
PasswordProtectedKeyEnvelopeError::Parsing(
277271
"Failed to parse PasswordProtectedKeyEnvelope".to_string(),
278272
)
279273
})
@@ -373,7 +367,7 @@ impl TryInto<Params> for &Argon2RawSettings {
373367
self.parallelism,
374368
Some(ENVELOPE_ARGON2_OUTPUT_KEY_SIZE),
375369
)
376-
.map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)
370+
.map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)
377371
}
378372
}
379373

@@ -388,9 +382,7 @@ impl TryInto<Argon2RawSettings> for &Header {
388382
salt: extract_bytes(self, ARGON2_SALT, "salt")?
389383
.try_into()
390384
.map_err(|_| {
391-
PasswordProtectedKeyEnvelopeError::ParsingError(
392-
"Invalid Argon2 salt".to_string(),
393-
)
385+
PasswordProtectedKeyEnvelopeError::Parsing("Invalid Argon2 salt".to_string())
394386
})?,
395387
})
396388
}
@@ -415,7 +407,7 @@ fn derive_key(
415407
argon2_settings.try_into()?,
416408
)
417409
.hash_password_into(password.as_bytes(), &argon2_settings.salt, &mut hash)
418-
.map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)?;
410+
.map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)?;
419411

420412
Ok(hash)
421413
}
@@ -428,29 +420,29 @@ pub enum PasswordProtectedKeyEnvelopeError {
428420
WrongPassword,
429421
/// The envelope could not be parsed correctly, or the KDF parameters are invalid
430422
#[error("Parsing error {0}")]
431-
ParsingError(String),
423+
Parsing(String),
432424
/// The KDF failed to derive a key, possibly due to invalid parameters or memory allocation
433425
/// issues
434426
#[error("Kdf error")]
435-
KdfError,
427+
Kdf,
436428
/// There is no key for the provided key id in the key store
437429
#[error("Key missing error")]
438-
KeyMissingError,
430+
KeyMissing,
439431
/// The key store could not be written to, for example due to being read-only
440432
#[error("Could not write to key store")]
441-
KeyStoreError,
433+
KeyStore,
442434
}
443435

444436
impl From<CoseExtractError> for PasswordProtectedKeyEnvelopeError {
445437
fn from(err: CoseExtractError) -> Self {
446438
let CoseExtractError::MissingValue(label) = err;
447-
PasswordProtectedKeyEnvelopeError::ParsingError(format!("Missing value for {}", label))
439+
PasswordProtectedKeyEnvelopeError::Parsing(format!("Missing value for {}", label))
448440
}
449441
}
450442

451443
impl From<TryFromIntError> for PasswordProtectedKeyEnvelopeError {
452444
fn from(err: TryFromIntError) -> Self {
453-
PasswordProtectedKeyEnvelopeError::ParsingError(format!("Invalid integer: {}", err))
445+
PasswordProtectedKeyEnvelopeError::Parsing(format!("Invalid integer: {}", err))
454446
}
455447
}
456448

crates/bitwarden-exporters/src/cxf/ssh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn extract_key_type(public_key: &str) -> Result<String, SshKeyExportError> {
7979
let key_type = public_key
8080
.split_whitespace()
8181
.next()
82-
.ok_or(SshKeyExportError::KeyConversionError)?;
82+
.ok_or(SshKeyExportError::KeyConversion)?;
8383

8484
Ok(key_type.to_string())
8585
}

0 commit comments

Comments
 (0)