Skip to content

Commit e30f1ea

Browse files
authored
Fix remaining error lints and tweak rule (#458)
- Enable dylint in CI and pre-commit. - Fix remaining violations. - Tweak linter to avoid catching `Error` variants in non error enums.
1 parent 1d43736 commit e30f1ea

File tree

26 files changed

+110
-76
lines changed

26 files changed

+110
-76
lines changed

.github/workflows/lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ jobs:
9292
- name: Cargo udeps
9393
run: cargo +"${{ steps.nightly-toolchain.outputs.RUST_NIGHTLY_TOOLCHAIN }}" udeps --workspace --all-features
9494

95+
- name: Install cargo-dylint
96+
run: cargo install cargo-dylint dylint-link --version 4.1.0 --locked
97+
98+
- name: Cargo dylint
99+
run: cargo dylint --all -- --all-features --all-targets
100+
95101
- name: Set up Node
96102
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
97103
with:

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ versions. Here are the cli tools we use:
127127
- Nightly [cargo fmt](https://github.com/rust-lang/rustfmt) and
128128
[cargo udeps](https://github.com/est31/cargo-udeps)
129129
- [rust clippy](https://github.com/rust-lang/rust-clippy)
130+
- [cargo dylint](https://github.com/trailofbits/dylint)
130131
- [cargo sort](https://github.com/DevinR528/cargo-sort)
131132
- [prettier](https://github.com/prettier/prettier)
132133

@@ -140,6 +141,7 @@ export RUSTFLAGS="-D warnings"
140141
cargo +nightly fmt --check
141142
cargo +nightly udeps --workspace --all-features
142143
cargo clippy --all-features --all-targets
144+
cargo dylint --all -- --all-features --all-targets
143145
cargo sort --workspace --check
144146
npm run lint
145147
```

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

0 commit comments

Comments
 (0)