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

@@ -61,15 +61,15 @@ enum DigestTranscriptMember {
}
impl DigestTranscriptMember {
fn as_u8(&self) -> u8 {
const fn as_u8(&self) -> u8 {
match self {
DigestTranscriptMember::Name => 0,
DigestTranscriptMember::Domain => 1,
DigestTranscriptMember::Label => 2,
DigestTranscriptMember::Value => 3,
DigestTranscriptMember::Challenge => 4,
DigestTranscriptMember::Continued => 5,
DigestTranscriptMember::Challenged => 6,
Self::Name => 0,
Self::Domain => 1,
Self::Label => 2,
Self::Value => 3,
Self::Challenge => 4,
Self::Continued => 5,
Self::Challenged => 6,
}
}
}
@@ -103,8 +103,9 @@ impl<D: Send + Clone + SecureDigest> DigestTranscript<D> {
impl<D: Send + Clone + SecureDigest> Transcript for DigestTranscript<D> {
type Challenge = Output<D>;
#[must_use]
fn new(name: &'static [u8]) -> Self {
let mut res = DigestTranscript(D::new());
let mut res = Self(D::new());
res.append(DigestTranscriptMember::Name, name);
res
}
@@ -139,10 +140,7 @@ impl<D: Send + Clone + SecureDigest> Transcript for DigestTranscript<D> {
// Digest doesn't implement Zeroize
// Implement Zeroize for DigestTranscript by writing twice the block size to the digest in an
// attempt to overwrite the internal hash state/any leftover bytes
impl<D: Send + Clone + SecureDigest> Zeroize for DigestTranscript<D>
where
D: BlockSizeUser,
{
impl<D: Send + Clone + SecureDigest + BlockSizeUser> Zeroize for DigestTranscript<D> {
fn zeroize(&mut self) {
// Update in 4-byte chunks to reduce call quantity and enable word-level update optimizations
const WORD_SIZE: usize = 4;
@@ -187,7 +185,7 @@ where
choice.zeroize();
}
mark_read(self)
mark_read(self);
}
}

View File

@@ -29,7 +29,7 @@ impl Transcript for MerlinTranscript {
type Challenge = [u8; 64];
fn new(name: &'static [u8]) -> Self {
MerlinTranscript(merlin::Transcript::new(name))
Self(merlin::Transcript::new(name))
}
fn domain_separate(&mut self, label: &'static [u8]) {
@@ -37,10 +37,7 @@ impl Transcript for MerlinTranscript {
}
fn append_message<M: AsRef<[u8]>>(&mut self, label: &'static [u8], message: M) {
assert!(
label != "dom-sep".as_bytes(),
"\"dom-sep\" is reserved for the domain_separate function",
);
assert!(label != b"dom-sep", "\"dom-sep\" is reserved for the domain_separate function",);
self.0.append_message(label, message.as_ref());
}

View File

@@ -84,20 +84,26 @@ where
assert!(t().rng_seed(b"a") != t().rng_seed(b"b"));
}
#[test]
fn test_digest() {
test_transcript::<crate::DigestTranscript<sha2::Sha256>>();
test_transcript::<crate::DigestTranscript<blake2::Blake2b512>>();
}
#[allow(clippy::module_inception)]
#[cfg(test)]
mod tests {
use super::*;
#[cfg(feature = "recommended")]
#[test]
fn test_recommended() {
test_transcript::<crate::RecommendedTranscript>();
}
#[test]
fn test_digest() {
test_transcript::<crate::DigestTranscript<sha2::Sha256>>();
test_transcript::<crate::DigestTranscript<blake2::Blake2b512>>();
}
#[cfg(feature = "merlin")]
#[test]
fn test_merlin() {
test_transcript::<crate::MerlinTranscript>();
#[cfg(feature = "recommended")]
#[test]
fn test_recommended() {
test_transcript::<crate::RecommendedTranscript>();
}
#[cfg(feature = "merlin")]
#[test]
fn test_merlin() {
test_transcript::<crate::MerlinTranscript>();
}
}