From e1a8ea9dd74841e573569e28edfb9668f36b3e2a Mon Sep 17 00:00:00 2001 From: "dobby-yivi-agent[bot]" <275734547+dobby-yivi-agent[bot]@users.noreply.github.com> Date: Tue, 5 May 2026 15:04:37 +0000 Subject: [PATCH] chore: clean up clippy warnings (#16) Address all 17 clippy warnings reported on stable so the CI lint job can flip to -D warnings. Changes: - needless_borrow: drop & in conditional_select calls. - let_and_return: drop temporary in waters/waters_naccache decrypt. - non_canonical_clone_impl: replace manual Clone impls on Copy types with `*self` (Parameters in waters & kiltz_vahlis_one, Identity in waters). - needless_range_loop: switch index-based loops in to_bytes / from_bytes to enumerate-over-iter_mut(). - wrong_self_convention: change to_bytes(&self) to to_bytes(self) on the three Copy parameter types (waters::Parameters, waters_naccache::Parameters, kiltz_vahlis_one::HashParameters). These are pub but the types themselves are crate-private (only reached via PublicKey::to_bytes), so this is source-compatible for downstream callers. No behavior changes. cargo clippy --all-features --all-targets exits clean. cargo test --release --all-features: 17/17 pass. cargo check --no-default-features (wasm32) builds. Closes #16 --- src/ibe/waters.rs | 37 +++++++++++++------------------------ src/ibe/waters_naccache.rs | 25 +++++++++++-------------- src/kem/kiltz_vahlis_one.rs | 18 +++++++----------- 3 files changed, 31 insertions(+), 49 deletions(-) diff --git a/src/ibe/waters.rs b/src/ibe/waters.rs index 83cf1c8..bcad2fb 100644 --- a/src/ibe/waters.rs +++ b/src/ibe/waters.rs @@ -170,22 +170,19 @@ impl IBE for Waters { /// Decrypt ciphertext to a message using a user secret key. fn decrypt(usk: &UserSecretKey, c: &CipherText) -> Msg { - let m = c.c1 - + multi_miller_loop(&[ - (&c.c3, &G2Prepared::from(usk.d2)), - (&-usk.d1, &G2Prepared::from(c.c2)), - ]) - .final_exponentiation(); - - m + c.c1 + multi_miller_loop(&[ + (&c.c3, &G2Prepared::from(usk.d2)), + (&-usk.d1, &G2Prepared::from(c.c2)), + ]) + .final_exponentiation() } } impl Parameters { - pub fn to_bytes(&self) -> [u8; PARAMETERSIZE] { + pub fn to_bytes(self) -> [u8; PARAMETERSIZE] { let mut res = [0u8; PARAMETERSIZE]; - for i in 0..CHUNKS { - *array_mut_ref![&mut res, i * 48, 48] = self.0[i].to_compressed(); + for (i, p) in self.0.iter().enumerate() { + *array_mut_ref![&mut res, i * 48, 48] = p.to_compressed(); } res } @@ -193,10 +190,10 @@ impl Parameters { pub fn from_bytes(bytes: &[u8; PARAMETERSIZE]) -> CtOption { let mut res = [G1Affine::default(); CHUNKS]; let mut is_some = Choice::from(1u8); - for i in 0..CHUNKS { + for (i, slot) in res.iter_mut().enumerate() { is_some &= G1Affine::from_compressed(array_ref![bytes, i * 48, 48]) .map(|s| { - res[i] = s; + *slot = s; }) .is_some(); } @@ -208,7 +205,7 @@ impl ConditionallySelectable for Parameters { fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self { let mut res = [G1Affine::default(); CHUNKS]; for (i, (ai, bi)) in a.0.iter().zip(b.0.iter()).enumerate() { - res[i] = G1Affine::conditional_select(&ai, &bi, choice); + res[i] = G1Affine::conditional_select(ai, bi, choice); } Parameters(res) } @@ -216,11 +213,7 @@ impl ConditionallySelectable for Parameters { impl Clone for Parameters { fn clone(&self) -> Self { - let mut res = [G1Affine::default(); CHUNKS]; - for (src, dst) in self.0.iter().zip(res.as_mut().iter_mut()) { - *dst = *src; - } - Parameters(res) + *self } } @@ -254,11 +247,7 @@ impl Derive for Identity { impl Clone for Identity { fn clone(&self) -> Self { - let mut res = [u8::default(); HASH_BYTE_LEN]; - for (src, dst) in self.0.iter().zip(res.as_mut().iter_mut()) { - *dst = *src; - } - Identity(res) + *self } } diff --git a/src/ibe/waters_naccache.rs b/src/ibe/waters_naccache.rs index 4bd6fa6..58dad1b 100644 --- a/src/ibe/waters_naccache.rs +++ b/src/ibe/waters_naccache.rs @@ -173,14 +173,11 @@ impl IBE for WatersNaccache { /// Decrypt ciphertext to a message using a user secret key. fn decrypt(usk: &UserSecretKey, c: &CipherText) -> Msg { - let m = c.c1 - + multi_miller_loop(&[ - (&usk.d2, &G2Prepared::from(c.c3)), - (&-c.c2, &G2Prepared::from(usk.d1)), - ]) - .final_exponentiation(); - - m + c.c1 + multi_miller_loop(&[ + (&usk.d2, &G2Prepared::from(c.c3)), + (&-c.c2, &G2Prepared::from(usk.d1)), + ]) + .final_exponentiation() } } @@ -188,17 +185,17 @@ impl ConditionallySelectable for Parameters { fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self { let mut res = [G2Affine::default(); CHUNKS]; for (i, (ai, bi)) in a.0.iter().zip(b.0.iter()).enumerate() { - res[i] = G2Affine::conditional_select(&ai, &bi, choice); + res[i] = G2Affine::conditional_select(ai, bi, choice); } Parameters(res) } } impl Parameters { - pub fn to_bytes(&self) -> [u8; PARAMETERSIZE] { + pub fn to_bytes(self) -> [u8; PARAMETERSIZE] { let mut res = [0u8; PARAMETERSIZE]; - for i in 0..CHUNKS { - *array_mut_ref![&mut res, i * 96, 96] = self.0[i].to_compressed(); + for (i, p) in self.0.iter().enumerate() { + *array_mut_ref![&mut res, i * 96, 96] = p.to_compressed(); } res } @@ -206,10 +203,10 @@ impl Parameters { pub fn from_bytes(bytes: &[u8; PARAMETERSIZE]) -> CtOption { let mut res = [G2Affine::default(); CHUNKS]; let mut is_some = Choice::from(1u8); - for i in 0..CHUNKS { + for (i, slot) in res.iter_mut().enumerate() { is_some &= G2Affine::from_compressed(array_ref![bytes, i * 96, 96]) .map(|s| { - res[i] = s; + *slot = s; }) .is_some(); } diff --git a/src/kem/kiltz_vahlis_one.rs b/src/kem/kiltz_vahlis_one.rs index 5e1af1c..54b9bfb 100644 --- a/src/kem/kiltz_vahlis_one.rs +++ b/src/kem/kiltz_vahlis_one.rs @@ -175,10 +175,10 @@ impl IBKEM for KV1 { } impl HashParameters { - pub fn to_bytes(&self) -> [u8; HASH_PARAMETER_SIZE] { + pub fn to_bytes(self) -> [u8; HASH_PARAMETER_SIZE] { let mut res = [0u8; HASH_PARAMETER_SIZE]; - for i in 0..N { - *array_mut_ref![&mut res, i * 48, 48] = self.0[i].to_compressed(); + for (i, p) in self.0.iter().enumerate() { + *array_mut_ref![&mut res, i * 48, 48] = p.to_compressed(); } res } @@ -186,11 +186,11 @@ impl HashParameters { pub fn from_bytes(bytes: &[u8; HASH_PARAMETER_SIZE]) -> CtOption { let mut res = [G1Affine::default(); N]; let mut is_some = Choice::from(1u8); - for i in 0..N { + for (i, slot) in res.iter_mut().enumerate() { // See comment in PublicKey::from_bytes on cofactor. is_some &= G1Affine::from_compressed_unchecked(array_ref![bytes, i * 48, 48]) .map(|s| { - res[i] = s; + *slot = s; }) .is_some(); } @@ -202,7 +202,7 @@ impl ConditionallySelectable for HashParameters { fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self { let mut res = [G1Affine::default(); N]; for (i, (ai, bi)) in a.0.iter().zip(b.0.iter()).enumerate() { - res[i] = G1Affine::conditional_select(&ai, &bi, choice); + res[i] = G1Affine::conditional_select(ai, bi, choice); } HashParameters(res) } @@ -216,11 +216,7 @@ impl PartialEq for HashParameters { impl Clone for HashParameters { fn clone(&self) -> Self { - let mut res = [G1Affine::default(); N]; - for (src, dst) in self.0.iter().zip(res.as_mut().iter_mut()) { - *dst = *src; - } - Self(res) + *self } }