mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
cksum: when length/bits can't be divided by 8, generate an error
This commit is contained in:
parent
1b78102a6b
commit
db58d2b6b5
2 changed files with 18 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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!();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue