add quit, exit if -c is missing and no files

This commit is contained in:
Bryson Steck 2025-07-28 23:17:01 -06:00
parent b938828700
commit 6cb3b9429f
Signed by: bryson
SSH key fingerprint: SHA256:XpKABw/nP4z8UVaH+weLaBnEOD86+cVwif+QjuYLGT4
4 changed files with 33 additions and 38 deletions

18
Cargo.lock generated
View file

@ -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"

View file

@ -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"

View file

@ -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);

View file

@ -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<PathBuf>,
}
@ -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);
}
}