Skip to content

Commit

Permalink
Update output
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeder committed Nov 16, 2024
1 parent 8e75c4d commit 2e37432
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 37 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,15 @@ Despite the text being invisible, it's important to note that the text remains p
```sh
✔ Enter your salt · ********
Salt's size 4 is shorter than 16 and will be SHA512 hashed and then truncated to 16 bytes. Do you want to continue? [y/n]
Salt's size 4 is shorter than 16 and will be SHA512 hashed and then truncated to 16 bytes.
Do you want to continue? [y/n]
```
```sh
✔ Enter your salt · ********
Salt's size 20 is longer than 16 and will be SHA512 hashed and then truncated to 16 bytes. Do you want to continue? [y/n]
Salt's size 20 is longer than 16 and will be SHA512 hashed and then truncated to 16 bytes.
Do you want to continue? [y/n]
```
### Checkpoints
Expand Down
74 changes: 39 additions & 35 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ fn get_salt() -> Vec<u8> {
let salt_len = salt.len();
match salt_len {
0 => {
println!();
println!(
"\nSalt is empty; a default {}-byte zero-filled salt will be used.",
SlowKey::SALT_SIZE
);

let confirmation = Confirm::new()
.with_prompt(format!(
"Salt is empty; a default {}-byte zero-filled salt will be used. Do you want to continue?",
SlowKey::SALT_SIZE
))
.with_prompt("Do you want to continue?")
.wait_for_newline(true)
.interact()
.unwrap();
Expand All @@ -248,14 +248,15 @@ fn get_salt() -> Vec<u8> {
},
_ => match salt_len.cmp(&SlowKey::SALT_SIZE) {
Ordering::Less => {
println!();
println!(
"\nSalt's length {} is shorter than {} and will be SHA512 hashed and then truncated to {} bytes.",
salt_len,
SlowKey::SALT_SIZE,
SlowKey::SALT_SIZE
);

let confirmation = Confirm::new()
.with_prompt(format!(
"Salt's length {} is shorter than {} and will be SHA512 hashed and then truncated to {} bytes. Do you want to continue?",
salt_len,
SlowKey::SALT_SIZE, SlowKey::SALT_SIZE
))
.with_prompt("Do you want to continue?")
.wait_for_newline(true)
.interact()
.unwrap();
Expand All @@ -271,17 +272,18 @@ fn get_salt() -> Vec<u8> {
}
},
Ordering::Greater => {
println!();
println!(
"\nSalt's length {} is longer than {} and will be SHA512 hashed and then truncated to {} bytes.",
salt_len,
SlowKey::SALT_SIZE,
SlowKey::SALT_SIZE
);

let confirmation = Confirm::new()
.with_prompt(format!(
"Salt's length {} is longer than {} and will be SHA512 hashed and then truncated to {} bytes. Do you want to continue?",
salt_len,
SlowKey::SALT_SIZE, SlowKey::SALT_SIZE
))
.wait_for_newline(true)
.interact()
.unwrap();
.with_prompt("Do you want to continue?")
.wait_for_newline(true)
.interact()
.unwrap();

if confirmation {
let mut sha512 = Sha512::new();
Expand Down Expand Up @@ -337,17 +339,18 @@ fn get_output_key() -> Vec<u8> {
let key_len = key.len();
match key_len.cmp(&ChaCha20Poly1305::KEY_SIZE) {
Ordering::Less => {
println!();
println!(
"\nOutput encryption key's length {} is shorter than {} and will be SHA512 hashed and then truncated to {} bytes.",
key_len,
ChaCha20Poly1305::KEY_SIZE,
ChaCha20Poly1305::KEY_SIZE
);

let confirmation = Confirm::new()
.with_prompt(format!(
"Output encryption key's length {} is shorter than {} and will be SHA512 hashed and then truncated to {} bytes. Do you want to continue?",
key_len,
ChaCha20Poly1305::KEY_SIZE, ChaCha20Poly1305::KEY_SIZE
))
.wait_for_newline(true)
.interact()
.unwrap();
.with_prompt("Do you want to continue?")
.wait_for_newline(true)
.interact()
.unwrap();

if confirmation {
let mut sha512 = Sha512::new();
Expand All @@ -360,14 +363,15 @@ fn get_output_key() -> Vec<u8> {
}
},
Ordering::Greater => {
println!();
println!(
"\nOutput encryption key's length {} is longer than {} and will be SHA512 hashed and then truncated to {} bytes.",
key_len,
ChaCha20Poly1305::KEY_SIZE,
ChaCha20Poly1305::KEY_SIZE
);

let confirmation = Confirm::new()
.with_prompt(format!(
"Output encryption key's length {} is longer than {} and will be SHA512 hashed and then truncated to {} bytes. Do you want to continue?",
key_len,
ChaCha20Poly1305::KEY_SIZE, ChaCha20Poly1305::KEY_SIZE
))
.with_prompt("Do you want to continue?")
.wait_for_newline(true)
.interact()
.unwrap();
Expand Down

0 comments on commit 2e37432

Please sign in to comment.