mirror of
https://github.com/kristoferssolo/cipher-workshop.git
synced 2026-02-04 14:52:11 +00:00
fix: clippy warnings
This commit is contained in:
@@ -15,7 +15,7 @@ macro_rules! secret_block {
|
||||
$vis:vis struct $name:ident ( $int:tt, $bits:expr, $mask:expr );
|
||||
) => {
|
||||
$(#[$meta])*
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, ::zeroize::Zeroize)]
|
||||
$vis struct $name($int);
|
||||
|
||||
impl $name {
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn permutate(
|
||||
.fold(0, |acc, (idx, &input_pos_1based)| {
|
||||
let input_bit_pos = input_bit_amount - u64::from(input_pos_1based);
|
||||
let bit_value = (input >> input_bit_pos) & 1;
|
||||
let output_bit_pos = output_bit_amount - 1 - (idx as u64);
|
||||
let output_bit_pos = (output_bit_amount - 1) - (idx as u64);
|
||||
acc | (bit_value << output_bit_pos)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -120,9 +120,9 @@ fn encrypt_decrypt_roundtrip(
|
||||
let dectrypted = assert_ok!(des.decrypt(&ciphertext));
|
||||
let re_ciphertext = assert_ok!(des.encrypt(&dectrypted));
|
||||
|
||||
let ciphertext_u64 = cipher_block_to_u64(ciphertext);
|
||||
let decrypted_u64 = cipher_block_to_u64(dectrypted);
|
||||
let re_ciphertext_u64 = cipher_block_to_u64(re_ciphertext);
|
||||
let ciphertext_u64 = cipher_block_to_u64(&ciphertext);
|
||||
let decrypted_u64 = cipher_block_to_u64(&dectrypted);
|
||||
let re_ciphertext_u64 = cipher_block_to_u64(&re_ciphertext);
|
||||
|
||||
assert_eq!(
|
||||
ciphertext_u64, expected_ciphertext,
|
||||
@@ -139,16 +139,16 @@ fn encrypt_decrypt_roundtrip(
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(0x0101010101010101)]
|
||||
#[case(0xFEFEFEFEFEFEFEFE)]
|
||||
#[case(0xE001E001E001E001)]
|
||||
#[case(0x0101_0101_0101_0101)]
|
||||
#[case(0xFEFE_FEFE_FEFE_FEFE)]
|
||||
#[case(0xE001_E001_E001_E001)]
|
||||
fn weak_keys(#[case] key: u64) {
|
||||
let des = Des::new(key);
|
||||
let plaintext = TEST_PLAINTEXT;
|
||||
let ciphertext = assert_ok!(des.encrypt(&plaintext.to_be_bytes()));
|
||||
let decrypted = assert_ok!(des.decrypt(&ciphertext));
|
||||
|
||||
let decrypted_u64 = cipher_block_to_u64(decrypted);
|
||||
let decrypted_u64 = cipher_block_to_u64(&decrypted);
|
||||
|
||||
assert_eq!(
|
||||
decrypted_u64, plaintext,
|
||||
@@ -163,7 +163,7 @@ fn all_zero_paintext() {
|
||||
let plain = 0u64;
|
||||
let encrypted = assert_ok!(des.encrypt(&plain.to_be_bytes()));
|
||||
let decrypted = assert_ok!(des.decrypt(&encrypted));
|
||||
let decrypted_u64 = cipher_block_to_u64(decrypted);
|
||||
let decrypted_u64 = cipher_block_to_u64(&decrypted);
|
||||
assert_eq!(decrypted_u64, plain, "All-zero plaintext failed");
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ fn all_one_paintext() {
|
||||
let plain = u64::MAX;
|
||||
let encrypted = assert_ok!(des.encrypt(&plain.to_be_bytes()));
|
||||
let decrypted = assert_ok!(des.decrypt(&encrypted));
|
||||
let decrypted_u64 = cipher_block_to_u64(decrypted);
|
||||
let decrypted_u64 = cipher_block_to_u64(&decrypted);
|
||||
assert_eq!(decrypted_u64, plain, "All-one plaintext failed");
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ fn different_inputs() {
|
||||
);
|
||||
}
|
||||
|
||||
fn cipher_block_to_u64(block: Output) -> u64 {
|
||||
fn cipher_block_to_u64(block: &Output) -> u64 {
|
||||
let bytes = block.as_slice().try_into().expect("8 bytes");
|
||||
u64::from_be_bytes(bytes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user