aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-07-16 16:28:48 -0400
committerJesse Luehrs <doy@tozt.net>2023-07-16 16:29:07 -0400
commiteb4669dbb7b9eb9175720ea12f2fa47f95158070 (patch)
treea8b49eec3ff7ec705a2959d3e970da42e02052cc
parent3e9bcc72938feee1491124ff8c5e8bec2f15bedc (diff)
downloadrbw-eb4669dbb7b9eb9175720ea12f2fa47f95158070.tar.gz
rbw-eb4669dbb7b9eb9175720ea12f2fa47f95158070.zip
clippy and fmt
-rw-r--r--src/bin/rbw-agent/actions.rs14
-rw-r--r--src/bin/rbw-agent/agent.rs44
-rw-r--r--src/bin/rbw-agent/notifications.rs21
-rw-r--r--src/bin/rbw/commands.rs36
-rw-r--r--src/bin/rbw/main.rs2
5 files changed, 46 insertions, 71 deletions
diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs
index 4d77133..1974736 100644
--- a/src/bin/rbw-agent/actions.rs
+++ b/src/bin/rbw-agent/actions.rs
@@ -1,5 +1,3 @@
-use std::f32::consts::E;
-
use anyhow::Context as _;
pub async fn register(
@@ -210,7 +208,7 @@ pub async fn login(
let err = subscribe_to_notifications(state.clone()).await.err();
if let Some(e) = err {
- eprintln!("failed to subscribe to notifications: {}", e)
+ eprintln!("failed to subscribe to notifications: {e}");
}
respond_ack(sock).await?;
@@ -674,7 +672,7 @@ pub async fn subscribe_to_notifications(
.await
.context("Config is missing")?;
let email = config.email.clone().context("Config is missing email")?;
- let db = rbw::db::Db::load_async(&config.server_name().as_str(), &email)
+ let db = rbw::db::Db::load_async(config.server_name().as_str(), &email)
.await?;
let access_token =
db.access_token.context("Error getting access token")?;
@@ -685,7 +683,7 @@ pub async fn subscribe_to_notifications(
.expect("config is missing base url")
.replace("https://", "wss://")
+ "/notifications/hub?access_token=";
- websocket_url = websocket_url + &access_token;
+ websocket_url.push_str(&access_token);
let mut state = state.write().await;
let err = state
@@ -694,9 +692,5 @@ pub async fn subscribe_to_notifications(
.await
.err();
- if let Some(err) = err {
- return Err(anyhow::anyhow!(err.to_string()));
- } else {
- Ok(())
- }
+ err.map_or_else(|| Ok(()), |err| Err(anyhow::anyhow!(err.to_string())))
}
diff --git a/src/bin/rbw-agent/agent.rs b/src/bin/rbw-agent/agent.rs
index b88121d..d4b3341 100644
--- a/src/bin/rbw-agent/agent.rs
+++ b/src/bin/rbw-agent/agent.rs
@@ -1,4 +1,3 @@
-use aes::cipher::typenum::private::IsNotEqualPrivate;
use anyhow::Context as _;
use futures_util::StreamExt as _;
@@ -12,7 +11,7 @@ pub struct State {
pub timeout_duration: std::time::Duration,
pub sync_timeout: crate::timeout::Timeout,
pub sync_timeout_duration: std::time::Duration,
- pub notifications_handler: crate::notifications::NotificationsHandler,
+ pub notifications_handler: crate::notifications::Handler,
}
impl State {
@@ -59,8 +58,7 @@ impl Agent {
if sync_timeout_duration > std::time::Duration::ZERO {
sync_timeout.set(sync_timeout_duration);
}
- let notifications_handler =
- crate::notifications::NotificationsHandler::new();
+ let notifications_handler = crate::notifications::Handler::new();
Ok(Self {
timer_r,
sync_timer_r,
@@ -80,19 +78,19 @@ impl Agent {
self,
listener: tokio::net::UnixListener,
) -> anyhow::Result<()> {
- let err =
- crate::actions::subscribe_to_notifications(self.state.clone())
- .await;
- if let Err(e) = err {
- eprintln!("failed to subscribe to notifications: {e:#}")
- }
-
enum Event {
Request(std::io::Result<tokio::net::UnixStream>),
Timeout(()),
Sync(()),
}
+ let err =
+ crate::actions::subscribe_to_notifications(self.state.clone())
+ .await;
+ if let Err(e) = err {
+ eprintln!("failed to subscribe to notifications: {e:#}");
+ }
+
let c: tokio::sync::mpsc::UnboundedReceiver<
notifications::NotificationMessage,
> = {
@@ -160,17 +158,19 @@ impl Agent {
let result = crate::actions::sync(None).await;
if let Err(e) = result {
eprintln!("failed to sync: {e:#}");
- } else {
- if !state
- .write()
- .await
- .notifications_handler
- .is_connected()
- {
- let err = crate::actions::subscribe_to_notifications(state).await;
- if let Err(e) = err {
- eprintln!("failed to subscribe to notifications: {e:#}")
- }
+ } else if !state
+ .write()
+ .await
+ .notifications_handler
+ .is_connected()
+ {
+ let err =
+ crate::actions::subscribe_to_notifications(
+ state,
+ )
+ .await;
+ if let Err(e) = err {
+ eprintln!("failed to subscribe to notifications: {e:#}");
}
}
});
diff --git a/src/bin/rbw-agent/notifications.rs b/src/bin/rbw-agent/notifications.rs
index e8f84b0..69ebda5 100644
--- a/src/bin/rbw-agent/notifications.rs
+++ b/src/bin/rbw-agent/notifications.rs
@@ -38,7 +38,7 @@ fn parse_messagepack(data: &[u8]) -> Option<NotificationMessage> {
let message_type =
unpacked_message.iter().next().unwrap().as_u64().unwrap();
- let message = match message_type {
+ match message_type {
0 => Some(NotificationMessage::SyncCipherUpdate),
1 => Some(NotificationMessage::SyncCipherCreate),
2 => Some(NotificationMessage::SyncLoginDelete),
@@ -52,12 +52,10 @@ fn parse_messagepack(data: &[u8]) -> Option<NotificationMessage> {
10 => Some(NotificationMessage::SyncSettings),
11 => Some(NotificationMessage::Logout),
_ => None,
- };
-
- return message;
+ }
}
-pub struct NotificationsHandler {
+pub struct Handler {
write: Option<
futures::stream::SplitSink<
tokio_tungstenite::WebSocketStream<
@@ -74,7 +72,7 @@ pub struct NotificationsHandler {
>,
}
-impl NotificationsHandler {
+impl Handler {
pub fn new() -> Self {
Self {
write: None,
@@ -99,7 +97,7 @@ impl NotificationsHandler {
self.write = Some(write);
self.read_handle = Some(read_handle);
- return Ok(());
+ Ok(())
}
pub fn is_connected(&self) -> bool {
@@ -128,7 +126,7 @@ impl NotificationsHandler {
let (tx, rx) =
tokio::sync::mpsc::unbounded_channel::<NotificationMessage>();
self.sending_channels.write().await.push(tx);
- return rx;
+ rx
}
}
@@ -167,7 +165,8 @@ async fn subscribe_to_notifications(
Ok(Message::Binary(binary)) => {
let msgpack = parse_messagepack(&binary);
if let Some(msg) = msgpack {
- for channel in a.iter() {
+ let channels = a.as_slice();
+ for channel in channels {
let res = channel.send(msg);
if res.is_err() {
eprintln!("error sending websocket message to channel");
@@ -176,12 +175,12 @@ async fn subscribe_to_notifications(
}
},
Err(e) => {
- eprintln!("websocket error: {:?}", e);
+ eprintln!("websocket error: {e:?}");
},
_ => {}
}
}).await;
};
- return Ok((write, tokio::spawn(read_future)));
+ Ok((write, tokio::spawn(read_future)))
}
diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs
index 252c5ec..af08657 100644
--- a/src/bin/rbw/commands.rs
+++ b/src/bin/rbw/commands.rs
@@ -35,10 +35,7 @@ impl DecryptedCipher {
eprintln!("entry for '{desc}' had no password");
false
},
- |password| {
- let res = val_display_or_store(clipboard, password);
- res
- },
+ |password| val_display_or_store(clipboard, password),
)
}
DecryptedData::Card { number, .. } => {
@@ -47,10 +44,7 @@ impl DecryptedCipher {
eprintln!("entry for '{desc}' had no card number");
false
},
- |number| {
- let res = val_display_or_store(clipboard, number);
- res
- },
+ |number| val_display_or_store(clipboard, number),
)
}
DecryptedData::Identity {
@@ -71,11 +65,7 @@ impl DecryptedCipher {
eprintln!("entry for '{desc}' had no name");
false
} else {
- let res = val_display_or_store(
- clipboard,
- &format!("{}", names.join(" ")),
- );
- res
+ val_display_or_store(clipboard, &names.join(" "))
}
}
DecryptedData::SecureNote {} => self.notes.as_ref().map_or_else(
@@ -83,10 +73,7 @@ impl DecryptedCipher {
eprintln!("entry for '{desc}' had no notes");
false
},
- |notes| {
- let res = val_display_or_store(clipboard, notes);
- res
- },
+ |notes| val_display_or_store(clipboard, notes),
),
}
}
@@ -573,10 +560,7 @@ impl DecryptedCipher {
}
}
-fn val_display_or_store(
- clipboard: bool,
- password: &str,
-) -> bool {
+fn val_display_or_store(clipboard: bool, password: &str) -> bool {
if clipboard {
match clipboard_store(password) {
Ok(_) => {
@@ -764,8 +748,9 @@ fn clipboard_store(val: &str) -> anyhow::Result<()> {
anyhow::anyhow!("Couldn't create clipboard context: {e}")
})?;
- ctx.set_contents(val.to_owned())
- .map_err(|e| anyhow::anyhow!("Couldn't store value to clipboard: {e}"))?;
+ ctx.set_contents(val.to_owned()).map_err(|e| {
+ anyhow::anyhow!("Couldn't store value to clipboard: {e}")
+ })?;
let _ = ctx.get_contents();
@@ -1996,9 +1981,6 @@ mod test {
fn display_field(name: &str, field: Option<&str>, clipboard: bool) -> bool {
field.map_or_else(
|| false,
- |field| {
- let res = val_display_or_store(clipboard, &format!("{name}: {field}"));
- res
- },
+ |field| val_display_or_store(clipboard, &format!("{name}: {field}")),
)
}
diff --git a/src/bin/rbw/main.rs b/src/bin/rbw/main.rs
index 3bede5b..72e4220 100644
--- a/src/bin/rbw/main.rs
+++ b/src/bin/rbw/main.rs
@@ -324,7 +324,7 @@ fn main() {
field,
full,
raw,
- clipboard
+ clipboard,
} => commands::get(
name,
user.as_deref(),