mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 20:47:46 +00:00
Merge pull request #6412 from sylvestre/hashsum-fix
hashsum: improve the blake2 --tag export
This commit is contained in:
commit
3156ad8298
2 changed files with 39 additions and 10 deletions
|
@ -59,7 +59,7 @@ struct Options {
|
|||
/// greater than 512.
|
||||
fn create_blake2b(matches: &ArgMatches) -> UResult<(&'static str, Box<dyn Digest>, usize)> {
|
||||
match matches.get_one::<usize>("length") {
|
||||
Some(0) | None => Ok(("BLAKE2", Box::new(Blake2b::new()) as Box<dyn Digest>, 512)),
|
||||
Some(0) | None => Ok(("BLAKE2b", Box::new(Blake2b::new()) as Box<dyn Digest>, 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<dyn Digest
|
|||
if length_in_bits % 8 == 0 {
|
||||
let length_in_bytes = length_in_bits / 8;
|
||||
Ok((
|
||||
"BLAKE2",
|
||||
"BLAKE2b",
|
||||
Box::new(Blake2b::with_output_bytes(length_in_bytes)),
|
||||
*length_in_bits,
|
||||
))
|
||||
|
@ -327,7 +327,7 @@ pub fn uumain(mut args: impl uucore::Args) -> 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 {
|
||||
|
|
|
@ -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!());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue