diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 39b5a0a07..892f3a15b 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -59,7 +59,7 @@ struct Options { /// greater than 512. fn create_blake2b(matches: &ArgMatches) -> UResult<(&'static str, Box, usize)> { match matches.get_one::("length") { - Some(0) | None => Ok(("BLAKE2", Box::new(Blake2b::new()) as Box, 512)), + Some(0) | None => Ok(("BLAKE2b", Box::new(Blake2b::new()) as Box, 512)), Some(length_in_bits) => { if *length_in_bits > 512 { return Err(USimpleError::new( @@ -71,7 +71,7 @@ fn create_blake2b(matches: &ArgMatches) -> UResult<(&'static str, Box UResult<()> { // least somewhat better from a user's perspective. let matches = command.try_get_matches_from(args)?; - let (name, algo, bits) = detect_algo(&binary_name, &matches)?; + let (algoname, algo, bits) = detect_algo(&binary_name, &matches)?; let binary = if matches.get_flag("binary") { true @@ -355,7 +355,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { } let opts = Options { - algoname: name, + algoname, digest: algo, output_bits: bits, binary, @@ -792,17 +792,22 @@ where .map_err_context(|| "failed to read input".to_string())?; let (escaped_filename, prefix) = escape_filename(filename); if options.tag { - println!( - "{}{} ({}) = {}", - prefix, options.algoname, escaped_filename, sum - ); + if options.algoname == "BLAKE2b" && options.digest.output_bits() != 512 { + // special case for BLAKE2b with non-default output length + println!( + "BLAKE2b-{} ({escaped_filename}) = {sum}", + options.digest.output_bits() + ); + } else { + println!("{prefix}{} ({escaped_filename}) = {sum}", options.algoname); + } } else if options.nonames { println!("{sum}"); } else if options.zero { // with zero, we don't escape the filename - print!("{} {}{}\0", sum, binary_marker, filename.display()); + print!("{sum} {binary_marker}{}\0", filename.display()); } else { - println!("{}{} {}{}", prefix, sum, binary_marker, escaped_filename); + println!("{prefix}{sum} {binary_marker}{escaped_filename}"); } } if bad_format > 0 && failed_cksum == 0 && correct_format == 0 && !options.status { diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index eed265ac5..ee792f0d4 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -243,6 +243,30 @@ fn test_invalid_b2sum_length_option_too_large() { .code_is(1); } +#[test] +fn test_check_b2sum_tag_output() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + + at.touch("f"); + + scene + .ccmd("b2sum") + .arg("--length=0") + .arg("--tag") + .arg("f") + .succeeds() + .stdout_only("BLAKE2b (f) = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce\n"); + + scene + .ccmd("b2sum") + .arg("--length=128") + .arg("--tag") + .arg("f") + .succeeds() + .stdout_only("BLAKE2b-128 (f) = cae66941d9efbd404e4d88758ea67670\n"); +} + #[test] fn test_check_file_not_found_warning() { let scene = TestScenario::new(util_name!());