Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
Antidote1911 committed Sep 2, 2023
1 parent 3e1df3f commit 77cb5f6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[workspace]

resolver = "2"

members = [
"core",
"cli",
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn run() -> Result<(Option<String>, Direction, f64)> {
} else if app.passwordfile().is_some() {
let pw_file = app.passwordfile().unwrap();
let p = Path::new(&pw_file);
drop(pw_file);
drop(pw_file.to_string());
let tmp=std::fs::read_to_string(p).unwrap();
Secret::new(tmp)
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sha3 = "0.10.1"
blake3 = "1.3.1"
rand = "0.8.5"
thiserror = "1.0.30"
indicatif = "0.17.0-rc.11"
indicatif = "0.17.6"
zeroize = "1.3.0"

[dev-dependencies]
Expand Down
31 changes: 19 additions & 12 deletions core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use deoxys::DeoxysII256;
use rand::prelude::StdRng;
use indicatif::{ProgressBar, ProgressStyle};


pub fn init_encryption_stream(
password: &Secret<String>,
header_type: HeaderType,
Expand Down Expand Up @@ -186,10 +187,12 @@ pub fn encrypt<>(
let mut buffer = [0u8; MSGLEN];
let mut total_bytes_read = 0;
let pb = ProgressBar::new(filesize as u64);
pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})")
.unwrap()
.with_key("eta", |state| format!("{:.1}s", state.eta().as_secs_f64()))
.progress_chars("#>-"));
pb.set_style(
ProgressStyle::with_template(
"{spinner:.green} [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})",
)
.unwrap()
.progress_chars("#>-"),);
loop {
let read_count = input.read(&mut buffer).map_err(|e| CoreErr::IOError(e))?;
total_bytes_read += read_count;
Expand Down Expand Up @@ -240,14 +243,14 @@ pub fn encrypt<>(
ui.output(percentage);

}
pb.finish();
if bench == BenchMode::WriteToFilesystem {
output.flush().map_err(|e| CoreErr::IOError(e))?;
}
if hash == HashMode::CalculateHash {
let hash = hasher.finalize().to_hex().to_string();
println!("Hash of the encrypted file is: {}", hash,);
println!("Hash Blake3 of the encrypted file is: {}", hash,);
}
pb.finish();
Ok(())
}

Expand All @@ -273,10 +276,13 @@ pub fn decrypt<>(

let mut total_bytes_read = 0;
let pb = ProgressBar::new(filesize as u64);
pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})")
.unwrap()
.with_key("eta", |state| format!("{:.1}s", state.eta().as_secs_f64()))
.progress_chars("#>-"));
pb.set_style(
ProgressStyle::with_template(
"{spinner:.green} [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})",
)
.unwrap()
.progress_chars("#>-"),
);
loop {
let read_count = input.read(&mut buffer)?;
total_bytes_read += read_count;
Expand Down Expand Up @@ -322,11 +328,12 @@ pub fn decrypt<>(
ui.output(percentage);

}
pb.finish();
if hash == HashMode::CalculateHash {
let hash = hasher.finalize().to_hex().to_string();
println!("Hash of the encrypted file is: {}. If this doesn't match with the original, something very bad has happened.", hash);
println!("Hash Blake3 of the encrypted file is: {}. If this doesn't match with the original, something very bad has happened.", hash);
}
pb.finish();

Ok(())
}

0 comments on commit 77cb5f6

Please sign in to comment.