diff --git a/Cargo.lock b/Cargo.lock index 041d448..8a52a68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,6 +60,21 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.15" @@ -230,6 +245,20 @@ dependencies = [ "zeroize", ] +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.6", +] + [[package]] name = "cipher" version = "0.4.4" @@ -310,6 +339,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "core2" version = "0.4.0" @@ -645,6 +680,29 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.5.0" @@ -708,6 +766,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "keccak" version = "0.1.5" @@ -861,6 +928,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "number_prefix" version = "0.4.0" @@ -1216,12 +1292,13 @@ dependencies = [ [[package]] name = "slowkey" -version = "1.1.0" +version = "1.1.1" dependencies = [ "base64 0.21.7", "better-panic", "bs58", "chacha20poly1305", + "chrono", "clap", "color-backtrace", "crossterm", @@ -1428,6 +1505,61 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + [[package]] name = "winapi" version = "0.3.9" @@ -1450,7 +1582,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -1459,6 +1591,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 3bbf2ff..0fd1a06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Leonid Beder "] edition = "2021" name = "slowkey" -version = "1.1.0" +version = "1.1.1" [dependencies] better-panic = "0.3.0" @@ -25,6 +25,7 @@ serde_json = "1.0.128" chacha20poly1305 = "0.10.1" glob = "0.3.1" indicatif = "0.17.8" +chrono = "0.4.38" [dev-dependencies] rstest = "0.18.2" diff --git a/README.md b/README.md index f3e4456..8f8d1da 100755 --- a/README.md +++ b/README.md @@ -206,7 +206,9 @@ Final result: Key (hex) is (please highlight to see): 8ef994a0383b2a445d3f55a1251eb002 -Finished in 49s +Start time: 2024-09-18 18:57:34 +End time: 2024-09-18 18:58:26 +Total running time: 52s ``` Please note that salt must be `16` bytes long, therefore shorter/longer salts will be SHA512 hashed and then truncated to `16` bytes: @@ -298,7 +300,9 @@ Final result: Key (hex) is (please highlight to see): 8ef994a0383b2a445d3f55a1251eb002 -Finished in 26s +Start time: 2024-09-18 19:00:59 +End time: 2024-09-18 19:01:25 +Total running time: 25s ``` ### Outputs @@ -322,7 +326,9 @@ Key (hex) is (please highlight to see): 8ef994a0383b2a445d3f55a1251eb002 Key (base64) is (please highlight to see): jvmUoDg7KkRdP1WhJR6wAg== Key (base58) is (please highlight to see): JezwF9TWYHNERQAi63dHcu -Finished in 50s +Start time: 2024-09-18 18:57:34 +End time: 2024-09-18 18:58:26 +Total running time: 52s ``` In addition to the above, the tool also supports saving the output to be encrypted and stored to the disk: @@ -346,7 +352,9 @@ Key (hex) is (please highlight to see): 8ef994a0383b2a445d3f55a1251eb002 Saved encrypted output to "~/output.enc" -Finished in 50s +Start time: 2024-09-18 18:57:34 +End time: 2024-09-18 18:58:26 +Total running time: 52s ``` Let's use the `show-output` command to decrypt its contents: @@ -408,7 +416,7 @@ Derived key: edada70cd27e31ddcfc41edba2f63a03418fc1acd352ff78eff149573c5e247f0e0 MIT License -Copyright (c) 2018 Leonid Beder +Copyright (c) 2024 Leonid Beder Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/main.rs b/src/main.rs index 47f1cc1..6e03d07 100755 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ use crate::{ }, }; use base64::{engine::general_purpose, Engine as _}; +use chrono::{DateTime, Utc}; use clap::{Parser, Subcommand}; use crossterm::style::Stylize; use dialoguer::{theme::ColorfulTheme, Confirm, Password}; @@ -37,7 +38,7 @@ use std::{ path::PathBuf, str::from_utf8, thread, - time::{Duration, Instant}, + time::{Duration, Instant, SystemTime}, }; use utils::{argon2id::Argon2idOptions, chacha20poly1305::ChaCha20Poly1305}; @@ -487,7 +488,8 @@ fn main() { } } - let start_time = Instant::now(); + let start_time = SystemTime::now(); + let running_time = Instant::now(); let slowkey = SlowKey::new(&slowkey_opts); let handle = thread::spawn(move || { @@ -563,8 +565,22 @@ fn main() { } println!( - "Finished in {}", - format_duration(Duration::new(start_time.elapsed().as_secs(), 0)) + "Start time: {}", + DateTime::::from(start_time) + .format("%Y-%m-%d %H:%M:%S") + .to_string() + .cyan() + ); + println!( + "End time: {}", + DateTime::::from(SystemTime::now()) + .format("%Y-%m-%d %H:%M:%S") + .to_string() + .cyan() + ); + println!( + "Total running time: {}", + format_duration(Duration::new(running_time.elapsed().as_secs(), 0)) .to_string() .cyan() );