From c76b390c6c06577a2f78aa3a1e854cfad3777ab7 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Mon, 28 Jul 2025 23:17:01 -0600 Subject: [PATCH] add quit, exit if -c is missing and no files --- Cargo.lock | 18 +++++++++++++++++- Cargo.toml | 3 ++- src/hashers.rs | 29 ----------------------------- src/main.rs | 21 ++++++++++++++------- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6b718af..58df6b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -361,7 +361,7 @@ checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" [[package]] name = "picca" -version = "0.3.2" +version = "0.4.0" dependencies = [ "ascon-hash", "belt-hash", @@ -377,6 +377,7 @@ dependencies = [ "md-5", "md2", "md4", + "quit", "ripemd", "sha1", "sha2", @@ -407,6 +408,21 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c090c608233d81bd6b90e718cf34506c60a10e633dff2292c3d1029e798d669b" +dependencies = [ + "quit_macros", +] + +[[package]] +name = "quit_macros" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d4b27a0dd5d08ad7af2d17952fb360ec9c30eeade0b32df7a3c9b099ff37564" + [[package]] name = "quote" version = "1.0.40" diff --git a/Cargo.toml b/Cargo.toml index d52692f..9d50ef8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "picca" -version = "0.3.2" +version = "0.4.0" edition = "2021" [dependencies] @@ -28,3 +28,4 @@ streebog = "0.10.2" tiger = "0.2.1" whirlpool = "0.10.4" blake3 = "1.8.2" +quit = "2.0.0" diff --git a/src/hashers.rs b/src/hashers.rs index 58dde13..84e58b9 100644 --- a/src/hashers.rs +++ b/src/hashers.rs @@ -7,7 +7,6 @@ use gost94::Gost94CryptoPro; use groestl::{Groestl224, Groestl256, Groestl384, Groestl512}; use jh::{Jh224, Jh256, Jh384, Jh512}; use k12::KangarooTwelve; -// use kupyna::{Digest as _, Kupyna224, Kupyna256, Kupyna384, Kupyna512}; use md2::Md2; use md4::Md4; use md5::Md5; @@ -246,34 +245,6 @@ pub fn hash_k12(mut file: File) -> String { return format!("{}", result); } -// pub fn hash_kupyna224(mut file: File) -> String { -// let mut hasher = Kupyna224::default(); -// _ = io::copy(&mut file, &mut hasher); - -// return format!("{:x}", hasher.finalize()); -// } - -// pub fn hash_kupyna256(mut file: File) -> String { -// let mut hasher = Kupyna256::new(); -// _ = io::copy(&mut file, &mut hasher); - -// return format!("{:x}", hasher.finalize()); -// } - -// pub fn hash_kupyna384(mut file: File) -> String { -// let mut hasher = Kupyna384::new(); -// _ = io::copy(&mut file, &mut hasher); - -// return format!("{:x}", hasher.finalize()); -// } - -// pub fn hash_kupyna512(mut file: File) -> String { -// let mut hasher = Kupyna512::new(); -// _ = io::copy(&mut file, &mut hasher); - -// return format!("{:x}", hasher.finalize()); -// } - pub fn hash_md2(mut file: File) -> String { let mut hasher = Md2::new(); _ = io::copy(&mut file, &mut hasher); diff --git a/src/main.rs b/src/main.rs index 60048f1..2813e52 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,9 +66,9 @@ const UNSECURE_ALGORITHMS: [&'static str; 7] = [ ]; #[derive(Parser)] -#[command(name = "psha")] +#[command(name = "picca")] #[command(version = option_env!("CARGO_PKG_VERSION"))] -#[command(about = "A parallel checksum tool for various algorithms")] +#[command(about = "a Parallel Implementation of Common Checksum Algorithms")] #[command(long_about = None)] struct Args { #[arg( @@ -92,16 +92,17 @@ struct Args { help = "Specify an algorithm for hashing", default_value = "sha256", value_parser = { - let mut cleaned: Vec<&str> = vec![]; + let mut combined: Vec<&str> = vec![]; for i in ALGORITHMS { - cleaned.push(i); + combined.push(i); } for i in UNSECURE_ALGORITHMS { - cleaned.push(i); + combined.push(i); } + combined.sort(); - clap::builder::PossibleValuesParser::new(Vec::from(cleaned)) + clap::builder::PossibleValuesParser::new(Vec::from(combined)) } )] algorithm: String, @@ -127,7 +128,7 @@ struct Args { )] quiet: bool, - #[arg(trailing_var_arg = true)] + #[arg(trailing_var_arg = true, required_unless_present("check"))] files: Vec, } @@ -353,6 +354,7 @@ fn generate( return (handles, arc_fe, arc_he); } +#[quit::main] fn main() { let args = Args::parse(); let cpus = match args.threads { @@ -377,6 +379,7 @@ fn main() { let handles; let arc_fe; let arc_he; + let check_mode = ! args.check.is_empty(); if &args.check.len() >= &1 { (handles, arc_fe, arc_he) = verify(cpus, args.algorithm, args.debug, args.quiet, args.check); } else { @@ -411,4 +414,8 @@ fn main() { if he != 0 { common::warning(format!("{} computed checksums did NOT match", he)); } + + if (he != 0 || fe != 0) && check_mode { + quit::with_code(1); + } }