Obey clippy

master
German Lashevich 5 years ago
parent 4a6a528885
commit 38a560681a
No known key found for this signature in database
GPG Key ID: 3446FAE369C9A8B4

@ -1,6 +1,6 @@
extern crate clap; extern crate clap;
extern crate dirs;
extern crate ctrlc; extern crate ctrlc;
extern crate dirs;
extern crate rpassword; extern crate rpassword;
extern crate rustotpony; extern crate rustotpony;
@ -26,7 +26,7 @@ impl Cli {
} }
fn get_secret() -> String { 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 { } // fn get_secret_from_storage() -> String { }
@ -120,7 +120,7 @@ impl Cli {
} }
fn get_database_path() -> PathBuf { 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)) home.join(Path::new(CONFIG_PATH))
} }
@ -134,9 +134,10 @@ impl Cli {
print!("\x1B[{}A\x1B[0G\x1B[0J", lines_count + 1); print!("\x1B[{}A\x1B[0G\x1B[0J", lines_count + 1);
println!("I won't tell anyone about this 🤫"); println!("I won't tell anyone about this 🤫");
std::process::exit(0); std::process::exit(0);
}).expect("Error setting Ctrl-C handler"); })
.expect("Error setting Ctrl-C handler");
// Prepare sorted keys for displaying apps in order // Prepare sorted keys for displaying apps in order
let mut keys: Vec<String> = apps.keys().map(|key| key.clone()).collect(); let mut keys: Vec<String> = apps.keys().cloned().collect();
keys.sort(); keys.sort();
loop { loop {
if is_first_iteration { if is_first_iteration {
@ -147,7 +148,7 @@ impl Cli {
Self::print_progress_bar(); Self::print_progress_bar();
for key in keys.iter() { for key in keys.iter() {
let app = &apps[key]; 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)); thread::sleep(Duration::from_millis(100));
} }
@ -179,19 +180,19 @@ impl Cli {
return; return;
} }
}; };
for (_, application) in apps { for application in apps.values() {
applications_count += 1; applications_count += 1;
output_table output_table
.entry("name") .entry("name")
.or_insert(Vec::new()) .or_insert_with(Vec::new)
.push(application.get_name()); .push(application.get_name());
output_table output_table
.entry("key") .entry("key")
.or_insert(Vec::new()) .or_insert_with(Vec::new)
.push(application.get_secret()); .push(application.get_secret());
output_table output_table
.entry("username") .entry("username")
.or_insert(Vec::new()) .or_insert_with(Vec::new)
.push(application.get_username()); .push(application.get_username());
} }
let name_max_length = output_table["name"] let name_max_length = output_table["name"]

@ -47,16 +47,16 @@ impl<DB: Database> RusTOTPony<DB> {
if self.applications.contains_key(name) { if self.applications.contains_key(name) {
Err(format!("Application with name '{}' already exists!", name)) Err(format!("Application with name '{}' already exists!", name))
} else { } else {
&self.applications.insert(String::from(name), new_app); self.applications.insert(String::from(name), new_app);
Ok(()) Ok(())
} }
} else { } 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> { 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(()) Ok(())
} else { } else {
Err(format!( Err(format!(
@ -76,7 +76,7 @@ impl<DB: Database> RusTOTPony<DB> {
} }
pub fn get_applications(&self) -> Result<&HashMap<String, GenApp>, String> { pub fn get_applications(&self) -> Result<&HashMap<String, GenApp>, String> {
if self.applications.len() == 0 { if self.applications.is_empty() {
Err(String::from("There are no applications")) Err(String::from("There are no applications"))
} else { } else {
Ok(&self.applications) Ok(&self.applications)
@ -96,7 +96,7 @@ impl<DB: Database> RusTOTPony<DB> {
} }
pub fn flush(&self) { 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 { pub fn new(path: PathBuf, secret_fn: &'static dyn Fn() -> String) -> JsonDatabase {
JsonDatabase { JsonDatabase {
file_path: path, file_path: path,
secret_fn: secret_fn, secret_fn,
} }
} }
@ -149,7 +149,7 @@ impl JsonDatabase {
sha.input_str(input); sha.input_str(input);
let mut res: [u8; KEY_SIZE] = [0; KEY_SIZE]; let mut res: [u8; KEY_SIZE] = [0; KEY_SIZE];
sha.result(&mut res); sha.result(&mut res);
return res; res
} }
fn read_database_file(&self) -> JsonDatabaseSchema { fn read_database_file(&self) -> JsonDatabaseSchema {
@ -254,7 +254,7 @@ impl JsonDatabase {
.take_read_buffer() .take_read_buffer()
.take_remaining() .take_remaining()
.iter() .iter()
.map(|&i| i), .copied(),
); );
match result { match result {
@ -288,7 +288,7 @@ impl JsonDatabase {
.take_read_buffer() .take_read_buffer()
.take_remaining() .take_remaining()
.iter() .iter()
.map(|&i| i), .copied(),
); );
match result { match result {
BufferResult::BufferUnderflow => break, BufferResult::BufferUnderflow => break,
@ -300,7 +300,7 @@ impl JsonDatabase {
} }
fn create_database_file(&self) -> Result<File, std::io::Error> { fn create_database_file(&self) -> Result<File, std::io::Error> {
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() { if let Some(parent_dir) = Path::new(&self.file_path).parent() {
let dir = dir.join(parent_dir); let dir = dir.join(parent_dir);
create_dir_all(dir)?; create_dir_all(dir)?;
@ -340,7 +340,7 @@ impl GenApp {
name: String::from(name), name: String::from(name),
secret: String::from(secret), secret: String::from(secret),
username: String::from(username), username: String::from(username),
secret_bytes: secret_bytes, secret_bytes,
} }
} }

Loading…
Cancel
Save