Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Clippy lints #1598

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.75.0
toolchain: 1.79.0
components: clippy
- run: cargo clippy --all --all-features --tests -- -D warnings

Expand Down
2 changes: 1 addition & 1 deletion aead/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ where
type NonceOverhead = U5;
type Counter = u32;
const COUNTER_INCR: u32 = 1;
const COUNTER_MAX: u32 = core::u32::MAX;
const COUNTER_MAX: u32 = u32::MAX;

fn encrypt_in_place(
&self,
Expand Down
1 change: 1 addition & 0 deletions elliptic-curve/src/jwk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl FromStr for JwkEcKey {
}
}

#[allow(clippy::to_string_trait_impl)]
impl ToString for JwkEcKey {
fn to_string(&self) -> String {
serde_json::to_string(self).expect("JWK encoding error")
Expand Down
1 change: 1 addition & 0 deletions elliptic-curve/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ where
}

#[cfg(feature = "pem")]
#[allow(clippy::to_string_trait_impl)]
Copy link
Member Author

@newpavlov newpavlov Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tarcieri
Maybe it's better remove ToString implementations? The trait docs state the following:

This trait is automatically implemented for any type which implements the Display trait. As such, ToString shouldn’t be implemented directly: Display should be implemented instead, and you get the ToString implementation for free.

But implementing Display on top of to_public_key_pem would look really wrong.

Copy link
Member

@tarcieri tarcieri Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is currently no way to use core::fmt::Formatter to serialize PEM, so ToString is the only option here.

You could potentially open an issue to add such support, but pem-rfc7468 is designed around constant-time operation (not really important here due to it being a public key).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, why have this implementation in the first place? Users should prefer using the to_public_key_pem method since it explicitly states how serialization is performed. IIUC ToString intended for user-facing serialization and PEM serialization arguably barely fits here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave the implementation as is, but I think it may be worth to remove it in a separate PR.

impl<C> ToString for PublicKey<C>
where
C: AssociatedOid + CurveArithmetic,
Expand Down
6 changes: 4 additions & 2 deletions elliptic-curve/src/scalar/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ where
// While this method isn't constant-time, the attacker shouldn't learn
// anything about unrelated outputs so long as `rng` is a secure `CryptoRng`.
loop {
// TODO: remove after `Field::random` switches to `&mut impl RngCore`
#[allow(clippy::needless_borrows_for_generic_args)]
if let Some(result) = Self::new(Field::random(&mut rng)).into() {
break result;
}
Expand Down Expand Up @@ -270,11 +272,11 @@ where
Scalar<C>: Reduce<I, Bytes = Self::Bytes> + ReduceNonZero<I>,
{
fn reduce_nonzero(n: I) -> Self {
Self::reduce(n)
<Self as Reduce<I>>::reduce(n)
}

fn reduce_nonzero_bytes(bytes: &Self::Bytes) -> Self {
Self::reduce_bytes(bytes)
<Self as Reduce<I>>::reduce_bytes(bytes)
}
}

Expand Down
3 changes: 3 additions & 0 deletions password-hash/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ pub enum Encoding {
/// - sha256_crypt,
/// - sha512_crypt,
/// - md5_crypt
///
/// ```text
/// [.-9] [A-Z] [a-z]
/// 0x2e-0x39, 0x41-0x5a, 0x61-0x7a
/// ```
ShaCrypt,
}

Expand Down
Loading