aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/rbw-agent
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/rbw-agent
parentc6a948a5cfa2783907c084cc8d1034c33db319e6 (diff)
downloadrbw-1d68b717e8ae12dfdf8af9c451dbf0d6a8cc6d71.tar.gz
rbw-1d68b717e8ae12dfdf8af9c451dbf0d6a8cc6d71.zip
clippy
Diffstat (limited to 'src/bin/rbw-agent')
-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
4 files changed, 39 insertions, 48 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")?;