diff --git a/src/filter.rs b/src/filter.rs index 82e4634..62c6834 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use xorf::{BinaryFuse16, BinaryFuse32, BinaryFuse8, Filter as FuseFilter}; -#[derive(Copy,Clone)] +#[derive(Copy, Clone)] pub enum FilterSize { Small, Medium, diff --git a/src/filter_generator.rs b/src/filter_generator.rs index e4f18d0..554ba9e 100644 --- a/src/filter_generator.rs +++ b/src/filter_generator.rs @@ -1,4 +1,4 @@ -use crate::filter::{FilterSize, self}; +use crate::filter::{self, FilterSize}; use crate::password; use siphasher::sip::SipHasher13; use std::hash::Hash; @@ -69,7 +69,10 @@ pub fn generate_filter(input: OsString, output: OsString) { } let input_file = std::fs::File::options().read(true).open(input); - let output_file = std::fs::File::options().write(true).create_new(true).open(output); + let output_file = std::fs::File::options() + .write(true) + .create_new(true) + .open(output); let keys = SipHasher13::new().keys(); if let Err(error) = input_file { @@ -96,7 +99,10 @@ pub fn generate_filter(input: OsString, output: OsString) { let filter = filter::Filter::new(&input_file, keys, result); if let Err(()) = filter { - eprintln!("Unable to generate filter. Please report this issue with diagnostics codes {} {}", keys.0, keys.1); + eprintln!( + "Unable to generate filter. Please report this issue with diagnostics codes {} {}", + keys.0, keys.1 + ); return; } let filter = filter.unwrap(); @@ -104,7 +110,7 @@ pub fn generate_filter(input: OsString, output: OsString) { drop(input_file); let output = rmp_serde::to_vec(&filter); - + if let Err(_) = output { eprintln!("Unable to convert filter for output"); return; diff --git a/src/interactive_file.rs b/src/interactive_file.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/interactive_file.rs @@ -0,0 +1 @@ + diff --git a/src/interactive_online.rs b/src/interactive_online.rs index 341fbb8..d2258fb 100644 --- a/src/interactive_online.rs +++ b/src/interactive_online.rs @@ -3,31 +3,21 @@ use crate::password::{self, PasswordWithUsage}; use num_format::{Locale, ToFormattedString}; pub fn interactive() { - loop { - let password = rpassword::prompt_password("Password to check: "); - if password.is_err() || password.as_ref().unwrap().is_empty() { - println!("No password given. Try again"); - continue; - } + let password = password::get_password(); - if let Ok(password) = password { - let result = password::check_password_online(password); + let result = password::check_password_online(password); - if let Ok(password_result) = result { - match password_result { - PasswordWithUsage::SafePassword => println!("Password not compromised"), - PasswordWithUsage::CompromisedPassword(num) => { - println!( - "The password is compromised. It has been seen {} times", - num.to_formatted_string(&Locale::en) - ) - } - } - } else { - error::server_error() + if let Ok(password_result) = result { + match password_result { + PasswordWithUsage::SafePassword => println!("Password not compromised"), + PasswordWithUsage::CompromisedPassword(num) => { + println!( + "The password is compromised. It has been seen {} times", + num.to_formatted_string(&Locale::en) + ) } - - break; } + } else { + error::server_error() } } diff --git a/src/main.rs b/src/main.rs index 05ec9b2..1513b1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod downloader; mod error; mod filter; mod filter_generator; +mod interactive_file; mod interactive_online; mod password; diff --git a/src/password.rs b/src/password.rs index d0ce4d5..c967b92 100644 --- a/src/password.rs +++ b/src/password.rs @@ -95,3 +95,15 @@ pub fn strip_padding(line: &&str) -> bool { pub fn remove_usage(line: &str) -> String { line.split(':').next().unwrap().to_string() } + +pub fn get_password() -> String { + let password = loop { + let password = rpassword::prompt_password("Password to check: "); + if password.is_err() || password.as_ref().unwrap().is_empty() { + println!("No password given. Try again"); + continue; + } + break password.unwrap(); + }; + password +}