-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6148ab7
commit 216293c
Showing
6 changed files
with
163 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,46 @@ | ||
use ahsah::{utils::{Args, HasherKind}, hashes::AhsahHasher, sha512::Sha512, sha256::Sha256}; | ||
use ahsah::{ | ||
hashes::AhsahHasher, | ||
sha256::Sha256, | ||
sha512::Sha512, | ||
utils::{Args, HasherKind}, | ||
}; | ||
use clap::Parser; | ||
use std::{ | ||
fs::File, | ||
io::{BufReader, Read}, | ||
}; | ||
use clap::Parser; | ||
|
||
|
||
|
||
fn main() { | ||
let args = Args::parse(); | ||
let file = File::open(&args.path).expect("Unable to open file"); | ||
let mut buf_reader = BufReader::new(file); | ||
let mut buffer = [0; 1024]; | ||
match &args.kind { | ||
HasherKind::Sha512 =>{ | ||
let mut hasher = Sha512::new(); | ||
while let Ok(n) = buf_reader.read(&mut buffer) { | ||
if n == 0 { | ||
break; | ||
if let Some(path) = &args.path { | ||
let file = File::open(path).expect("Unable to open file"); | ||
let mut buf_reader = BufReader::new(file); | ||
let mut buffer = [0; 1024]; | ||
match &args.kind { | ||
HasherKind::Sha512 => { | ||
let mut hasher = Sha512::new(); | ||
while let Ok(n) = buf_reader.read(&mut buffer) { | ||
if n == 0 { | ||
break; | ||
} | ||
hasher.digest(&buffer[..n]); | ||
} | ||
hasher.digest(&buffer[..n]); | ||
println!("Hashing {} bytes", hasher.len()); | ||
println!("{}", hasher.finish()); | ||
} | ||
println!("Hashing {} bytes", hasher.len()); | ||
println!("{}", hasher.finish()); | ||
|
||
|
||
} , | ||
HasherKind::Sha256 =>{ | ||
let mut hasher = Sha256::new(); | ||
while let Ok(n) = buf_reader.read(&mut buffer) { | ||
if n == 0 { | ||
break; | ||
HasherKind::Sha256 => { | ||
let mut hasher = Sha256::new(); | ||
while let Ok(n) = buf_reader.read(&mut buffer) { | ||
if n == 0 { | ||
break; | ||
} | ||
hasher.digest(&buffer[..n]); | ||
} | ||
hasher.digest(&buffer[..n]); | ||
println!("Hashing {} bytes", hasher.len()); | ||
println!("{}", hasher.finish()); | ||
} | ||
println!("Hashing {} bytes", hasher.len()); | ||
println!("{}", hasher.finish()); | ||
|
||
} , | ||
} | ||
} else { | ||
panic!("File path not provided"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
use std::io::Read; | ||
|
||
pub trait AhsahHasher { | ||
fn digest(&mut self, data: &[u8]); | ||
fn finish(&mut self) -> String; | ||
|
||
fn hash_bufferd<R: Read>(&mut self, handle: &mut R) -> String; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
use ahsah::{hashes::AhsahHasher, sha512::Sha512}; | ||
use ahsah::{ | ||
hashes::AhsahHasher, | ||
sha256::Sha256, | ||
sha512::Sha512, | ||
utils::{Args, HasherKind}, | ||
}; | ||
use clap::Parser; | ||
use std::{ | ||
env::args, | ||
fs::File, | ||
io::{BufReader, Read}, | ||
io::{stdin, BufReader, Read}, | ||
path::Path, | ||
}; | ||
|
||
fn main() { | ||
let mut hasher = Sha512::new(); | ||
let file_path = match args().skip(1).next() { | ||
Some(val) => val, | ||
None => String::from("res/test.txt"), | ||
let args = Args::parse(); | ||
let mut handle: Box<dyn Read> = match args.path { | ||
Some(path) => { | ||
let path = Path::new(&path); | ||
Box::new(BufReader::new(File::open(path).unwrap())) | ||
} | ||
None => Box::new(stdin().lock()), | ||
}; | ||
let file = File::open(&file_path).expect("Unable to open file"); | ||
let mut buf_reader = BufReader::new(file); | ||
let mut buffer = [0; 1024]; | ||
while let Ok(n) = buf_reader.read(&mut buffer) { | ||
if n == 0 { | ||
break; | ||
match args.kind { | ||
HasherKind::Sha512 => { | ||
let mut hasher = Sha512::new(); | ||
println!("{}", hasher.hash_bufferd(&mut handle)); | ||
} | ||
HasherKind::Sha256 => { | ||
let mut hasher = Sha256::new(); | ||
println!("{}", hasher.hash_bufferd(&mut handle)); | ||
} | ||
hasher.digest(&buffer[..n]); | ||
} | ||
println!("Hashing {} bytes", hasher.len()); | ||
println!("{}", hasher.finish()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters