diff options
Diffstat (limited to 'src/bin/rbw/commands.rs')
-rw-r--r-- | src/bin/rbw/commands.rs | 111 |
1 files changed, 56 insertions, 55 deletions
diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index fd720cf..dda35e8 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -30,11 +30,11 @@ impl DecryptedCipher { DecryptedData::Login { password, .. } => { password.as_ref().map_or_else( || { - eprintln!("entry for '{}' had no password", desc); + eprintln!("entry for '{desc}' had no password"); false }, |password| { - println!("{}", password); + println!("{password}"); true }, ) @@ -42,11 +42,11 @@ impl DecryptedCipher { DecryptedData::Card { number, .. } => { number.as_ref().map_or_else( || { - eprintln!("entry for '{}' had no card number", desc); + eprintln!("entry for '{desc}' had no card number"); false }, |number| { - println!("{}", number); + println!("{number}"); true }, ) @@ -62,11 +62,11 @@ impl DecryptedCipher { [title, first_name, middle_name, last_name] .iter() .copied() - .cloned() .flatten() + .cloned() .collect(); if names.is_empty() { - eprintln!("entry for '{}' had no name", desc); + eprintln!("entry for '{desc}' had no name"); false } else { println!("{}", names.join(" ")); @@ -75,11 +75,11 @@ impl DecryptedCipher { } DecryptedData::SecureNote {} => self.notes.as_ref().map_or_else( || { - eprintln!("entry for '{}' had no notes", desc); + eprintln!("entry for '{desc}' had no notes"); false }, |notes| { - println!("{}", notes); + println!("{notes}"); true }, ), @@ -99,7 +99,7 @@ impl DecryptedCipher { } => match field { "notes" => { if let Some(notes) = &self.notes { - println!("{}", notes); + println!("{notes}"); } } "username" | "user" => { @@ -107,8 +107,8 @@ impl DecryptedCipher { } "totp" | "code" => { if let Some(totp) = totp { - if let Ok(code) = generate_totp(&totp) { - println!("{}", code); + if let Ok(code) = generate_totp(totp) { + println!("{code}"); } } } @@ -120,7 +120,7 @@ impl DecryptedCipher { } } "password" => { - self.display_short(&desc); + self.display_short(desc); } _ => { for f in &self.fields { @@ -148,13 +148,13 @@ impl DecryptedCipher { .. } => match field { "number" | "card" => { - self.display_short(&desc); + self.display_short(desc); } "exp" => { if let (Some(month), Some(year)) = (exp_month, exp_year) { display_field( "Exp", - Some(format!("{}/{}", month, year).as_str()), + Some(format!("{month}/{year}").as_str()), ); } } @@ -175,7 +175,7 @@ impl DecryptedCipher { } "notes" => { if let Some(notes) = &self.notes { - println!("{}", notes); + println!("{notes}"); } } _ => { @@ -212,7 +212,7 @@ impl DecryptedCipher { .. } => match field { "name" => { - self.display_short(&desc); + self.display_short(desc); } "email" => { display_field("Email", email.as_deref()); @@ -251,7 +251,7 @@ impl DecryptedCipher { } "notes" => { if let Some(notes) = &self.notes { - println!("{}", notes); + println!("{notes}"); } } _ => { @@ -311,7 +311,7 @@ impl DecryptedCipher { for uri in uris { displayed |= display_field("URI", Some(&uri.uri)); let match_type = - uri.match_type.map(|ty| format!("{}", ty)); + uri.match_type.map(|ty| format!("{ty}")); displayed |= display_field( "Match type", match_type.as_deref(), @@ -330,7 +330,7 @@ impl DecryptedCipher { if displayed { println!(); } - println!("{}", notes); + println!("{notes}"); } } DecryptedData::Card { @@ -346,7 +346,7 @@ impl DecryptedCipher { if let (Some(exp_month), Some(exp_year)) = (exp_month, exp_year) { - println!("Expiration: {}/{}", exp_month, exp_year); + println!("Expiration: {exp_month}/{exp_year}"); displayed = true; } displayed |= display_field("CVV", code.as_deref()); @@ -358,7 +358,7 @@ impl DecryptedCipher { if displayed { println!(); } - println!("{}", notes); + println!("{notes}"); } } DecryptedData::Identity { @@ -400,7 +400,7 @@ impl DecryptedCipher { if displayed { println!(); } - println!("{}", notes); + println!("{notes}"); } } DecryptedData::SecureNote {} => { @@ -616,7 +616,9 @@ pub fn config_set(key: &str, value: &str) -> anyhow::Result<()> { "email" => config.email = Some(value.to_string()), "base_url" => config.base_url = Some(value.to_string()), "identity_url" => config.identity_url = Some(value.to_string()), - "client_cert_path" => config.client_cert_path = Some(value.to_string()), + "client_cert_path" => { + config.client_cert_path = Some(value.to_string()); + } "lock_timeout" => { let timeout = value .parse() @@ -731,14 +733,14 @@ pub fn list(fields: &[String]) -> anyhow::Result<()> { ListField::User => match &cipher.data { DecryptedData::Login { username, .. } => { username.as_ref().map_or_else( - || "".to_string(), + String::new, std::string::ToString::to_string, ) } - _ => "".to_string(), + _ => String::new(), }, ListField::Folder => cipher.folder.as_ref().map_or_else( - || "".to_string(), + String::new, std::string::ToString::to_string, ), }) @@ -768,15 +770,15 @@ pub fn get( let desc = format!( "{}{}", - user.map_or_else(|| "".to_string(), |s| format!("{}@", s)), + user.map_or_else(String::new, |s| format!("{s}@")), name ); let (_, decrypted) = find_entry(&db, name, user, folder) - .with_context(|| format!("couldn't find entry for '{}'", desc))?; + .with_context(|| format!("couldn't find entry for '{desc}'"))?; if full { decrypted.display_long(&desc); - } else if field != None { + } else if field.is_some() { decrypted.display_field(&desc, field.unwrap()); } else { decrypted.display_short(&desc); @@ -796,12 +798,12 @@ pub fn code( let desc = format!( "{}{}", - user.map_or_else(|| "".to_string(), |s| format!("{}@", s)), + user.map_or_else(String::new, |s| format!("{s}@")), name ); let (_, decrypted) = find_entry(&db, name, user, folder) - .with_context(|| format!("couldn't find entry for '{}'", desc))?; + .with_context(|| format!("couldn't find entry for '{desc}'"))?; if let DecryptedData::Login { totp, .. } = decrypted.data { if let Some(totp) = totp { @@ -924,7 +926,7 @@ pub fn generate( ty: rbw::pwgen::Type, ) -> anyhow::Result<()> { let password = rbw::pwgen::pwgen(ty, len); - println!("{}", password); + println!("{password}"); if let Some(name) = name { unlock()?; @@ -1024,19 +1026,19 @@ pub fn edit( let desc = format!( "{}{}", - username.map_or_else(|| "".to_string(), |s| format!("{}@", s)), + username.map_or_else(String::new, |s| format!("{s}@")), name ); let (entry, decrypted) = find_entry(&db, name, username, folder) - .with_context(|| format!("couldn't find entry for '{}'", desc))?; + .with_context(|| format!("couldn't find entry for '{desc}'"))?; let (data, notes, history) = match &decrypted.data { DecryptedData::Login { password, .. } => { let mut contents = format!("{}\n", password.as_deref().unwrap_or("")); if let Some(notes) = decrypted.notes { - contents.push_str(&format!("\n{}\n", notes)); + contents.push_str(&format!("\n{notes}\n")); } let contents = rbw::edit::edit(&contents, HELP)?; @@ -1056,16 +1058,15 @@ pub fn edit( }) .transpose()?; let mut history = entry.history.clone(); - let (entry_username, entry_password, entry_uris, entry_totp) = - match &entry.data { - rbw::db::EntryData::Login { - username, - password, - uris, - totp, - } => (username, password, uris, totp), - _ => unreachable!(), - }; + let rbw::db::EntryData::Login { + username: entry_username, + password: entry_password, + uris: entry_uris, + totp: entry_totp, + } = &entry.data + else { + unreachable!(); + }; if let Some(prev_password) = entry_password.clone() { let new_history_entry = rbw::db::HistoryEntry { @@ -1127,12 +1128,12 @@ pub fn remove( let desc = format!( "{}{}", - username.map_or_else(|| "".to_string(), |s| format!("{}@", s)), + username.map_or_else(String::new, |s| format!("{s}@")), name ); let (entry, _) = find_entry(&db, name, username, folder) - .with_context(|| format!("couldn't find entry for '{}'", desc))?; + .with_context(|| format!("couldn't find entry for '{desc}'"))?; if let (Some(access_token), ()) = rbw::actions::remove(access_token, refresh_token, &entry.id)? @@ -1157,12 +1158,12 @@ pub fn history( let desc = format!( "{}{}", - username.map_or_else(|| "".to_string(), |s| format!("{}@", s)), + username.map_or_else(String::new, |s| format!("{s}@")), name ); let (_, decrypted) = find_entry(&db, name, username, folder) - .with_context(|| format!("couldn't find entry for '{}'", desc))?; + .with_context(|| format!("couldn't find entry for '{desc}'"))?; for history in decrypted.history { println!("{}: {}", history.last_used_date, history.password); } @@ -1251,7 +1252,7 @@ fn check_config() -> anyhow::Result<()> { fn version_or_quit() -> anyhow::Result<u32> { crate::actions::version().map_err(|e| { // https://github.com/rust-lang/rust-clippy/issues/8003 - #[allow(clippy::let_underscore_drop)] + #[allow(let_underscore_drop)] let _ = crate::actions::quit(); e }) @@ -1639,7 +1640,7 @@ fn parse_editor(contents: &str) -> (Option<String>, Option<String>) { let mut notes: String = lines .skip_while(|line| line.is_empty()) .filter(|line| !line.starts_with('#')) - .map(|line| format!("{}\n", line)) + .map(|line| format!("{line}\n")) .collect(); while notes.ends_with('\n') { notes.pop(); @@ -1707,7 +1708,7 @@ fn parse_totp_secret(secret: &str) -> anyhow::Result<Vec<u8>> { }; base32::decode( base32::Alphabet::RFC4648 { padding: false }, - &secret_str.replace(" ", ""), + &secret_str.replace(' ', ""), ) .ok_or_else(|| anyhow::anyhow!("totp secret was not valid base32")) } @@ -1819,7 +1820,7 @@ mod test { ) -> bool { let res = find_entry_raw(entries, name, username, folder); if let Err(e) = res { - format!("{}", e).contains("no entry found") + format!("{e}").contains("no entry found") } else { false } @@ -1833,7 +1834,7 @@ mod test { ) -> bool { let res = find_entry_raw(entries, name, username, folder); if let Err(e) = res { - format!("{}", e).contains("multiple entries found") + format!("{e}").contains("multiple entries found") } else { false } @@ -1892,7 +1893,7 @@ fn display_field(name: &str, field: Option<&str>) -> bool { field.map_or_else( || false, |field| { - println!("{}: {}", name, field); + println!("{name}: {field}"); true }, ) |