Skip to content

Commit

Permalink
Added blake3 support
Browse files Browse the repository at this point in the history
Fixed monospace font
  • Loading branch information
guillerpsanchez committed Jun 30, 2021
1 parent 5c5b861 commit 39d1231
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 17 deletions.
71 changes: 70 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ edition = "2018"
[dependencies]
sha2 = "0.9.5"
native-windows-gui = "1.0.11"
native-windows-derive = "1.0.3"
native-windows-derive = "1.0.3"
blake3 = "0.3.8"
hex = "0.4.2"
62 changes: 47 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,88 @@
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;
}

fn main() {
let args: Vec<String> = 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();

nwg::Label::builder()
.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);
Expand Down

0 comments on commit 39d1231

Please sign in to comment.