Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eschorn1 committed Jan 6, 2024
1 parent d47b34b commit 9144179
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use fips204::traits::{PreGen, Signer, Verifier};
use fips204::{ml_dsa_44, ml_dsa_65, ml_dsa_87};


#[allow(clippy::redundant_closure)]
pub fn criterion_benchmark(c: &mut Criterion) {
let message = [0u8, 1, 2, 3, 4, 5, 6, 7];

Expand Down
23 changes: 12 additions & 11 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,29 +303,30 @@ mod tests {
fn test_coef_from_three_bytes1() {
let bytes = [0x12u8, 0x34, 0x56];
let res = coef_from_three_bytes(bytes).unwrap();
assert_eq!(res, 0x563412);
assert_eq!(res, 0x0056_3412);
}

#[test]
fn test_coef_from_three_bytes2() {
let bytes = [0x12u8, 0x34, 0x80];
let res = coef_from_three_bytes(bytes).unwrap();
assert_eq!(res, 0x003412);
assert_eq!(res, 0x0000_3412);
}

#[test]
fn test_coef_from_three_bytes3() {
let bytes = [0x01u8, 0xe0, 0x80];
let res = coef_from_three_bytes(bytes).unwrap();
assert_eq!(res, 0x00e001);
assert_eq!(res, 0x0000_e001);
}

#[test]
#[allow(clippy::should_panic_without_expect)]
#[should_panic]
fn test_coef_from_three_bytes4() {
let bytes = [0x01u8, 0xe0, 0x7f];
let res = coef_from_three_bytes(bytes).unwrap();
assert_eq!(res, 0x563412);
assert_eq!(res, 0x0056_3412);
}

#[test]
Expand All @@ -346,21 +347,21 @@ mod tests {
fn test_coef_from_half_byte_validation1() {
let inp = 22;
let res = coef_from_half_byte::<2>(inp);
assert!(res.is_err())
assert!(res.is_err());
}

#[test]
fn test_coef_from_half_byte_validation2() {
let inp = 15;
let res = coef_from_half_byte::<2>(inp);
assert!(res.is_err())
assert!(res.is_err());
}

#[test]
fn test_coef_from_half_byte_validation3() {
let inp = 10;
let res = coef_from_half_byte::<4>(inp);
assert!(res.is_err())
assert!(res.is_err());
}

#[test]
Expand All @@ -378,23 +379,23 @@ mod tests {
// wrong size of bytes
let random_bytes: Vec<u8> = (0..32 * 7).map(|_| rand::random::<u8>()).collect();
let res = simple_bit_unpack(&random_bytes, 2u32.pow(6) - 1);
assert!(res.is_err())
assert!(res.is_err());
}

#[test]
fn test_bit_unpack_validation1() {
// wrong size of bytes
let random_bytes: Vec<u8> = (0..32 * 7).map(|_| rand::random::<u8>()).collect();
let res = bit_unpack(&random_bytes, 0, 2u32.pow(6) - 1);
assert!(res.is_err())
assert!(res.is_err());
}

#[test]
fn test_simple_bit_pack_validation1() {
let mut random_bytes: Vec<u8> = (0..32 * 6).map(|_| rand::random::<u8>()).collect();
let r = [0i32; 256];
let res = simple_bit_pack(&r, 2u32.pow(6) - 1, &mut random_bytes);
assert!(res.is_ok())
assert!(res.is_ok());
}

#[test]
Expand All @@ -403,7 +404,7 @@ mod tests {
// wrong size r coeff
let r = [1024i32; 256];
let res = simple_bit_pack(&r, 2u32.pow(6) - 1, &mut random_bytes);
assert!(res.is_err())
assert!(res.is_err());
}

// TODO: reword to start with bit_pack..
Expand Down
5 changes: 3 additions & 2 deletions src/encodings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ mod tests {
random_pk.iter_mut().for_each(|a| *a = rand::random::<u8>());
//let mut rho = [0u8; 32];
//let mut t1 = [[0i32; 256]; 6];
let (rho, t1) = pk_decode::<6, 1952>(&random_pk.try_into().unwrap()).unwrap();
let (rho, t1) = pk_decode::<6, 1952>(&random_pk).unwrap();
//let mut res = [0u8; 1952];
let res = pk_encode::<6, 1952>(&rho, &t1).unwrap();
assert_eq!(random_pk, res);
Expand All @@ -392,7 +392,7 @@ mod tests {
random_pk.iter_mut().for_each(|a| *a = rand::random::<u8>());
//let mut rho = [0u8; 32];
//let mut t1 = [[0i32; 256]; 8];
let (rho, t1) = pk_decode::<8, 2592>(&random_pk.try_into().unwrap()).unwrap();
let (rho, t1) = pk_decode::<8, 2592>(&random_pk).unwrap();
//let mut res = [0u8; 2592];
let res = pk_encode::<8, 2592>(&rho, &t1).unwrap();
assert_eq!(random_pk, res);
Expand Down Expand Up @@ -427,6 +427,7 @@ mod tests {
let sk = sk_encode::<13, 2, 4, 4, 2560>(&rho, &k, &tr, &s1, &s2, &t0).unwrap();
let res = sk_decode::<13, 2, 4, 4, 2560>(&sk);
assert!(res.is_ok());
#[allow(clippy::similar_names)]
let (rho_test, k_test, tr_test, s1_test, s2_test, t0_test) = res.unwrap();

assert!(
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![allow(clippy::cast_possible_wrap)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::cast_sign_loss)]
#![allow(clippy::similar_names)]

// Roadmap
// 0. Stay on top of FIPS 204 updates
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn test_44_no_verif() {

// Bad messages
for i in 0..8 {
let mut msg_bad = msg.clone();
let mut msg_bad = msg;
msg_bad[i] ^= 0x08;
let ver = pk.try_verify_vt(&msg_bad, &sig).unwrap();
assert!(!ver)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ impl RngCore for MyRng {
}

fn try_fill_bytes(&mut self, out: &mut [u8]) -> Result<(), rand_core::Error> {
Ok(self.fill_bytes(out))
self.fill_bytes(out);
Ok(())
}
}

Expand Down

0 comments on commit 9144179

Please sign in to comment.