Skip to content

Commit 92f0f1f

Browse files
committed
Fix remaining error lints and tweak rule
1 parent 31b18f0 commit 92f0f1f

File tree

23 files changed

+97
-75
lines changed

23 files changed

+97
-75
lines changed

crates/bitwarden-core/src/auth/access_token.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{fmt::Debug, str::FromStr};
22

33
use bitwarden_crypto::{derive_shareable_key, SymmetricCryptoKey};
4-
use bitwarden_encoding::{NotB64Encoded, B64};
4+
use bitwarden_encoding::{NotB64EncodedError, B64};
55
use thiserror::Error;
66
use uuid::Uuid;
77
use zeroize::Zeroizing;
@@ -19,7 +19,7 @@ pub enum AccessTokenInvalidError {
1919
InvalidUuid,
2020

2121
#[error("Error decoding base64: {0}")]
22-
InvalidBase64(#[from] NotB64Encoded),
22+
InvalidBase64(#[from] NotB64EncodedError),
2323

2424
#[error("Invalid base64 length: expected {expected}, got {got}")]
2525
InvalidBase64Length { expected: usize, got: usize },

crates/bitwarden-core/src/auth/jwt_token.rs

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

3-
use bitwarden_encoding::{B64Url, NotB64UrlEncoded};
3+
use bitwarden_encoding::{B64Url, NotB64UrlEncodedError};
44
use thiserror::Error;
55

66
/// A Bitwarden secrets manager JWT Token.
@@ -31,7 +31,7 @@ pub enum JwtTokenParseError {
3131
#[error("JWT token parse error: {0}")]
3232
Parse(#[from] serde_json::Error),
3333
#[error("JWT token decode error: {0}")]
34-
Decode(#[from] NotB64UrlEncoded),
34+
Decode(#[from] NotB64UrlEncodedError),
3535

3636
#[error("JWT token has an invalid number of parts")]
3737
InvalidParts,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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},
9+
error::{CryptoError, EncStringParseError, Result, UnsupportedOperationError},
1010
Aes256CbcHmacKey, ContentFormat, KeyDecryptable, KeyEncryptable, KeyEncryptableWithContentType,
1111
SymmetricCryptoKey, Utf8Bytes, XChaCha20Poly1305Key,
1212
};
@@ -294,7 +294,7 @@ impl KeyEncryptableWithContentType<SymmetricCryptoKey, EncString> for &[u8] {
294294
EncString::encrypt_xchacha20_poly1305(self, inner_key, content_format)
295295
}
296296
SymmetricCryptoKey::Aes256CbcKey(_) => Err(CryptoError::OperationNotSupported(
297-
UnsupportedOperation::EncryptionNotImplementedForKey,
297+
UnsupportedOperationError::EncryptionNotImplementedForKey,
298298
)),
299299
}
300300
}

crates/bitwarden-crypto/src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fmt::Debug;
22

3-
use bitwarden_encoding::NotB64Encoded;
3+
use bitwarden_encoding::NotB64EncodedError;
44
use bitwarden_error::bitwarden_error;
55
use thiserror::Error;
66
use uuid::Uuid;
@@ -45,13 +45,13 @@ pub enum CryptoError {
4545
Fingerprint(#[from] FingerprintError),
4646

4747
#[error("Argon2 error, {0}")]
48-
ArgonError(#[from] argon2::Error),
48+
Argon(#[from] argon2::Error),
4949

5050
#[error("Number is zero")]
5151
ZeroNumber,
5252

5353
#[error("Unsupported operation, {0}")]
54-
OperationNotSupported(UnsupportedOperation),
54+
OperationNotSupported(UnsupportedOperationError),
5555

5656
#[error("Key algorithm does not match encrypted data type")]
5757
WrongKeyType,
@@ -73,7 +73,7 @@ pub enum CryptoError {
7373
}
7474

7575
#[derive(Debug, Error)]
76-
pub enum UnsupportedOperation {
76+
pub enum UnsupportedOperationError {
7777
#[error("Encryption is not implemented for key")]
7878
EncryptionNotImplementedForKey,
7979
}
@@ -87,7 +87,7 @@ pub enum EncStringParseError {
8787
#[error("Invalid asymmetric type, got type {enc_type} with {parts} parts")]
8888
InvalidTypeAsymm { enc_type: String, parts: usize },
8989
#[error("Error decoding base64: {0}")]
90-
InvalidBase64(#[from] NotB64Encoded),
90+
InvalidBase64(#[from] NotB64EncodedError),
9191
#[error("Invalid length: expected {expected}, got {got}")]
9292
InvalidLength { expected: usize, got: usize },
9393
#[error("Invalid encoding {0}")]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub(super) fn decrypt_user_key(
155155
}
156156
EncString::Cose_Encrypt0_B64 { .. } => {
157157
return Err(CryptoError::OperationNotSupported(
158-
crate::error::UnsupportedOperation::EncryptionNotImplementedForKey,
158+
crate::error::UnsupportedOperationError::EncryptionNotImplementedForKey,
159159
));
160160
}
161161
};

crates/bitwarden-crypto/src/rsa.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rsa::{
66
use sha1::Sha1;
77

88
use crate::{
9-
error::{Result, RsaError, UnsupportedOperation},
9+
error::{Result, RsaError, UnsupportedOperationError},
1010
CryptoError, EncString, SymmetricCryptoKey,
1111
};
1212

@@ -41,10 +41,10 @@ pub(crate) fn make_key_pair(key: &SymmetricCryptoKey) -> Result<RsaKeyPair> {
4141
EncString::encrypt_aes256_hmac(pkcs.as_bytes(), key)
4242
}
4343
SymmetricCryptoKey::XChaCha20Poly1305Key(_) => Err(CryptoError::OperationNotSupported(
44-
UnsupportedOperation::EncryptionNotImplementedForKey,
44+
UnsupportedOperationError::EncryptionNotImplementedForKey,
4545
)),
4646
SymmetricCryptoKey::Aes256CbcKey(_) => Err(CryptoError::OperationNotSupported(
47-
UnsupportedOperation::EncryptionNotImplementedForKey,
47+
UnsupportedOperationError::EncryptionNotImplementedForKey,
4848
)),
4949
}?;
5050

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use zeroize::Zeroizing;
88

99
use super::KeyStoreInner;
1010
use crate::{
11-
derive_shareable_key, error::UnsupportedOperation, signing, store::backend::StoreBackend,
11+
derive_shareable_key, error::UnsupportedOperationError, signing, store::backend::StoreBackend,
1212
AsymmetricCryptoKey, BitwardenLegacyKeyBytes, ContentFormat, CryptoError, EncString, KeyId,
1313
KeyIds, PublicKeyEncryptionAlgorithm, Result, RotatedUserKeys, Signature, SignatureAlgorithm,
1414
SignedObject, SignedPublicKey, SignedPublicKeyMessage, SigningKey, SymmetricCryptoKey,
@@ -236,7 +236,7 @@ impl<Ids: KeyIds> KeyStoreContext<'_, Ids> {
236236
)
237237
}
238238
_ => Err(CryptoError::OperationNotSupported(
239-
UnsupportedOperation::EncryptionNotImplementedForKey,
239+
UnsupportedOperationError::EncryptionNotImplementedForKey,
240240
)),
241241
}
242242
}
@@ -503,7 +503,7 @@ impl<Ids: KeyIds> KeyStoreContext<'_, Ids> {
503503
let key = self.get_symmetric_key(key)?;
504504
match key {
505505
SymmetricCryptoKey::Aes256CbcKey(_) => Err(CryptoError::OperationNotSupported(
506-
UnsupportedOperation::EncryptionNotImplementedForKey,
506+
UnsupportedOperationError::EncryptionNotImplementedForKey,
507507
)),
508508
SymmetricCryptoKey::Aes256CbcHmacKey(key) => EncString::encrypt_aes256_hmac(data, key),
509509
SymmetricCryptoKey::XChaCha20Poly1305Key(key) => {

crates/bitwarden-encoding/src/b64.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl std::fmt::Display for B64 {
8686
/// An error returned when a string is not base64 decodable.
8787
#[derive(Debug, Error)]
8888
#[error("Data isn't base64 encoded")]
89-
pub struct NotB64Encoded;
89+
pub struct NotB64EncodedError;
9090

9191
const BASE64_PERMISSIVE: data_encoding::Encoding = data_encoding_macro::new_encoding! {
9292
symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
@@ -96,27 +96,27 @@ const BASE64_PERMISSIVE: data_encoding::Encoding = data_encoding_macro::new_enco
9696
const BASE64_PADDING: &str = "=";
9797

9898
impl TryFrom<String> for B64 {
99-
type Error = NotB64Encoded;
99+
type Error = NotB64EncodedError;
100100

101101
fn try_from(value: String) -> Result<Self, Self::Error> {
102102
Self::try_from(value.as_str())
103103
}
104104
}
105105

106106
impl TryFrom<&str> for B64 {
107-
type Error = NotB64Encoded;
107+
type Error = NotB64EncodedError;
108108

109109
fn try_from(value: &str) -> Result<Self, Self::Error> {
110110
let sane_string = value.trim_end_matches(BASE64_PADDING);
111111
BASE64_PERMISSIVE
112112
.decode(sane_string.as_bytes())
113113
.map(Self)
114-
.map_err(|_| NotB64Encoded)
114+
.map_err(|_| NotB64EncodedError)
115115
}
116116
}
117117

118118
impl FromStr for B64 {
119-
type Err = NotB64Encoded;
119+
type Err = NotB64EncodedError;
120120

121121
fn from_str(s: &str) -> Result<Self, Self::Err> {
122122
Self::try_from(s)
@@ -224,7 +224,7 @@ mod tests {
224224

225225
#[test]
226226
fn test_not_b64_encoded_error_display() {
227-
let error = NotB64Encoded;
227+
let error = NotB64EncodedError;
228228
assert_eq!(error.to_string(), "Data isn't base64 encoded");
229229
}
230230

crates/bitwarden-encoding/src/b64url.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl std::fmt::Display for B64Url {
6161
/// An error returned when a string is not base64 decodable.
6262
#[derive(Debug, Error)]
6363
#[error("Data isn't base64url encoded")]
64-
pub struct NotB64UrlEncoded;
64+
pub struct NotB64UrlEncodedError;
6565

6666
const BASE64URL_PERMISSIVE: data_encoding::Encoding = data_encoding_macro::new_encoding! {
6767
symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
@@ -71,27 +71,27 @@ const BASE64URL_PERMISSIVE: data_encoding::Encoding = data_encoding_macro::new_e
7171
const BASE64URL_PADDING: &str = "=";
7272

7373
impl TryFrom<String> for B64Url {
74-
type Error = NotB64UrlEncoded;
74+
type Error = NotB64UrlEncodedError;
7575

7676
fn try_from(value: String) -> Result<Self, Self::Error> {
7777
Self::try_from(value.as_str())
7878
}
7979
}
8080

8181
impl TryFrom<&str> for B64Url {
82-
type Error = NotB64UrlEncoded;
82+
type Error = NotB64UrlEncodedError;
8383

8484
fn try_from(value: &str) -> Result<Self, Self::Error> {
8585
let sane_string = value.trim_end_matches(BASE64URL_PADDING);
8686
BASE64URL_PERMISSIVE
8787
.decode(sane_string.as_bytes())
8888
.map(Self)
89-
.map_err(|_| NotB64UrlEncoded)
89+
.map_err(|_| NotB64UrlEncodedError)
9090
}
9191
}
9292

9393
impl FromStr for B64Url {
94-
type Err = NotB64UrlEncoded;
94+
type Err = NotB64UrlEncodedError;
9595

9696
fn from_str(s: &str) -> Result<Self, Self::Err> {
9797
Self::try_from(s)
@@ -198,7 +198,7 @@ mod tests {
198198

199199
#[test]
200200
fn test_not_b64url_encoded_error_display() {
201-
let error = NotB64UrlEncoded;
201+
let error = NotB64UrlEncodedError;
202202
assert_eq!(error.to_string(), "Data isn't base64url encoded");
203203
}
204204

crates/bitwarden-encoding/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ mod b64;
44
mod b64url;
55
mod serde;
66

7-
pub use b64::{NotB64Encoded, B64};
8-
pub use b64url::{B64Url, NotB64UrlEncoded};
7+
pub use b64::{NotB64EncodedError, B64};
8+
pub use b64url::{B64Url, NotB64UrlEncodedError};
99
pub use serde::FromStrVisitor;
1010

1111
#[cfg(feature = "uniffi")]

0 commit comments

Comments
 (0)