Port common, and most of crypto, to a more aggressive clippy

This commit is contained in:
Luke Parker
2023-07-07 22:05:07 -04:00
parent 3c6cc42c23
commit 3a626cc51e
34 changed files with 367 additions and 282 deletions

View File

@@ -85,7 +85,7 @@ impl<C: Ciphersuite> SchnorrAggregate<C> {
Rs.push(C::read_G(reader)?);
}
Ok(SchnorrAggregate { Rs, s: C::read_F(reader)? })
Ok(Self { Rs, s: C::read_F(reader)? })
}
/// Write a SchnorrAggregate to something implementing Write.
@@ -155,6 +155,7 @@ impl<C: Ciphersuite> SchnorrAggregator<C> {
///
/// The DST used here must prevent a collision with whatever hash function produced the
/// challenges.
#[must_use]
pub fn new(dst: &'static [u8]) -> Self {
let mut res = Self { digest: DigestTranscript::<C::H>::new(dst), sigs: vec![] };
res.digest.domain_separate(b"signatures");

View File

@@ -48,7 +48,7 @@ pub struct SchnorrSignature<C: Ciphersuite> {
impl<C: Ciphersuite> SchnorrSignature<C> {
/// Read a SchnorrSignature from something implementing Read.
pub fn read<R: Read>(reader: &mut R) -> io::Result<Self> {
Ok(SchnorrSignature { R: C::read_G(reader)?, s: C::read_F(reader)? })
Ok(Self { R: C::read_G(reader)?, s: C::read_F(reader)? })
}
/// Write a SchnorrSignature to something implementing Read.
@@ -69,12 +69,8 @@ impl<C: Ciphersuite> SchnorrSignature<C> {
/// This challenge must be properly crafted, which means being binding to the public key, nonce,
/// and any message. Failure to do so will let a malicious adversary to forge signatures for
/// different keys/messages.
pub fn sign(
private_key: &Zeroizing<C::F>,
nonce: Zeroizing<C::F>,
challenge: C::F,
) -> SchnorrSignature<C> {
SchnorrSignature {
pub fn sign(private_key: &Zeroizing<C::F>, nonce: Zeroizing<C::F>, challenge: C::F) -> Self {
Self {
// Uses deref instead of * as * returns C::F yet deref returns &C::F, preventing a copy
R: C::generator() * nonce.deref(),
s: (challenge * private_key.deref()) + nonce.deref(),

View File

@@ -106,7 +106,7 @@ pub(crate) fn aggregate<C: Ciphersuite>() {
keys
.iter()
.map(|key| C::generator() * key.deref())
.zip(challenges.iter().cloned())
.zip(challenges.iter().copied())
.collect::<Vec<_>>()
.as_ref(),
));