From 60c2afe39ee503bd4e9c8752dee2457353f15909 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Thu, 14 Aug 2025 22:02:37 -0600 Subject: [PATCH] use another feature to create smaller single algorithm binaries --- .gitignore | 1 + Cargo.lock | 142 +++++++++++++++++++++++++++++++++---------- Cargo.toml | 13 ++-- Justfile | 8 +-- docker/Dockerfile | 2 +- src/bin/picca.rs | 4 +- src/bin/sha256sum.rs | 5 +- src/core.rs | 75 ++++++----------------- src/core/hashers.rs | 57 +++++++++++++++++ src/core/macros.rs | 29 +++++++-- src/lib.rs | 2 +- 11 files changed, 232 insertions(+), 106 deletions(-) diff --git a/.gitignore b/.gitignore index ea8c4bf..83d48e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +.vscode/ /target diff --git a/Cargo.lock b/Cargo.lock index 230cae7..8ee3fad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,22 +34,22 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ - "windows-sys", + "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.9" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys", + "windows-sys 0.60.2", ] [[package]] @@ -129,9 +129,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.31" +version = "1.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2" +checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e" dependencies = [ "shlex", ] @@ -144,9 +144,9 @@ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "clap" -version = "4.5.43" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50fd97c9dc2399518aa331917ac6f274280ec5eb34e555dd291899745c48ec6f" +checksum = "1fc0e74a703892159f5ae7d3aac52c8e6c392f5ae5f359c70b5881d60aaac318" dependencies = [ "clap_builder", "clap_derive", @@ -154,9 +154,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.43" +version = "4.5.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c35b5830294e1fa0462034af85cc95225a4cb07092c088c55bda3147cfcd8f65" +checksum = "b3e7f4214277f3c7aa526a59dd3fbe306a370daee1f8b7b8c987069cd8e888a8" dependencies = [ "anstream", "anstyle", @@ -166,9 +166,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.41" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ "heck", "proc-macro2", @@ -194,7 +194,7 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" dependencies = [ - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -327,9 +327,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "md-5" @@ -367,7 +367,7 @@ checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" [[package]] name = "picca" -version = "0.5.0" +version = "0.6.0" dependencies = [ "ascon-hash", "belt-hash", @@ -408,9 +408,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "d61789d7719defeb74ea5fe81f2fdfdbd28a803847077cecce2ff14e1472f6f1" dependencies = [ "unicode-ident", ] @@ -537,9 +537,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.104" +version = "2.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +checksum = "7bc3fcb250e53458e712715cf74285c1f889686520d79294a9ef3bd7aa1fc619" dependencies = [ "proc-macro2", "quote", @@ -594,13 +594,28 @@ dependencies = [ "digest", ] +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + [[package]] name = "windows-sys" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.3", ] [[package]] @@ -609,14 +624,31 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", ] [[package]] @@ -625,48 +657,96 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + [[package]] name = "zerocopy" version = "0.8.26" diff --git a/Cargo.toml b/Cargo.toml index 3782f71..b9e48a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,22 @@ [package] name = "picca" -version = "0.5.0" +version = "0.6.0" edition = "2024" autobins = true [features] -default = [] -all-algorithms = [] +all = [] +single = [] [[bin]] name = "picca" path = "src/bin/picca.rs" -required-features = ["all-algorithms"] +required-features = ["all"] + +[profile.release] +opt-level = "z" +lto = true +strip = true [dependencies] sha2 = "0.10.9" diff --git a/Justfile b/Justfile index de41be4..c51b442 100644 --- a/Justfile +++ b/Justfile @@ -13,13 +13,13 @@ default: build-docker build-release doc # main build build-release: - cargo build --release - cargo build --release --bin picca --features all-algorithms + cargo build --release --features single + cargo build --release --bin picca --features all # debug build build-debug: - cargo build - cargo build --bin picca --features all-algorithms + cargo build --features single + cargo build --bin picca --features all # build docker images locally build-docker: clean diff --git a/docker/Dockerfile b/docker/Dockerfile index 8d407ee..6cc2e32 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,7 +6,7 @@ WORKDIR /usr/src/picca COPY . . RUN apk upgrade --no-cache && apk add musl-dev -RUN cargo install --path . --bin picca --features all-algorithms && cargo clean +RUN cargo install --path . --bin picca --features all && cargo clean FROM alpine:3 AS package diff --git a/src/bin/picca.rs b/src/bin/picca.rs index 77f6e4b..36d39db 100644 --- a/src/bin/picca.rs +++ b/src/bin/picca.rs @@ -1,6 +1,6 @@ #[quit::main] fn main() { let args = picca::Args::parse(); - let algorithm = env!("CARGO_BIN_NAME").replace("sum", ""); - picca::main!(args, algorithm, false); + let algorithm = args.algorithm; + picca::main!(args, algorithm, false, None); } diff --git a/src/bin/sha256sum.rs b/src/bin/sha256sum.rs index c216c39..e6b3939 100644 --- a/src/bin/sha256sum.rs +++ b/src/bin/sha256sum.rs @@ -1,6 +1,9 @@ +use picca::core::hashers::hash_sha256; + #[quit::main] fn main() { let args = picca::Args::parse(); let algorithm = env!("CARGO_BIN_NAME").replace("sum", ""); - picca::main!(args, algorithm, true); + let hasher = hash_sha256 as fn(Option, Option) -> String; + picca::main!(args, algorithm, true, hasher); } diff --git a/src/core.rs b/src/core.rs index 952294c..c9b2974 100644 --- a/src/core.rs +++ b/src/core.rs @@ -20,7 +20,10 @@ struct ThreadInfo { quiet: bool, thread_id: usize, filenames: Arc>>, + #[cfg(feature = "all")] algorithm: Arc, + #[cfg(feature = "single")] + hash_function: fn(Option, Option) -> String, hash_map: Option>>>, file_errors: Arc, hash_errors: Arc, @@ -66,60 +69,10 @@ fn hash(info: ThreadInfo) -> Result<(), String> { }); } - let res = match &*info.algorithm.as_str() { - "ascon" => hashers::hash_ascon(file, stdin), - "belt" => hashers::hash_belt(file, stdin), - "blake2b512" => hashers::hash_blake2b512(file, stdin), - "blake2s256" => hashers::hash_blake2s256(file, stdin), - "blake3" => hashers::hash_blake3(file, stdin), - "fsb160" => hashers::hash_fsb160(file, stdin), - "fsb224" => hashers::hash_fsb224(file, stdin), - "fsb256" => hashers::hash_fsb256(file, stdin), - "fsb384" => hashers::hash_fsb384(file, stdin), - "fsb512" => hashers::hash_fsb512(file, stdin), - "gost94" => hashers::hash_gost94(file, stdin), - "groestl224" => hashers::hash_groestl224(file, stdin), - "groestl256" => hashers::hash_groestl256(file, stdin), - "groestl384" => hashers::hash_groestl384(file, stdin), - "groestl512" => hashers::hash_groestl512(file, stdin), - "jh224" => hashers::hash_jh224(file, stdin), - "jh256" => hashers::hash_jh256(file, stdin), - "jh384" => hashers::hash_jh384(file, stdin), - "jh512" => hashers::hash_jh512(file, stdin), - "k12" => hashers::hash_k12(file, stdin), - "md2" => hashers::hash_md2(file, stdin), - "md4" => hashers::hash_md4(file, stdin), - "md5" => hashers::hash_md5(file, stdin), - "ripemd128" => hashers::hash_ripemd128(file, stdin), - "ripemd160" => hashers::hash_ripemd160(file, stdin), - "ripemd256" => hashers::hash_ripemd256(file, stdin), - "ripemd320" => hashers::hash_ripemd320(file, stdin), - "sha1" => hashers::hash_sha1(file, stdin), - "sha224" => hashers::hash_sha224(file, stdin), - "sha256" => hashers::hash_sha256(file, stdin), - "sha384" => hashers::hash_sha384(file, stdin), - "sha512" => hashers::hash_sha512(file, stdin), - "sha3_224" => hashers::hash_sha3_224(file, stdin), - "sha3_256" => hashers::hash_sha3_256(file, stdin), - "sha3_384" => hashers::hash_sha3_384(file, stdin), - "sha3_512" => hashers::hash_sha3_512(file, stdin), - "shabal192" => hashers::hash_shabal192(file, stdin), - "shabal224" => hashers::hash_shabal224(file, stdin), - "shabal256" => hashers::hash_shabal256(file, stdin), - "shabal384" => hashers::hash_shabal384(file, stdin), - "shabal512" => hashers::hash_shabal512(file, stdin), - "shake128" => hashers::hash_shake128(file, stdin), - "shake256" => hashers::hash_shake256(file, stdin), - "skein256" => hashers::hash_skein256(file, stdin), - "skein512" => hashers::hash_skein512(file, stdin), - "skein1024" => hashers::hash_skein1024(file, stdin), - "sm3" => hashers::hash_sm3(file, stdin), - "streebog256" => hashers::hash_streebog256(file, stdin), - "streebog512" => hashers::hash_streebog512(file, stdin), - "tiger" => hashers::hash_tiger(file, stdin), - "whirlpool" => hashers::hash_whirlpool(file, stdin), - _ => panic!("Somehow did not pass a supported algorithm"), - }; + #[cfg(feature = "all")] + let res = hashers::run_algorithm(info.algorithm.to_string(), file, stdin); + #[cfg(feature = "single")] + let res = (info.hash_function)(file, stdin); match &info.hash_map { Some(h) => { @@ -149,10 +102,11 @@ fn hash(info: ThreadInfo) -> Result<(), String> { pub fn verify( cpus: usize, - algorithm: String, + #[cfg(feature = "all")] algorithm: String, debug: bool, quiet: bool, checksum_files: Vec, + #[cfg(feature = "single")] hash_function: fn(Option, Option) -> String, ) -> ( Vec>>, Arc, @@ -198,6 +152,7 @@ pub fn verify( let safe_fe = Arc::clone(&arc_fe); let safe_he = Arc::clone(&arc_he); let safe_buf = Arc::clone(&arc_buf); + #[cfg(feature = "all")] let safe_alg = Arc::new(algorithm.clone()); let safe_hash = Arc::clone(&arc_hash); handles.push(thread::spawn(move || { @@ -206,7 +161,10 @@ pub fn verify( quiet, thread_id: i, filenames: safe_buf, + #[cfg(feature = "all")] algorithm: safe_alg, + #[cfg(feature = "single")] + hash_function, hash_map: Some(safe_hash), file_errors: safe_fe, hash_errors: safe_he, @@ -220,9 +178,10 @@ pub fn verify( pub fn generate( cpus: usize, buffer: VecDeque, - algorithm: String, + #[cfg(feature = "all")] algorithm: String, debug: bool, quiet: bool, + #[cfg(feature = "single")] hash_function: fn(Option, Option) -> String, ) -> ( Vec>>, Arc, @@ -243,6 +202,7 @@ pub fn generate( let safe_fe = Arc::clone(&arc_fe); let safe_he = Arc::clone(&arc_he); let safe_buf = Arc::clone(&arc_buf); + #[cfg(feature = "all")] let safe_alg = Arc::new(algorithm.clone()); handles.push(thread::spawn(move || { hash(ThreadInfo { @@ -250,7 +210,10 @@ pub fn generate( quiet, thread_id: i, filenames: safe_buf, + #[cfg(feature = "all")] algorithm: safe_alg, + #[cfg(feature = "single")] + hash_function, hash_map: None, file_errors: safe_fe, hash_errors: safe_he, diff --git a/src/core/hashers.rs b/src/core/hashers.rs index dbdb0b2..60e4ee6 100644 --- a/src/core/hashers.rs +++ b/src/core/hashers.rs @@ -23,6 +23,63 @@ use streebog::{Streebog256, Streebog512}; use tiger::Tiger; use whirlpool::Whirlpool; +pub fn run_algorithm(algorithm: String, file: Option, stdin: Option) -> String { + return match &*algorithm.as_str() { + "ascon" => hash_ascon(file, stdin), + "belt" => hash_belt(file, stdin), + "blake2b512" => hash_blake2b512(file, stdin), + "blake2s256" => hash_blake2s256(file, stdin), + "blake3" => hash_blake3(file, stdin), + "fsb160" => hash_fsb160(file, stdin), + "fsb224" => hash_fsb224(file, stdin), + "fsb256" => hash_fsb256(file, stdin), + "fsb384" => hash_fsb384(file, stdin), + "fsb512" => hash_fsb512(file, stdin), + "gost94" => hash_gost94(file, stdin), + "groestl224" => hash_groestl224(file, stdin), + "groestl256" => hash_groestl256(file, stdin), + "groestl384" => hash_groestl384(file, stdin), + "groestl512" => hash_groestl512(file, stdin), + "jh224" => hash_jh224(file, stdin), + "jh256" => hash_jh256(file, stdin), + "jh384" => hash_jh384(file, stdin), + "jh512" => hash_jh512(file, stdin), + "k12" => hash_k12(file, stdin), + "md2" => hash_md2(file, stdin), + "md4" => hash_md4(file, stdin), + "md5" => hash_md5(file, stdin), + "ripemd128" => hash_ripemd128(file, stdin), + "ripemd160" => hash_ripemd160(file, stdin), + "ripemd256" => hash_ripemd256(file, stdin), + "ripemd320" => hash_ripemd320(file, stdin), + "sha1" => hash_sha1(file, stdin), + "sha224" => hash_sha224(file, stdin), + "sha256" => hash_sha256(file, stdin), + "sha384" => hash_sha384(file, stdin), + "sha512" => hash_sha512(file, stdin), + "sha3_224" => hash_sha3_224(file, stdin), + "sha3_256" => hash_sha3_256(file, stdin), + "sha3_384" => hash_sha3_384(file, stdin), + "sha3_512" => hash_sha3_512(file, stdin), + "shabal192" => hash_shabal192(file, stdin), + "shabal224" => hash_shabal224(file, stdin), + "shabal256" => hash_shabal256(file, stdin), + "shabal384" => hash_shabal384(file, stdin), + "shabal512" => hash_shabal512(file, stdin), + "shake128" => hash_shake128(file, stdin), + "shake256" => hash_shake256(file, stdin), + "skein256" => hash_skein256(file, stdin), + "skein512" => hash_skein512(file, stdin), + "skein1024" => hash_skein1024(file, stdin), + "sm3" => hash_sm3(file, stdin), + "streebog256" => hash_streebog256(file, stdin), + "streebog512" => hash_streebog512(file, stdin), + "tiger" => hash_tiger(file, stdin), + "whirlpool" => hash_whirlpool(file, stdin), + _ => panic!("Somehow did not pass a supported algorithm"), + }; +} + pub fn hash_streebog256(file: Option, stdin: Option) -> String { let mut hasher = Streebog256::new(); if file.is_some() { diff --git a/src/core/macros.rs b/src/core/macros.rs index b73bf81..ee5d7ce 100644 --- a/src/core/macros.rs +++ b/src/core/macros.rs @@ -1,10 +1,9 @@ - #[macro_export] macro_rules! main { - ($args: expr, $algorithm: expr, $independent: expr) => { + ($args: expr, $algorithm: expr, $independent: expr, $hasher: expr) => { use clap::Parser; use std::collections::VecDeque; - use std::fs::{self}; + use std::fs::{self, File}; use std::path::PathBuf; use std::sync::atomic::Ordering; use std::thread::available_parallelism; @@ -25,7 +24,7 @@ macro_rules! main { }; if $args.debug { - if env!("CARGO_BIN_NAME") != "picca" { + if env!("CARGO_BIN_NAME") == "picca" { message::debug(format!( "Starting picca using algorithm {} with a max of {} threads", $algorithm, cpus @@ -52,7 +51,16 @@ macro_rules! main { let arc_he; let check_mode = !$args.check.is_empty(); if &$args.check.len() >= &1 { - (handles, arc_fe, arc_he) = picca::core::verify(cpus, $algorithm, $args.debug, $args.quiet, $args.check); + (handles, arc_fe, arc_he) = picca::core::verify( + cpus, + #[cfg(feature = "all")] + $algorithm, + $args.debug, + $args.quiet, + $args.check, + #[cfg(feature = "single")] + $hasher, + ); } else { let mut buffer = VecDeque::new(); if &$args.files.len() >= &1 { @@ -71,7 +79,16 @@ macro_rules! main { buffer.push_back(PathBuf::from("-")); } - (handles, arc_fe, arc_he) = picca::core::generate(cpus, buffer, $algorithm, $args.debug, $args.quiet); + (handles, arc_fe, arc_he) = picca::core::generate( + cpus, + buffer, + #[cfg(feature = "all")] + $algorithm, + $args.debug, + $args.quiet, + #[cfg(feature = "single")] + $hasher, + ); } for handle in handles { diff --git a/src/lib.rs b/src/lib.rs index 109e49e..c7bfce7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,7 @@ pub struct Args { )] pub debug: bool, - #[cfg(feature = "all-algorithms")] + #[cfg(feature = "all")] #[arg( short, long,