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

Address clippy lints #543

Merged
merged 1 commit into from
Aug 27, 2023
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.
Jump to
Jump to file
Failed to load files.
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 @@ -65,7 +65,7 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy
- run: cargo clippy --target x86_64-unknown-linux-gnu
- run: cargo clippy --target x86_64-unknown-linux-gnu --all-features

rustfmt:
name: Check formatting
Expand Down
6 changes: 1 addition & 5 deletions curve25519-dalek-derive/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ impl<T: Copy + core::ops::Sub> StructWithGenericsNoWhere<T> {
#[unsafe_target_feature("sse2")]
#[allow(dead_code)]
impl<'a> From<&'a Struct> for () {
fn from(_: &'a Struct) -> Self {
()
}
fn from(_: &'a Struct) -> Self {}
}

#[unsafe_target_feature("sse2")]
Expand All @@ -97,8 +95,6 @@ mod inner {

#[unsafe_target_feature_specialize("sse2", "avx2", conditional("avx512ifma", disabled))]
mod inner_spec {
use std;

#[for_target_feature("sse2")]
const CONST: u32 = 1;

Expand Down
6 changes: 3 additions & 3 deletions curve25519-dalek/benches/dalek_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ mod multiscalar_benches {
let static_size = total_size;

let static_points = construct_points(static_size);
let precomp = VartimeEdwardsPrecomputation::new(&static_points);
let precomp = VartimeEdwardsPrecomputation::new(static_points);
// Rerandomize the scalars for every call to prevent
// false timings from better caching (e.g., the CPU
// cache lifts exactly the right table entries for the
// benchmark into the highest cache levels).
b.iter_batched(
|| construct_scalars(static_size),
|scalars| precomp.vartime_multiscalar_mul(&scalars),
|scalars| precomp.vartime_multiscalar_mul(scalars),
BatchSize::SmallInput,
);
},
Expand Down Expand Up @@ -182,7 +182,7 @@ mod multiscalar_benches {

let static_points = construct_points(static_size);
let dynamic_points = construct_points(dynamic_size);
let precomp = VartimeEdwardsPrecomputation::new(&static_points);
let precomp = VartimeEdwardsPrecomputation::new(static_points);
// Rerandomize the scalars for every call to prevent
// false timings from better caching (e.g., the CPU
// cache lifts exactly the right table entries for the
Expand Down
2 changes: 2 additions & 0 deletions curve25519-dalek/src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ impl<'de> Deserialize<'de> for EdwardsPoint {
A: serde::de::SeqAccess<'de>,
{
let mut bytes = [0u8; 32];
#[allow(clippy::needless_range_loop)]
for i in 0..32 {
bytes[i] = seq
.next_element()?
Expand Down Expand Up @@ -311,6 +312,7 @@ impl<'de> Deserialize<'de> for CompressedEdwardsY {
A: serde::de::SeqAccess<'de>,
{
let mut bytes = [0u8; 32];
#[allow(clippy::needless_range_loop)]
for i in 0..32 {
bytes[i] = seq
.next_element()?
Expand Down
6 changes: 4 additions & 2 deletions curve25519-dalek/src/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ impl<'de> Deserialize<'de> for RistrettoPoint {
A: serde::de::SeqAccess<'de>,
{
let mut bytes = [0u8; 32];
#[allow(clippy::needless_range_loop)]
for i in 0..32 {
bytes[i] = seq
.next_element()?
Expand Down Expand Up @@ -423,6 +424,7 @@ impl<'de> Deserialize<'de> for CompressedRistretto {
A: serde::de::SeqAccess<'de>,
{
let mut bytes = [0u8; 32];
#[allow(clippy::needless_range_loop)]
for i in 0..32 {
bytes[i] = seq
.next_element()?
Expand Down Expand Up @@ -1270,7 +1272,7 @@ mod test {
let bp_compressed_ristretto = constants::RISTRETTO_BASEPOINT_POINT.compress();
let bp_recaf = bp_compressed_ristretto.decompress().unwrap().0;
// Check that bp_recaf differs from bp by a point of order 4
let diff = &constants::RISTRETTO_BASEPOINT_POINT.0 - bp_recaf;
let diff = constants::RISTRETTO_BASEPOINT_POINT.0 - bp_recaf;
let diff4 = diff.mul_by_pow_2(2);
assert_eq!(diff4.compress(), CompressedEdwardsY::identity());
}
Expand Down Expand Up @@ -1681,7 +1683,7 @@ mod test {
];
// Check that onewaymap(input) == output for all the above vectors
for (input, output) in test_vectors {
let Q = RistrettoPoint::from_uniform_bytes(&input);
let Q = RistrettoPoint::from_uniform_bytes(input);
assert_eq!(&Q.compress(), output);
}
}
Expand Down
11 changes: 6 additions & 5 deletions curve25519-dalek/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,14 @@ impl<'de> Deserialize<'de> for Scalar {
A: serde::de::SeqAccess<'de>,
{
let mut bytes = [0u8; 32];
#[allow(clippy::needless_range_loop)]
for i in 0..32 {
bytes[i] = seq
.next_element()?
.ok_or_else(|| serde::de::Error::invalid_length(i, &"expected 32 bytes"))?;
}
Option::from(Scalar::from_canonical_bytes(bytes))
.ok_or_else(|| serde::de::Error::custom(&"scalar was not canonically encoded"))
.ok_or_else(|| serde::de::Error::custom("scalar was not canonically encoded"))
}
}

Expand Down Expand Up @@ -1476,13 +1477,13 @@ pub(crate) mod test {
#[cfg(feature = "alloc")]
fn impl_product() {
// Test that product works for non-empty iterators
let X_Y_vector = vec![X, Y];
let X_Y_vector = [X, Y];
let should_be_X_times_Y: Scalar = X_Y_vector.iter().product();
assert_eq!(should_be_X_times_Y, X_TIMES_Y);

// Test that product works for the empty iterator
let one = Scalar::ONE;
let empty_vector = vec![];
let empty_vector = [];
let should_be_one: Scalar = empty_vector.iter().product();
assert_eq!(should_be_one, one);

Expand All @@ -1507,13 +1508,13 @@ pub(crate) mod test {
fn impl_sum() {
// Test that sum works for non-empty iterators
let two = Scalar::from(2u64);
let one_vector = vec![Scalar::ONE, Scalar::ONE];
let one_vector = [Scalar::ONE, Scalar::ONE];
let should_be_two: Scalar = one_vector.iter().sum();
assert_eq!(should_be_two, two);

// Test that sum works for the empty iterator
let zero = Scalar::ZERO;
let empty_vector = vec![];
let empty_vector = [];
let should_be_zero: Scalar = empty_vector.iter().sum();
assert_eq!(should_be_zero, zero);

Expand Down
3 changes: 1 addition & 2 deletions ed25519-dalek/benches/ed25519_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ mod ed25519_benches {
.collect();
let msg: &[u8] = b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
let messages: Vec<&[u8]> = (0..size).map(|_| msg).collect();
let signatures: Vec<Signature> =
keypairs.iter().map(|key| key.sign(&msg)).collect();
let signatures: Vec<Signature> = keypairs.iter().map(|key| key.sign(msg)).collect();
let verifying_keys: Vec<_> =
keypairs.iter().map(|key| key.verifying_key()).collect();

Expand Down
2 changes: 1 addition & 1 deletion ed25519-dalek/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub fn verify_batch(
let mut h: Sha512 = Sha512::default();
h.update(signatures[i].r_bytes());
h.update(verifying_keys[i].as_bytes());
h.update(&messages[i]);
h.update(messages[i]);
*h.finalize().as_ref()
})
.collect();
Expand Down
2 changes: 2 additions & 0 deletions ed25519-dalek/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ impl<'k, 'v, K> Context<'k, 'v, K> {

#[cfg(all(test, feature = "digest"))]
mod test {
#![allow(clippy::unwrap_used)]

use crate::{Signature, SigningKey, VerifyingKey};
use curve25519_dalek::digest::Digest;
use ed25519::signature::{DigestSigner, DigestVerifier};
Expand Down
14 changes: 8 additions & 6 deletions ed25519-dalek/src/hazmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ where
/// [rfc8032]: https://tools.ietf.org/html/rfc8032#section-5.1
#[cfg(feature = "digest")]
#[allow(non_snake_case)]
pub fn raw_sign_prehashed<'a, CtxDigest, MsgDigest>(
pub fn raw_sign_prehashed<CtxDigest, MsgDigest>(
esk: &ExpandedSecretKey,
prehashed_message: MsgDigest,
verifying_key: &VerifyingKey,
context: Option<&'a [u8]>,
context: Option<&[u8]>,
) -> Result<Signature, SignatureError>
where
MsgDigest: Digest<OutputSize = U64>,
Expand Down Expand Up @@ -204,6 +204,8 @@ where

#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]

use super::*;

use rand::{rngs::OsRng, CryptoRng, RngCore};
Expand All @@ -226,8 +228,8 @@ mod test {
#[test]
fn sign_verify_nonspec() {
// Generate the keypair
let mut rng = OsRng;
let esk = ExpandedSecretKey::random(&mut rng);
let rng = OsRng;
let esk = ExpandedSecretKey::random(rng);
let vk = VerifyingKey::from(&esk);

let msg = b"Then one day, a piano fell on my head";
Expand All @@ -245,8 +247,8 @@ mod test {
use curve25519_dalek::digest::Digest;

// Generate the keypair
let mut rng = OsRng;
let esk = ExpandedSecretKey::random(&mut rng);
let rng = OsRng;
let esk = ExpandedSecretKey::random(rng);
let vk = VerifyingKey::from(&esk);

// Hash the message
Expand Down
7 changes: 4 additions & 3 deletions ed25519-dalek/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,14 +700,15 @@ impl<'d> Deserialize<'d> for SigningKey {
self,
bytes: &'de [u8],
) -> Result<Self::Value, E> {
SigningKey::try_from(bytes.as_ref()).map_err(E::custom)
SigningKey::try_from(bytes).map_err(E::custom)
}

fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: serde::de::SeqAccess<'de>,
{
let mut bytes = [0u8; 32];
#[allow(clippy::needless_range_loop)]
for i in 0..32 {
bytes[i] = seq
.next_element()?
Expand Down Expand Up @@ -797,11 +798,11 @@ impl ExpandedSecretKey {
#[cfg(feature = "digest")]
#[allow(non_snake_case)]
#[inline(always)]
pub(crate) fn raw_sign_prehashed<'a, CtxDigest, MsgDigest>(
pub(crate) fn raw_sign_prehashed<CtxDigest, MsgDigest>(
&self,
prehashed_message: MsgDigest,
verifying_key: &VerifyingKey,
context: Option<&'a [u8]>,
context: Option<&[u8]>,
) -> Result<Signature, SignatureError>
where
CtxDigest: Digest<OutputSize = U64>,
Expand Down
3 changes: 2 additions & 1 deletion ed25519-dalek/src/verifying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ impl<'d> Deserialize<'d> for VerifyingKey {
self,
bytes: &'de [u8],
) -> Result<Self::Value, E> {
VerifyingKey::try_from(bytes.as_ref()).map_err(E::custom)
VerifyingKey::try_from(bytes).map_err(E::custom)
}

fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
Expand All @@ -649,6 +649,7 @@ impl<'d> Deserialize<'d> for VerifyingKey {
{
let mut bytes = [0u8; 32];

#[allow(clippy::needless_range_loop)]
for i in 0..32 {
bytes[i] = seq
.next_element()?
Expand Down