From cd6fdc3e03b0143f0e2a4d7537f58e595cf7cc0b Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Fri, 28 Feb 2025 16:38:16 +0100 Subject: b3sum: add --tag --- b3sum/src/main.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/b3sum/src/main.rs b/b3sum/src/main.rs index baa6b6c..b10cff8 100644 --- a/b3sum/src/main.rs +++ b/b3sum/src/main.rs @@ -16,6 +16,7 @@ const KEYED_ARG: &str = "keyed"; const LENGTH_ARG: &str = "length"; const NO_NAMES_ARG: &str = "no_names"; const RAW_ARG: &str = "raw"; +const TAG_ARG: &str = "tag"; const CHECK_ARG: &str = "check"; #[derive(Parser)] @@ -72,6 +73,10 @@ struct Inner { #[arg(long)] raw: bool, + /// Prefix output with `BLAKE3 (...) =` + #[arg(long)] + tag: bool, + /// Read BLAKE3 sums from the [FILE]s and check them #[arg( short, @@ -80,6 +85,7 @@ struct Inner { conflicts_with(KEYED_ARG), conflicts_with(LENGTH_ARG), conflicts_with(RAW_ARG), + conflicts_with(TAG_ARG), conflicts_with(NO_NAMES_ARG) )] check: bool, @@ -138,6 +144,10 @@ impl Args { self.inner.raw } + fn tag(&self) -> bool { + self.inner.tag + } + fn no_mmap(&self) -> bool { self.inner.no_mmap } @@ -393,6 +403,12 @@ fn hash_one_input(path: &Path, args: &Args) -> Result<()> { if is_escaped { print!("\\"); } + if args.tag() { + print!("BLAKE3 ({}) = ", filepath_string); + write_hex_output(output, args)?; + println!(); + return Ok(()); + } write_hex_output(output, args)?; println!(" {}", filepath_string); Ok(()) -- cgit v1.2.3