aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-02-18 15:38:43 -0500
committerJesse Luehrs <doy@tozt.net>2023-02-18 15:49:17 -0500
commit1d68b717e8ae12dfdf8af9c451dbf0d6a8cc6d71 (patch)
tree9416fd8d1bc125aa6f217d6cbc6340e27655bb99 /src/bin
parentc6a948a5cfa2783907c084cc8d1034c33db319e6 (diff)
downloadrbw-1d68b717e8ae12dfdf8af9c451dbf0d6a8cc6d71.tar.gz
rbw-1d68b717e8ae12dfdf8af9c451dbf0d6a8cc6d71.zip
clippy
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/rbw-agent/actions.rs69
-rw-r--r--src/bin/rbw-agent/agent.rs9
-rw-r--r--src/bin/rbw-agent/main.rs2
-rw-r--r--src/bin/rbw-agent/sock.rs7
-rw-r--r--src/bin/rbw/actions.rs6
-rw-r--r--src/bin/rbw/commands.rs111
-rw-r--r--src/bin/rbw/main.rs2
7 files changed, 99 insertions, 107 deletions
diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs
index 61eb74b..fff34a5 100644
--- a/src/bin/rbw-agent/actions.rs
+++ b/src/bin/rbw-agent/actions.rs
@@ -10,9 +10,8 @@ pub async fn register(
let url_str = config_base_url().await?;
let url = reqwest::Url::parse(&url_str)
.context("failed to parse base url")?;
- let host = if let Some(host) = url.host_str() {
- host
- } else {
+ let Some(host) = url.host_str()
+ else {
return Err(anyhow::anyhow!(
"couldn't find host in rbw base url {}",
url_str
@@ -33,7 +32,7 @@ pub async fn register(
let client_id = rbw::pinentry::getpin(
&config_pinentry().await?,
"API key client__id",
- &format!("Log in to {}", host),
+ &format!("Log in to {host}"),
err.as_deref(),
tty,
false,
@@ -43,7 +42,7 @@ pub async fn register(
let client_secret = rbw::pinentry::getpin(
&config_pinentry().await?,
"API key client__secret",
- &format!("Log in to {}", host),
+ &format!("Log in to {host}"),
err.as_deref(),
tty,
false,
@@ -89,9 +88,8 @@ pub async fn login(
let url_str = config_base_url().await?;
let url = reqwest::Url::parse(&url_str)
.context("failed to parse base url")?;
- let host = if let Some(host) = url.host_str() {
- host
- } else {
+ let Some(host) = url.host_str()
+ else {
return Err(anyhow::anyhow!(
"couldn't find host in rbw base url {}",
url_str
@@ -112,7 +110,7 @@ pub async fn login(
let password = rbw::pinentry::getpin(
&config_pinentry().await?,
"Master Password",
- &format!("Log in to {}", host),
+ &format!("Log in to {host}"),
err.as_deref(),
tty,
true,
@@ -292,14 +290,12 @@ async fn login_success(
sync(sock, false).await?;
let db = load_db().await?;
- let protected_private_key =
- if let Some(protected_private_key) = db.protected_private_key {
- protected_private_key
- } else {
- return Err(anyhow::anyhow!(
- "failed to find protected private key in db"
- ));
- };
+ let Some(protected_private_key) = db.protected_private_key
+ else {
+ return Err(anyhow::anyhow!(
+ "failed to find protected private key in db"
+ ));
+ };
let res = rbw::actions::unlock(
&email,
@@ -330,28 +326,24 @@ pub async fn unlock(
if state.read().await.needs_unlock() {
let db = load_db().await?;
- let iterations = if let Some(iterations) = db.iterations {
- iterations
- } else {
+ let Some(iterations) = db.iterations
+ else {
return Err(anyhow::anyhow!(
"failed to find number of iterations in db"
));
};
- let protected_key = if let Some(protected_key) = db.protected_key {
- protected_key
- } else {
+ let Some(protected_key) = db.protected_key
+ else {
return Err(anyhow::anyhow!(
"failed to find protected key in db"
));
};
- let protected_private_key =
- if let Some(protected_private_key) = db.protected_private_key {
- protected_private_key
- } else {
- return Err(anyhow::anyhow!(
- "failed to find protected private key in db"
- ));
- };
+ let Some(protected_private_key) = db.protected_private_key
+ else {
+ return Err(anyhow::anyhow!(
+ "failed to find protected private key in db"
+ ));
+ };
let email = config_email().await?;
@@ -367,7 +359,10 @@ pub async fn unlock(
let password = rbw::pinentry::getpin(
&config_pinentry().await?,
"Master Password",
- &format!("Unlock the local database for '{}'", rbw::dirs::profile()),
+ &format!(
+ "Unlock the local database for '{}'",
+ rbw::dirs::profile()
+ ),
err.as_deref(),
tty,
true,
@@ -487,9 +482,8 @@ pub async fn decrypt(
org_id: Option<&str>,
) -> anyhow::Result<()> {
let state = state.read().await;
- let keys = if let Some(keys) = state.key(org_id) {
- keys
- } else {
+ let Some(keys) = state.key(org_id)
+ else {
return Err(anyhow::anyhow!(
"failed to find decryption keys in in-memory state"
));
@@ -515,9 +509,8 @@ pub async fn encrypt(
org_id: Option<&str>,
) -> anyhow::Result<()> {
let state = state.read().await;
- let keys = if let Some(keys) = state.key(org_id) {
- keys
- } else {
+ let Some(keys) = state.key(org_id)
+ else {
return Err(anyhow::anyhow!(
"failed to find encryption keys in in-memory state"
));
diff --git a/src/bin/rbw-agent/agent.rs b/src/bin/rbw-agent/agent.rs
index d64bf21..b36fbb7 100644
--- a/src/bin/rbw-agent/agent.rs
+++ b/src/bin/rbw-agent/agent.rs
@@ -15,10 +15,9 @@ pub struct State {
impl State {
pub fn key(&self, org_id: Option<&str>) -> Option<&rbw::locked::Keys> {
- match org_id {
- Some(id) => self.org_keys.as_ref().and_then(|h| h.get(id)),
- None => self.priv_key.as_ref(),
- }
+ org_id.map_or(self.priv_key.as_ref(), |id| {
+ self.org_keys.as_ref().and_then(|h| h.get(id))
+ })
}
pub fn needs_unlock(&self) -> bool {
@@ -94,7 +93,7 @@ impl Agent {
if let Err(e) = res {
// unwrap is the only option here
sock.send(&rbw::protocol::Response::Error {
- error: format!("{:#}", e),
+ error: format!("{e:#}"),
}).await.unwrap();
}
});
diff --git a/src/bin/rbw-agent/main.rs b/src/bin/rbw-agent/main.rs
index f5d478d..d84ab5b 100644
--- a/src/bin/rbw-agent/main.rs
+++ b/src/bin/rbw-agent/main.rs
@@ -78,7 +78,7 @@ fn main() {
if let Err(e) = res {
// XXX log file?
- eprintln!("{:#}", e);
+ eprintln!("{e:#}");
std::process::exit(1);
}
}
diff --git a/src/bin/rbw-agent/sock.rs b/src/bin/rbw-agent/sock.rs
index 9458239..b97d33d 100644
--- a/src/bin/rbw-agent/sock.rs
+++ b/src/bin/rbw-agent/sock.rs
@@ -36,9 +36,8 @@ impl Sock {
buf.read_line(&mut line)
.await
.context("failed to read message from socket")?;
- Ok(serde_json::from_str(&line).map_err(|e| {
- format!("failed to parse message '{}': {}", line, e)
- }))
+ Ok(serde_json::from_str(&line)
+ .map_err(|e| format!("failed to parse message '{line}': {e}")))
}
}
@@ -46,7 +45,7 @@ pub fn listen() -> anyhow::Result<tokio::net::UnixListener> {
let path = rbw::dirs::socket_file();
// if the socket already doesn't exist, that's fine
// https://github.com/rust-lang/rust-clippy/issues/8003
- #[allow(clippy::let_underscore_drop)]
+ #[allow(let_underscore_drop)]
let _ = std::fs::remove_file(&path);
let sock = tokio::net::UnixListener::bind(&path)
.context("failed to listen on socket")?;
diff --git a/src/bin/rbw/actions.rs b/src/bin/rbw/actions.rs
index 321bff5..7ca0ef9 100644
--- a/src/bin/rbw/actions.rs
+++ b/src/bin/rbw/actions.rs
@@ -33,9 +33,9 @@ pub fn quit() -> anyhow::Result<()> {
std::fs::File::open(pidfile)?.read_to_string(&mut pid)?;
let pid = nix::unistd::Pid::from_raw(pid.parse()?);
sock.send(&rbw::protocol::Request {
- tty: nix::unistd::ttyname(0)
- .ok()
- .and_then(|p| p.to_str().map(std::string::ToString::to_string)),
+ tty: nix::unistd::ttyname(0).ok().and_then(|p| {
+ p.to_str().map(std::string::ToString::to_string)
+ }),
action: rbw::protocol::Action::Quit,
})?;
wait_for_exit(pid);
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
},
)
diff --git a/src/bin/rbw/main.rs b/src/bin/rbw/main.rs
index f56a5b1..994fb97 100644
--- a/src/bin/rbw/main.rs
+++ b/src/bin/rbw/main.rs
@@ -398,7 +398,7 @@ fn main(opt: Opt) {
.context(format!("rbw {}", opt.subcommand_name()));
if let Err(e) = res {
- eprintln!("{:#}", e);
+ eprintln!("{e:#}");
std::process::exit(1);
}
}