diff --git a/Cargo.lock b/Cargo.lock index 4da5266..c5aaaf0 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,7 +17,6 @@ version = "0.1.0" dependencies = [ "assert_hex", "criterion", - "getopts", "iai", "pretty_assertions", ] @@ -116,7 +115,7 @@ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "bitflags", "textwrap", - "unicode-width 0.1.14", + "unicode-width", ] [[package]] @@ -322,15 +321,6 @@ dependencies = [ "num", ] -[[package]] -name = "getopts" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1" -dependencies = [ - "unicode-width 0.2.1", -] - [[package]] name = "half" version = "1.8.3" @@ -789,7 +779,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" dependencies = [ - "unicode-width 0.1.14", + "unicode-width", ] [[package]] @@ -834,12 +824,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" -[[package]] -name = "unicode-width" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" - [[package]] name = "vcell" version = "0.1.3" diff --git a/crates/algorithms/Cargo.toml b/crates/algorithms/Cargo.toml index db2cdd0..06a45ec 100755 --- a/crates/algorithms/Cargo.toml +++ b/crates/algorithms/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] -getopts = { version = "0.2.23", optional = true } [dev-dependencies] assert_hex = "0.4.1" @@ -24,7 +23,6 @@ harness = false default = [] std = [] show_internals = ["std"] -getopts = ["dep:getopts"] [[bin]] path = "src/bin/crc32sum.rs" @@ -33,5 +31,5 @@ required-features = ["std"] [[bin]] path = "src/bin/sha256sum.rs" -name = "sha256sum" +name = "algsha256sum" required-features = ["std"] diff --git a/crates/algorithms/src/bin/crc32sum.rs b/crates/algorithms/src/bin/crc32sum.rs index e69de29..5546afd 100644 --- a/crates/algorithms/src/bin/crc32sum.rs +++ b/crates/algorithms/src/bin/crc32sum.rs @@ -0,0 +1,18 @@ +use std::io::Read; + +use algorithms::crc::Crc; + +fn main() { + let args: Vec = std::env::args().collect(); + let use_ffi = args.contains(&"-c".to_string()); + let mut input = Vec::new(); + std::io::stdin() + .read_to_end(&mut input) + .expect("could not read from stdin"); + let crc = if use_ffi { + algorithms::crc::ffi::Crc32::checksum(&input) + } else { + algorithms::crc::Crc32::checksum(&input) + }; + println!("{crc:08x}"); +} diff --git a/crates/algorithms/src/bin/sha256sum.rs b/crates/algorithms/src/bin/sha256sum.rs index 036a9fc..bcb8e43 100644 --- a/crates/algorithms/src/bin/sha256sum.rs +++ b/crates/algorithms/src/bin/sha256sum.rs @@ -1,23 +1,18 @@ +use std::io::Read; + use algorithms::hash::format_digest; fn main() { let args: Vec = std::env::args().collect(); let use_ffi = args.contains(&"-c".to_string()); - if args.len() < 2 { - usage(&args[0], 1) - } - let input = &args[1]; - println!("{:x?}", input.as_bytes()); - let raw_in = input.as_bytes(); + let mut input = Vec::new(); + std::io::stdin() + .read_to_end(&mut input) + .expect("could not read from stdin"); let hash = if use_ffi { - algorithms::hash::ffi::sha2_256_oneshot(raw_in).expect("could not hash your input data") + algorithms::hash::ffi::sha2_256_oneshot(&input).expect("could not hash your input data") } else { - algorithms::hash::sha2_256_oneshot(raw_in).expect("could not hash your input data") + algorithms::hash::sha2_256_oneshot(&input).expect("could not hash your input data") }; println!("{}", format_digest(&hash)); } - -fn usage(call: &str, code: i32) -> ! { - println!("USAGE: {call} INPUT [-c]"); - std::process::exit(code) -}