add quit, exit if -c is missing and no files
This commit is contained in:
parent
b938828700
commit
6cb3b9429f
4 changed files with 33 additions and 38 deletions
18
Cargo.lock
generated
18
Cargo.lock
generated
|
@ -361,7 +361,7 @@ checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "picca"
|
name = "picca"
|
||||||
version = "0.3.2"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ascon-hash",
|
"ascon-hash",
|
||||||
"belt-hash",
|
"belt-hash",
|
||||||
|
@ -377,6 +377,7 @@ dependencies = [
|
||||||
"md-5",
|
"md-5",
|
||||||
"md2",
|
"md2",
|
||||||
"md4",
|
"md4",
|
||||||
|
"quit",
|
||||||
"ripemd",
|
"ripemd",
|
||||||
"sha1",
|
"sha1",
|
||||||
"sha2",
|
"sha2",
|
||||||
|
@ -407,6 +408,21 @@ dependencies = [
|
||||||
"unicode-ident",
|
"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]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.40"
|
version = "1.0.40"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "picca"
|
name = "picca"
|
||||||
version = "0.3.2"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -28,3 +28,4 @@ streebog = "0.10.2"
|
||||||
tiger = "0.2.1"
|
tiger = "0.2.1"
|
||||||
whirlpool = "0.10.4"
|
whirlpool = "0.10.4"
|
||||||
blake3 = "1.8.2"
|
blake3 = "1.8.2"
|
||||||
|
quit = "2.0.0"
|
||||||
|
|
|
@ -7,7 +7,6 @@ use gost94::Gost94CryptoPro;
|
||||||
use groestl::{Groestl224, Groestl256, Groestl384, Groestl512};
|
use groestl::{Groestl224, Groestl256, Groestl384, Groestl512};
|
||||||
use jh::{Jh224, Jh256, Jh384, Jh512};
|
use jh::{Jh224, Jh256, Jh384, Jh512};
|
||||||
use k12::KangarooTwelve;
|
use k12::KangarooTwelve;
|
||||||
// use kupyna::{Digest as _, Kupyna224, Kupyna256, Kupyna384, Kupyna512};
|
|
||||||
use md2::Md2;
|
use md2::Md2;
|
||||||
use md4::Md4;
|
use md4::Md4;
|
||||||
use md5::Md5;
|
use md5::Md5;
|
||||||
|
@ -246,34 +245,6 @@ pub fn hash_k12(mut file: File) -> String {
|
||||||
return format!("{}", result);
|
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 {
|
pub fn hash_md2(mut file: File) -> String {
|
||||||
let mut hasher = Md2::new();
|
let mut hasher = Md2::new();
|
||||||
_ = io::copy(&mut file, &mut hasher);
|
_ = io::copy(&mut file, &mut hasher);
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -66,9 +66,9 @@ const UNSECURE_ALGORITHMS: [&'static str; 7] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(name = "psha")]
|
#[command(name = "picca")]
|
||||||
#[command(version = option_env!("CARGO_PKG_VERSION"))]
|
#[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)]
|
#[command(long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[arg(
|
#[arg(
|
||||||
|
@ -92,16 +92,17 @@ struct Args {
|
||||||
help = "Specify an algorithm for hashing",
|
help = "Specify an algorithm for hashing",
|
||||||
default_value = "sha256",
|
default_value = "sha256",
|
||||||
value_parser = {
|
value_parser = {
|
||||||
let mut cleaned: Vec<&str> = vec![];
|
let mut combined: Vec<&str> = vec![];
|
||||||
for i in ALGORITHMS {
|
for i in ALGORITHMS {
|
||||||
cleaned.push(i);
|
combined.push(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in UNSECURE_ALGORITHMS {
|
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,
|
algorithm: String,
|
||||||
|
@ -127,7 +128,7 @@ struct Args {
|
||||||
)]
|
)]
|
||||||
quiet: bool,
|
quiet: bool,
|
||||||
|
|
||||||
#[arg(trailing_var_arg = true)]
|
#[arg(trailing_var_arg = true, required_unless_present("check"))]
|
||||||
files: Vec<PathBuf>,
|
files: Vec<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,6 +354,7 @@ fn generate(
|
||||||
return (handles, arc_fe, arc_he);
|
return (handles, arc_fe, arc_he);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[quit::main]
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let cpus = match args.threads {
|
let cpus = match args.threads {
|
||||||
|
@ -377,6 +379,7 @@ fn main() {
|
||||||
let handles;
|
let handles;
|
||||||
let arc_fe;
|
let arc_fe;
|
||||||
let arc_he;
|
let arc_he;
|
||||||
|
let check_mode = ! args.check.is_empty();
|
||||||
if &args.check.len() >= &1 {
|
if &args.check.len() >= &1 {
|
||||||
(handles, arc_fe, arc_he) = verify(cpus, args.algorithm, args.debug, args.quiet, args.check);
|
(handles, arc_fe, arc_he) = verify(cpus, args.algorithm, args.debug, args.quiet, args.check);
|
||||||
} else {
|
} else {
|
||||||
|
@ -411,4 +414,8 @@ fn main() {
|
||||||
if he != 0 {
|
if he != 0 {
|
||||||
common::warning(format!("{} computed checksums did NOT match", he));
|
common::warning(format!("{} computed checksums did NOT match", he));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (he != 0 || fe != 0) && check_mode {
|
||||||
|
quit::with_code(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue