diff --git a/Cargo.lock b/Cargo.lock index 64f6a8c..299ea79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,39 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "blake3" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b64485778c4f16a6a5a9d335e80d449ac6c70cdd6a06d2af18a6f6f775a125b3" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if 0.1.10", + "constant_time_eq", + "crypto-mac", + "digest", +] + [[package]] name = "block-buffer" version = "0.9.0" @@ -17,12 +44,30 @@ dependencies = [ "generic-array", ] +[[package]] +name = "cc" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "cpufeatures" version = "0.1.5" @@ -32,6 +77,16 @@ dependencies = [ "libc", ] +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + [[package]] name = "digest" version = "0.9.0" @@ -51,6 +106,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "lazy_static" version = "1.4.0" @@ -98,6 +159,8 @@ dependencies = [ name = "nhc" version = "0.1.0" dependencies = [ + "blake3", + "hex", "native-windows-derive", "native-windows-gui", "sha2", @@ -149,7 +212,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" dependencies = [ "block-buffer", - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest", "opaque-debug", @@ -165,6 +228,12 @@ dependencies = [ "libm", ] +[[package]] +name = "subtle" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" + [[package]] name = "syn" version = "1.0.73" diff --git a/Cargo.toml b/Cargo.toml index 21bd236..fbb3fa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,6 @@ edition = "2018" [dependencies] sha2 = "0.9.5" native-windows-gui = "1.0.11" -native-windows-derive = "1.0.3" \ No newline at end of file +native-windows-derive = "1.0.3" +blake3 = "0.3.8" +hex = "0.4.2" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2c752e2..24cc072 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,20 +3,33 @@ extern crate native_windows_gui as nwg; use sha2::{Sha256, Digest}; +use blake3; use std::env; use std::fs::File; use std::io; use std::rc::Rc; +use hex; - -fn gen_hash(path: String) -> String { +fn gen_hash_sha256(path: String) -> String { let mut sha256 = Sha256::new(); let mut file = File::open(path).expect("Error"); io::copy(&mut file, &mut sha256).expect("Error"); - let hash: String = format!("{:X}", sha256.finalize()); + let hash: String = format!("{:x}", sha256.finalize()); + + return hash; +} + +fn gen_hash_blake3(path: String) -> std::string::String { + let mut blake3 = blake3::Hasher::new(); + + let mut file = File::open(path).expect("Error"); + + io::copy(&mut file, &mut blake3).expect("Error"); + + let hash = format!("{}", hex::encode(blake3.finalize()).to_string()); return hash; } @@ -24,19 +37,21 @@ fn gen_hash(path: String) -> String { fn main() { let args: Vec = env::args().collect(); - let hash = gen_hash(args[1].to_string()); - + let hash_sha256 = gen_hash_sha256(args[1].to_string()); + let hash_blake3 = gen_hash_blake3(args[1].to_string()); nwg::init().expect("Failed to init Native Windows GUI"); - nwg::Font::set_global_family("Segoe UI").expect("Failed to set default font"); + nwg::Font::set_global_family("Courier New").expect("Failed to set default font"); let mut window = Default::default(); - let mut text_box = Default::default(); - let mut hash_box = Default::default(); + let mut text_box_sha256 = Default::default(); + let mut hash_box_sha256 = Default::default(); + let mut text_box_blake3 = Default::default(); + let mut hash_box_blake3 = Default::default(); nwg::Window::builder() - .size((700, 40)) + .size((750, 70)) .center(true) - .title("SHA-256") + .title("Native-Hash-Calculator") .build(&mut window) .unwrap(); @@ -44,15 +59,32 @@ fn main() { .text("SHA-256:") .position((10,10)) .parent(&window) - .build(&mut text_box) + .build(&mut text_box_sha256) .unwrap(); + + nwg::TextInput::builder() + .text(&*hash_sha256) + .size((650, 20)) + .position((95,10)) + .parent(&window) + .build(&mut hash_box_sha256) + .unwrap(); + + nwg::Label::builder() + .text("Blake3:") + .position((10,40)) + .parent(&window) + .build(&mut text_box_blake3) + .unwrap(); + + nwg::TextInput::builder() - .text(&*hash) - .size((600, 20)) - .position((85,10)) + .text(&*hash_blake3) + .size((650, 20)) + .position((95,40)) .parent(&window) - .build(&mut hash_box) + .build(&mut hash_box_blake3) .unwrap(); let window = Rc::new(window);