diff --git a/src/bin/totp.rs b/src/bin/totp.rs index 03dd4ef..ed429a6 100644 --- a/src/bin/totp.rs +++ b/src/bin/totp.rs @@ -1,6 +1,6 @@ extern crate clap; -extern crate dirs; extern crate ctrlc; +extern crate dirs; extern crate rpassword; extern crate rustotpony; @@ -26,7 +26,7 @@ impl Cli { } fn get_secret() -> String { - return rpassword::prompt_password_stdout("Enter your database pass: ").unwrap(); + rpassword::prompt_password_stdout("Enter your database pass: ").unwrap() } // fn get_secret_from_storage() -> String { } @@ -120,7 +120,7 @@ impl Cli { } fn get_database_path() -> PathBuf { - let home = dirs::home_dir().unwrap_or(PathBuf::from(".")); + let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")); home.join(Path::new(CONFIG_PATH)) } @@ -134,9 +134,10 @@ impl Cli { print!("\x1B[{}A\x1B[0G\x1B[0J", lines_count + 1); println!("I won't tell anyone about this 🤫"); std::process::exit(0); - }).expect("Error setting Ctrl-C handler"); + }) + .expect("Error setting Ctrl-C handler"); // Prepare sorted keys for displaying apps in order - let mut keys: Vec = apps.keys().map(|key| key.clone()).collect(); + let mut keys: Vec = apps.keys().cloned().collect(); keys.sort(); loop { if is_first_iteration { @@ -147,7 +148,7 @@ impl Cli { Self::print_progress_bar(); for key in keys.iter() { let app = &apps[key]; - println!{"{:06} {}", app.get_code(), app.get_name()}; + println! {"{:06} {}", app.get_code(), app.get_name()}; } thread::sleep(Duration::from_millis(100)); } @@ -179,19 +180,19 @@ impl Cli { return; } }; - for (_, application) in apps { + for application in apps.values() { applications_count += 1; output_table .entry("name") - .or_insert(Vec::new()) + .or_insert_with(Vec::new) .push(application.get_name()); output_table .entry("key") - .or_insert(Vec::new()) + .or_insert_with(Vec::new) .push(application.get_secret()); output_table .entry("username") - .or_insert(Vec::new()) + .or_insert_with(Vec::new) .push(application.get_username()); } let name_max_length = output_table["name"] diff --git a/src/lib.rs b/src/lib.rs index d8697bb..254448b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,16 +47,16 @@ impl RusTOTPony { if self.applications.contains_key(name) { Err(format!("Application with name '{}' already exists!", name)) } else { - &self.applications.insert(String::from(name), new_app); + self.applications.insert(String::from(name), new_app); Ok(()) } } else { - return Err(String::from("Couldn't decode secret key")); + Err(String::from("Couldn't decode secret key")) } } pub fn delete_application(&mut self, name: &str) -> Result<(), String> { - if let Some(_) = self.applications.remove(name) { + if self.applications.remove(name).is_some() { Ok(()) } else { Err(format!( @@ -76,7 +76,7 @@ impl RusTOTPony { } pub fn get_applications(&self) -> Result<&HashMap, String> { - if self.applications.len() == 0 { + if self.applications.is_empty() { Err(String::from("There are no applications")) } else { Ok(&self.applications) @@ -96,7 +96,7 @@ impl RusTOTPony { } pub fn flush(&self) { - &self.database.save_applications(&self.applications); + self.database.save_applications(&self.applications); } } @@ -140,7 +140,7 @@ impl JsonDatabase { pub fn new(path: PathBuf, secret_fn: &'static dyn Fn() -> String) -> JsonDatabase { JsonDatabase { file_path: path, - secret_fn: secret_fn, + secret_fn, } } @@ -149,7 +149,7 @@ impl JsonDatabase { sha.input_str(input); let mut res: [u8; KEY_SIZE] = [0; KEY_SIZE]; sha.result(&mut res); - return res; + res } fn read_database_file(&self) -> JsonDatabaseSchema { @@ -254,7 +254,7 @@ impl JsonDatabase { .take_read_buffer() .take_remaining() .iter() - .map(|&i| i), + .copied(), ); match result { @@ -288,7 +288,7 @@ impl JsonDatabase { .take_read_buffer() .take_remaining() .iter() - .map(|&i| i), + .copied(), ); match result { BufferResult::BufferUnderflow => break, @@ -300,7 +300,7 @@ impl JsonDatabase { } fn create_database_file(&self) -> Result { - let dir = dirs::home_dir().unwrap_or(PathBuf::from(".")); + let dir = dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")); if let Some(parent_dir) = Path::new(&self.file_path).parent() { let dir = dir.join(parent_dir); create_dir_all(dir)?; @@ -340,7 +340,7 @@ impl GenApp { name: String::from(name), secret: String::from(secret), username: String::from(username), - secret_bytes: secret_bytes, + secret_bytes, } }