util(cksum): Fix unexpected fail when giving --length 0 to wrong algorithm

This commit is contained in:
Dorian Peron 2025-10-26 14:32:20 +01:00
parent fd83181ac2
commit 4e9d07e86c
2 changed files with 20 additions and 7 deletions

View file

@ -383,14 +383,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let input_length = matches.get_one::<usize>(options::LENGTH);
let length = match input_length {
Some(length) => {
if algo_name == ALGORITHM_OPTIONS_BLAKE2B {
calculate_blake2b_length(*length)?
} else {
return Err(ChecksumError::LengthOnlyForBlake2b.into());
}
None | Some(0) => None,
Some(length) if algo_name == ALGORITHM_OPTIONS_BLAKE2B => {
calculate_blake2b_length(*length)?
}
_ => {
return Err(ChecksumError::LengthOnlyForBlake2b.into());
}
None => None,
};
if LEGACY_ALGORITHMS.contains(&algo_name) && check {