1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

cksum: when length/bits can't be divided by 8, generate an error

This commit is contained in:
Sylvestre Ledru 2024-05-17 21:06:32 +02:00
parent 1b78102a6b
commit db58d2b6b5
2 changed files with 18 additions and 5 deletions

View file

@ -498,10 +498,24 @@ where
properly_formatted = false;
continue;
}
let bits = caps
.name("bits")
.map(|m| m.as_str().parse::<usize>().unwrap() / 8);
(algorithm, bits)
let bits = caps.name("bits").map_or(Some(None), |m| {
let bits_value = m.as_str().parse::<usize>().unwrap();
if bits_value % 8 == 0 {
Some(Some(bits_value / 8))
} else {
properly_formatted = false;
None // Return None to signal a parsing or divisibility issue
}
});
if bits.is_none() {
// If bits is None, we have a parsing or divisibility issue
// Exit the loop outside of the closure
continue;
}
(algorithm, bits.unwrap())
} else if let Some(a) = algo_name_input {
// When a specific algorithm name is input, use it and default bits to None
(a.to_lowercase(), None)

View file

@ -1105,7 +1105,6 @@ fn test_md5_bits() {
.stderr_contains("f: no properly formatted checksum lines found");
}
#[ignore = "Should fail on bits"]
#[test]
fn test_blake2b_bits() {
let (at, mut ucmd) = at_and_ucmd!();