From 42082254f6dcf5ea915a03bad45e7a027f08fd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Mon, 7 Aug 2023 17:24:07 +0300 Subject: [PATCH] Update Clippy and fix lints --- .github/workflows/workspace.yml | 2 +- argon2/src/algorithm.rs | 9 ++------- argon2/src/lib.rs | 1 + argon2/tests/kat.rs | 1 + balloon-hash/src/algorithm.rs | 9 ++------- password-auth/src/lib.rs | 4 ++-- pbkdf2/benches/lib.rs | 6 +++--- pbkdf2/src/simple.rs | 2 +- 8 files changed, 13 insertions(+), 21 deletions(-) diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index def9c6dc..8fd9b5a1 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -17,7 +17,7 @@ jobs: - uses: RustCrypto/actions/cargo-cache@master - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.67.0 + toolchain: 1.71.0 components: clippy - run: cargo clippy --all -- -D warnings diff --git a/argon2/src/algorithm.rs b/argon2/src/algorithm.rs index 4efe86b5..e7260d6e 100644 --- a/argon2/src/algorithm.rs +++ b/argon2/src/algorithm.rs @@ -25,7 +25,7 @@ pub const ARGON2I_IDENT: Ident<'_> = Ident::new_unwrap("argon2i"); pub const ARGON2ID_IDENT: Ident<'_> = Ident::new_unwrap("argon2id"); /// Argon2 primitive type: variants of the algorithm. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Default, Ord)] pub enum Algorithm { /// Optimizes against GPU cracking attacks but vulnerable to side-channels. /// @@ -47,15 +47,10 @@ pub enum Algorithm { /// TMTO/GPU cracking resistance as Argon2d, nor as good of side-channel /// resistance as Argon2i, but overall provides the most well-rounded /// approach to both classes of attacks. + #[default] Argon2id = 2, } -impl Default for Algorithm { - fn default() -> Algorithm { - Algorithm::Argon2id - } -} - impl Algorithm { /// Parse an [`Algorithm`] from the provided string. pub fn new(id: impl AsRef) -> Result { diff --git a/argon2/src/lib.rs b/argon2/src/lib.rs index 458265d5..6a6f04f0 100644 --- a/argon2/src/lib.rs +++ b/argon2/src/lib.rs @@ -627,6 +627,7 @@ impl<'key> From<&Params> for Argon2<'key> { } #[cfg(all(test, feature = "alloc", feature = "password-hash"))] +#[allow(clippy::unwrap_used)] mod tests { use crate::{Algorithm, Argon2, Params, PasswordHasher, Salt, Version}; diff --git a/argon2/tests/kat.rs b/argon2/tests/kat.rs index d26b3cb9..cfabcfe1 100644 --- a/argon2/tests/kat.rs +++ b/argon2/tests/kat.rs @@ -333,6 +333,7 @@ fn output_bad_length() { // ======================================= // Taken from https://github.com/P-H-C/phc-winner-argon2/blob/master/src/test.c +#[allow(clippy::too_many_arguments)] fn hashtest( algorithm: Algorithm, version: Version, diff --git a/balloon-hash/src/algorithm.rs b/balloon-hash/src/algorithm.rs index 9f30ab25..96780ee3 100644 --- a/balloon-hash/src/algorithm.rs +++ b/balloon-hash/src/algorithm.rs @@ -10,7 +10,7 @@ use core::{ use password_hash::Ident; /// Balloon primitive type: variants of the algorithm. -#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Default)] pub enum Algorithm { /// Standard Balloon hashing algorithm. Balloon, @@ -19,15 +19,10 @@ pub enum Algorithm { /// /// Supports parallelism by computing M instances of the /// single-core Balloon function and XORing all the outputs. + #[default] BalloonM, } -impl Default for Algorithm { - fn default() -> Algorithm { - Algorithm::BalloonM - } -} - impl Algorithm { /// Balloon algorithm identifier #[cfg(feature = "password-hash")] diff --git a/password-auth/src/lib.rs b/password-auth/src/lib.rs index c4af006e..967f2e02 100644 --- a/password-auth/src/lib.rs +++ b/password-auth/src/lib.rs @@ -7,7 +7,7 @@ )] #![warn( clippy::checked_conversions, - clippy::integer_arithmetic, + clippy::arithmetic_side_effects, clippy::panic, clippy::panic_in_result_fn, clippy::unwrap_used, @@ -142,7 +142,7 @@ mod tests { let hash = generate_hash(EXAMPLE_PASSWORD); assert!(verify_password(EXAMPLE_PASSWORD, &hash).is_ok()); assert!(verify_password("bogus", &hash).is_err()); - assert!(!is_hash_obsolete(&hash).unwrap()); + assert!(!is_hash_obsolete(&hash).expect("hash can be parsed")); } #[cfg(feature = "argon2")] diff --git a/pbkdf2/benches/lib.rs b/pbkdf2/benches/lib.rs index 13f3a2d5..7b67c98e 100644 --- a/pbkdf2/benches/lib.rs +++ b/pbkdf2/benches/lib.rs @@ -13,7 +13,7 @@ pub fn pbkdf2_hmac_sha1_16384_20(bh: &mut Bencher) { let salt = b"salty salt"; let mut buf = [0u8; 20]; bh.iter(|| { - pbkdf2::>(password, salt, 16_384, &mut buf); + pbkdf2::>(password, salt, 16_384, &mut buf).unwrap(); test::black_box(&buf); }); } @@ -24,7 +24,7 @@ pub fn pbkdf2_hmac_sha256_16384_20(bh: &mut Bencher) { let salt = b"salty salt"; let mut buf = [0u8; 20]; bh.iter(|| { - pbkdf2::>(password, salt, 16_384, &mut buf); + pbkdf2::>(password, salt, 16_384, &mut buf).unwrap(); test::black_box(&buf); }); } @@ -35,7 +35,7 @@ pub fn pbkdf2_hmac_sha512_16384_20(bh: &mut Bencher) { let salt = b"salty salt"; let mut buf = [0u8; 20]; bh.iter(|| { - pbkdf2::>(password, salt, 16_384, &mut buf); + pbkdf2::>(password, salt, 16_384, &mut buf).unwrap(); test::black_box(&buf); }); } diff --git a/pbkdf2/src/simple.rs b/pbkdf2/src/simple.rs index 957f00b1..a071a827 100644 --- a/pbkdf2/src/simple.rs +++ b/pbkdf2/src/simple.rs @@ -236,7 +236,7 @@ impl<'a> TryFrom<&'a PasswordHash<'a>> for Params { } } -impl<'a> TryFrom for ParamsString { +impl TryFrom for ParamsString { type Error = Error; fn try_from(input: Params) -> Result {