aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-04-12 04:58:58 -0400
committerJesse Luehrs <doy@tozt.net>2020-04-12 04:58:58 -0400
commitda206507de2bc04c577030bc6a258130e03881bc (patch)
tree73cb5f02059e5318f8bb1337b7ce89ca36b871a1
parent3884ac4c0543329e8da96485e6ae626cb6a16a22 (diff)
downloadrbw-da206507de2bc04c577030bc6a258130e03881bc.tar.gz
rbw-da206507de2bc04c577030bc6a258130e03881bc.zip
avoid holding the state mutex for as long
in particular, don't hold it over pinentry calls, since those can take arbitrarily long
-rw-r--r--src/bin/rbw-agent/actions.rs13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs
index 4662164..2cb012c 100644
--- a/src/bin/rbw-agent/actions.rs
+++ b/src/bin/rbw-agent/actions.rs
@@ -5,7 +5,6 @@ pub async fn login(
state: std::sync::Arc<tokio::sync::RwLock<crate::agent::State>>,
tty: Option<&str>,
) -> anyhow::Result<()> {
- let mut state = state.write().await;
let email = config_email()
.await
.context("failed to read email from config")?;
@@ -39,7 +38,7 @@ pub async fn login(
.await
.context("failed to log in to bitwarden instance")?;
- state.priv_key = Some(keys);
+ state.write().await.priv_key = Some(keys);
db.access_token = Some(access_token);
db.refresh_token = Some(refresh_token);
@@ -62,9 +61,7 @@ pub async fn unlock(
state: std::sync::Arc<tokio::sync::RwLock<crate::agent::State>>,
tty: Option<&str>,
) -> anyhow::Result<()> {
- let mut state = state.write().await;
-
- if state.needs_unlock() {
+ if state.read().await.needs_unlock() {
let email = config_email()
.await
.context("failed to read email from config")?;
@@ -103,7 +100,7 @@ pub async fn unlock(
.await
.context("failed to unlock database")?;
- state.priv_key = Some(keys);
+ state.write().await.priv_key = Some(keys);
}
respond_ack(sock).await?;
@@ -115,9 +112,7 @@ pub async fn lock(
sock: &mut crate::sock::Sock,
state: std::sync::Arc<tokio::sync::RwLock<crate::agent::State>>,
) -> anyhow::Result<()> {
- let mut state = state.write().await;
-
- state.priv_key = None;
+ state.write().await.clear();
respond_ack(sock).await?;