diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index 9f4fe1d7776..79711476bc8 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -504,7 +504,6 @@ where get_expected_checksum(filename_to_check, &caps, &chosen_regex)?; // If the algo_name is provided, we use it, otherwise we try to detect it - let (algo_name, length) = if is_algo_based_format { identify_algo_name_and_length( &caps, @@ -515,7 +514,16 @@ where .unwrap_or((String::new(), None)) } else if let Some(a) = algo_name_input { // When a specific algorithm name is input, use it and use the provided bits - (a.to_lowercase(), length_input) + // except when dealing with blake2b, where we will detect the length + if algo_name_input == Some(ALGORITHM_OPTIONS_BLAKE2B) { + let length = match expected_checksum.len() { + 128 | 96 | 64 | 48 | 32 => Some(expected_checksum.len() / 2), + _ => length_input, + }; + (ALGORITHM_OPTIONS_BLAKE2B.to_string(), length) + } else { + (a.to_lowercase(), length_input) + } } else { // Default case if no algorithm is specified and non-algo based format is matched (String::new(), None) diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index f9863a30fb3..5c9edeb839f 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -890,3 +890,26 @@ fn test_star_to_start() { .succeeds() .stdout_only("f: OK\n"); } + +#[test] +fn test_check_b2sum_strict_check() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.touch("f"); + at.write("ck", "cae66941d9efbd404e4d88758ea67670 f\n"); + + scene + .ccmd("b2sum") + .arg("-c") + .arg(at.subdir.join("ck")) + .succeeds() + .stdout_only("f: OK\n"); + + scene + .ccmd("b2sum") + .arg("--strict") + .arg("-c") + .arg(at.subdir.join("ck")) + .succeeds() + .stdout_only("f: OK\n"); +}