cksum/blake2b, when length=512, don't add it in the line

This commit is contained in:
Sylvestre Ledru 2024-05-14 13:13:35 +02:00
parent 1aec8b407d
commit 8ddb2131df
2 changed files with 34 additions and 4 deletions

View file

@ -376,7 +376,13 @@ fn calculate_length(algo_name: &str, length: usize) -> UResult<Option<usize>> {
n => {
if algo_name == ALGORITHM_OPTIONS_BLAKE2B {
// Divide by 8, as our blake2b implementation expects bytes instead of bits.
Ok(Some(n / 8))
if n == 512 {
// When length is 512, it is blake2b's default.
// So, don't show it
Ok(None)
} else {
Ok(Some(n / 8))
}
} else {
Err(io::Error::new(
io::ErrorKind::InvalidInput,

View file

@ -491,9 +491,6 @@ fn test_check_error_incorrect_format() {
#[test]
fn test_dev_null() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("f");
scene
.ucmd()
@ -505,6 +502,33 @@ fn test_dev_null() {
.stdout_contains("d41d8cd98f00b204e9800998ecf8427e ");
}
#[cfg(unix)]
#[test]
fn test_blake2b_512() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("f");
scene
.ucmd()
.arg("-a")
.arg("blake2b")
.arg("-l512")
.arg("f")
.succeeds()
.stdout_contains("BLAKE2b (f) = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce");
// test also the read
at.write("checksum", "BLAKE2b (f) = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce");
scene
.ucmd()
.arg("--check")
.arg("checksum")
.succeeds()
.stdout_contains("f: OK");
}
#[test]
fn test_reset_binary() {
let scene = TestScenario::new(util_name!());