diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 9f6ed3bec..1b6ace6da 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -376,7 +376,13 @@ fn calculate_length(algo_name: &str, length: usize) -> UResult> { 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, diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 71fc1dece..62a182a7f 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -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!());