mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
cksum: properly handle cases where --lenghth is 0 or >512
This commit is contained in:
parent
e1863ac64e
commit
e7cb4e9ff0
1 changed files with 33 additions and 20 deletions
|
@ -244,28 +244,41 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
|
||||||
let input_length = matches.get_one::<usize>(options::LENGTH);
|
let input_length = matches.get_one::<usize>(options::LENGTH);
|
||||||
let length = if let Some(length) = input_length {
|
let length = if let Some(length) = input_length {
|
||||||
if length % 8 != 0 {
|
match length.to_owned() {
|
||||||
// GNU's implementation seem to use these quotation marks
|
n if n == 0 => None,
|
||||||
// in their error messages, so we do the same.
|
n if n % 8 != 0 => {
|
||||||
uucore::show_error!("invalid length: \u{2018}{length}\u{2019}");
|
// GNU's implementation seem to use these quotation marks
|
||||||
return Err(io::Error::new(
|
// in their error messages, so we do the same.
|
||||||
io::ErrorKind::InvalidInput,
|
uucore::show_error!("invalid length: \u{2018}{length}\u{2019}");
|
||||||
"length is not a multiple of 8",
|
return Err(io::Error::new(
|
||||||
)
|
io::ErrorKind::InvalidInput,
|
||||||
.into());
|
"length is not a multiple of 8",
|
||||||
}
|
)
|
||||||
|
.into());
|
||||||
|
}
|
||||||
|
n if n > 512 => {
|
||||||
|
uucore::show_error!("invalid length: \u{2018}{length}\u{2019}");
|
||||||
|
|
||||||
if algo_name != ALGORITHM_OPTIONS_BLAKE2B {
|
return Err(io::Error::new(
|
||||||
return Err(io::Error::new(
|
io::ErrorKind::InvalidInput,
|
||||||
io::ErrorKind::InvalidInput,
|
"maximum digest length for \u{2018}BLAKE2b\u{2019} is 512 bits",
|
||||||
"--length is only supported with --algorithm=blake2b",
|
)
|
||||||
)
|
.into());
|
||||||
.into());
|
}
|
||||||
}
|
n => {
|
||||||
|
if algo_name != ALGORITHM_OPTIONS_BLAKE2B {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
"--length is only supported with --algorithm=blake2b",
|
||||||
|
)
|
||||||
|
.into());
|
||||||
|
}
|
||||||
|
|
||||||
// Divide by 8, as our blake2b implementation expects bytes
|
// Divide by 8, as our blake2b implementation expects bytes
|
||||||
// instead of bits.
|
// instead of bits.
|
||||||
Some(length / 8)
|
Some(n / 8)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue