Skip to content

Commit 363e2e9

Browse files
committed
Merge branch 'dev'
2 parents e360268 + fd614d9 commit 363e2e9

File tree

4 files changed

+49
-68
lines changed

4 files changed

+49
-68
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "worgen_x"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
edition = "2021"
55
authors = ["Xen0rInspire"]
66
license = "GNU General Public License v3.0"
@@ -16,11 +16,11 @@ gui = []
1616

1717
[dependencies]
1818
rand = { version = "0.8.5", features = ["getrandom"], default-features = false }
19-
thiserror = "1.0.61"
19+
thiserror = "1.0.63"
2020
num_cpus = "1.16.0"
21-
serde_json = { version = "1.0.120", optional = true, features = ["std"], default-features = false }
21+
serde_json = { version = "1.0.128", optional = true, features = ["std"], default-features = false }
2222
indicatif = { version = "0.17.8", default-features = false }
23-
clap = { version = "4.5.9", optional = true, features = ["std"], default-features = false }
23+
clap = { version = "4.5.17", optional = true, features = ["std"], default-features = false }
2424
md-5 = "0.10.6"
2525
sha-1 = "0.10.1"
2626
sha2 = "0.10.8"

src/benchmark.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,18 @@ pub fn load_cpu_benchmark(nb_of_threads: u8) -> Result<u64, WorgenXError> {
7575
shared_signal.store(false, Ordering::SeqCst); // Stop the stress test
7676
drop(tx_progress_bar); // Drop the channel to stop the progress bar thread
7777

78-
match progress_bar_thread.join() {
79-
Ok(_) => {}
80-
Err(_) => {
81-
return Err(WorgenXError::SystemError(SystemError::ThreadError(
82-
"Something went wrong with the progress bar thread".to_string(),
83-
)))
84-
}
85-
}
78+
let _ = progress_bar_thread.join().map_err(|_| {
79+
WorgenXError::SystemError(SystemError::ThreadError(
80+
"Something went wrong with the progress bar thread".to_string(),
81+
))
82+
})?;
8683

8784
for thread in threads {
88-
match thread.join() {
89-
Ok(_) => {}
90-
Err(_) => {
91-
return Err(WorgenXError::SystemError(SystemError::ThreadError(
92-
"CPU Benchmark feature".to_string(),
93-
)))
94-
}
95-
}
85+
thread.join().map_err(|_| {
86+
WorgenXError::SystemError(SystemError::ThreadError(
87+
"CPU Benchmark feature".to_string(),
88+
))
89+
})?;
9690
}
9791

9892
let nb_of_passwd: u64 = match shared_passwd_counter.lock() {

src/system.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Internal crates
22
use crate::error::{SystemError, WorgenXError};
33

4-
// Extern crates
4+
// External crates
55
use blake2::{Blake2b512, Blake2s256};
66
use digest::Digest;
77
use indicatif::{ProgressBar, ProgressStyle};
@@ -66,9 +66,10 @@ pub fn get_user_choice_yn() -> String {
6666
#[cfg(feature = "gui")]
6767
pub fn get_user_choice() -> String {
6868
let mut buffer: String = String::new();
69-
match stdin().read_line(&mut buffer) {
70-
Ok(_) => buffer.trim().to_string(),
71-
Err(_) => String::new(),
69+
if stdin().read_line(&mut buffer).is_ok() {
70+
buffer.trim().to_string()
71+
} else {
72+
String::new()
7273
}
7374
}
7475

@@ -278,22 +279,20 @@ pub fn get_elapsed_time(start_time: Instant) -> String {
278279
/// Ok if the passwords have been written to the file, WorgenXError otherwise.
279280
///
280281
pub fn save_passwd_to_file(file: Arc<Mutex<File>>, passwords: String) -> Result<(), WorgenXError> {
281-
let mut file = match file.lock() {
282-
Ok(file) => file,
283-
Err(_) => {
284-
return Err(WorgenXError::SystemError(SystemError::UnableToWriteToFile(
285-
"output file".to_string(),
286-
"Please check the path, the permissions and try again".to_string(),
287-
)))
288-
}
289-
};
290-
match file.write_all(format!("{}\n", passwords).as_bytes()) {
291-
Ok(_) => Ok(()),
292-
Err(_) => Err(WorgenXError::SystemError(SystemError::UnableToWriteToFile(
282+
let mut file = file.lock().map_err(|_| {
283+
WorgenXError::SystemError(SystemError::UnableToWriteToFile(
293284
"output file".to_string(),
294285
"Please check the path, the permissions and try again".to_string(),
295-
))),
296-
}
286+
))
287+
})?;
288+
289+
file.write_all(format!("{}\n", passwords).as_bytes())
290+
.map_err(|_| {
291+
WorgenXError::SystemError(SystemError::UnableToWriteToFile(
292+
"output file".to_string(),
293+
"Please check the path, the permissions and try again".to_string(),
294+
))
295+
})
297296
}
298297

299298
/// This function is charged to return the progress used by the program.
@@ -510,7 +509,7 @@ mod tests {
510509
assert_eq!(manage_hash(password.clone(), "sha3-512").unwrap(), "e9a75486736a550af4fea861e2378305c4a555a05094dee1dca2f68afea49cc3a50e8de6ea131ea521311f4d6fb054a146e8282f8e35ff2e6368c1a62e909716");
511510
assert_eq!(manage_hash(password.clone(), "blake2s-256").unwrap(), "4c81099df884bd6e14a639d648bccd808512e48af211ae4f44d545ea6d5e5f2b");
512511
assert_eq!(manage_hash(password.clone(), "blake2b-512").unwrap(), "7c863950ac93c93692995e4732ce1e1466ad74a775352ffbaaf2a4a4ce9b549d0b414a1f3150452be6c7c72c694a7cb46f76452917298d33e67611f0a42addb8");
513-
assert_eq!(manage_hash(password.clone(), "whirlpool").unwrap(), "74dfc2b27acfa364da55f93a5caee29ccad3557247eda238831b3e9bd931b01d77fe994e4f12b9d4cfa92a124461d2065197d8cf7f33fc88566da2db2a4d6eae");
512+
assert_eq!(manage_hash(password.clone(), "whirlpool").unwrap(), "74dfc2b27acfa364da55f93a5caee29ccad3557247eda238831b3e9bd931b01d77fe994e4f12b9d4cfa92a124461d2065197d8cf7f33fc88566da2db2a4d6eae");
514513
assert!(manage_hash(password, "sha999").is_err());
515514
}
516515
}

src/wordlist.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const BUFFER_SIZE: usize = 100000;
2525
///
2626
static GLOBAL_COUNTER: Mutex<u64> = Mutex::new(0);
2727

28-
/// This struct is built from the user's choices will be used to generate the wordlist.
28+
/// This struct is built from the user's choices and will be used to generate the wordlist.
2929
///
3030
#[derive(Debug)]
3131
pub struct WordlistValues {
@@ -113,7 +113,7 @@ fn format_mask_to_indexes(mask: &str) -> (Vec<char>, Vec<usize>) {
113113
formated_mask.push(c);
114114
} else {
115115
mask_indexes.push(idx_formated_mask);
116-
formated_mask.push(0 as char);
116+
formated_mask.push(0u8 as char);
117117
}
118118
}
119119
_ => {
@@ -171,6 +171,7 @@ pub fn wordlist_generation_scheduler(
171171
let pb: Arc<Mutex<indicatif::ProgressBar>> = Arc::new(Mutex::new(system::get_progress_bar()));
172172
let pb_clone: Arc<Mutex<indicatif::ProgressBar>> = Arc::clone(&pb);
173173
let start: Instant = Instant::now();
174+
174175
let main_thread: JoinHandle<Result<(), WorgenXError>> = thread::spawn(move || {
175176
let mut current_value: u64 = 0;
176177
while current_value < nb_of_passwords {
@@ -185,28 +186,18 @@ pub fn wordlist_generation_scheduler(
185186
Ok(())
186187
});
187188

188-
match run_wordlist_generation(wordlist_config, nb_of_passwords, nb_of_threads, file_path) {
189-
Ok(_) => (),
190-
Err(e) => {
191-
return Err(e);
192-
}
193-
};
194-
match main_thread.join() {
195-
Ok(_) => (),
196-
Err(e) => {
197-
if let Some(err) = e.downcast_ref::<WorgenXError>() {
198-
return Err(err.clone());
199-
} else {
200-
return Err(WorgenXError::SystemError(SystemError::ThreadError(
201-
format!("{:?}", e),
202-
)));
203-
}
189+
run_wordlist_generation(wordlist_config, nb_of_passwords, nb_of_threads, file_path)?;
190+
if let Err(e) = main_thread.join() {
191+
if let Some(err) = e.downcast_ref::<WorgenXError>() {
192+
return Err(err.clone());
193+
} else {
194+
return Err(WorgenXError::SystemError(SystemError::ThreadError(
195+
format!("{:?}", e),
196+
)));
204197
}
205198
}
206-
println!(
207-
"\nWordlist generated in {}",
208-
system::get_elapsed_time(start)
209-
);
199+
200+
println!("\nWordlist generated in {}", system::get_elapsed_time(start));
210201
Ok(())
211202
}
212203

@@ -287,13 +278,10 @@ fn run_wordlist_generation(
287278
}
288279

289280
for thread in threads {
290-
match thread.join() {
291-
Ok(_) => {}
292-
Err(_) => {
293-
return Err(WorgenXError::SystemError(SystemError::ThreadError(
294-
"wordlist generation".to_string(),
295-
)))
296-
}
281+
if thread.join().is_err() {
282+
return Err(WorgenXError::SystemError(SystemError::ThreadError(
283+
"wordlist generation".to_string(),
284+
)))
297285
}
298286
}
299287

0 commit comments

Comments
 (0)