aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-04-12 01:40:46 -0400
committerJesse Luehrs <doy@tozt.net>2020-04-12 01:40:46 -0400
commite45e35125e623a8fb683a28f55ad96d42d01a1d0 (patch)
treeffdf2130cb2197bc3e0769b732dfb4fc933b4618
parent14b647f9d6dbb76960e6cad6f51531ea6a8dbf3a (diff)
downloadrbw-e45e35125e623a8fb683a28f55ad96d42d01a1d0.tar.gz
rbw-e45e35125e623a8fb683a28f55ad96d42d01a1d0.zip
rename some stuff to be less confusing
-rw-r--r--src/bin/rbw-agent/actions.rs4
-rw-r--r--src/bin/rbw-agent/agent.rs14
-rw-r--r--src/bin/rbw-agent/sock.rs4
-rw-r--r--src/bin/rbw/actions.rs28
-rw-r--r--src/bin/rbw/sock.rs7
-rw-r--r--src/lib.rs2
-rw-r--r--src/protocol.rs (renamed from src/agent.rs)0
7 files changed, 31 insertions, 28 deletions
diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs
index 0eec665..81e2597 100644
--- a/src/bin/rbw-agent/actions.rs
+++ b/src/bin/rbw-agent/actions.rs
@@ -179,7 +179,7 @@ pub async fn decrypt(
}
async fn respond_ack(sock: &mut crate::sock::Sock) -> anyhow::Result<()> {
- sock.send(&rbw::agent::Response::Ack)
+ sock.send(&rbw::protocol::Response::Ack)
.await
.context("failed to send response")?;
@@ -190,7 +190,7 @@ async fn respond_decrypt(
sock: &mut crate::sock::Sock,
plaintext: String,
) -> anyhow::Result<()> {
- sock.send(&rbw::agent::Response::Decrypt { plaintext })
+ sock.send(&rbw::protocol::Response::Decrypt { plaintext })
.await
.context("failed to send response")?;
diff --git a/src/bin/rbw-agent/agent.rs b/src/bin/rbw-agent/agent.rs
index f092787..46af63c 100644
--- a/src/bin/rbw-agent/agent.rs
+++ b/src/bin/rbw-agent/agent.rs
@@ -51,7 +51,7 @@ impl Agent {
= handle_request(&mut sock, state.clone()).await;
if let Err(e) = res {
// unwrap is the only option here
- sock.send(&rbw::agent::Response::Error {
+ sock.send(&rbw::protocol::Response::Error {
error: format!("{:#}", e),
}).await.unwrap();
}
@@ -77,21 +77,21 @@ async fn handle_request(
.await
.context("failed to receive incoming message")?;
match &req.action {
- rbw::agent::Action::Login => {
+ rbw::protocol::Action::Login => {
crate::actions::login(sock, state.clone(), req.tty.as_deref())
.await
}
- rbw::agent::Action::Unlock => {
+ rbw::protocol::Action::Unlock => {
crate::actions::unlock(sock, state.clone(), req.tty.as_deref())
.await
}
- rbw::agent::Action::Lock => {
+ rbw::protocol::Action::Lock => {
crate::actions::lock(sock, state.clone()).await
}
- rbw::agent::Action::Sync => crate::actions::sync(sock).await,
- rbw::agent::Action::Decrypt { cipherstring } => {
+ rbw::protocol::Action::Sync => crate::actions::sync(sock).await,
+ rbw::protocol::Action::Decrypt { cipherstring } => {
crate::actions::decrypt(sock, state.clone(), &cipherstring).await
}
- rbw::agent::Action::Quit => std::process::exit(0),
+ rbw::protocol::Action::Quit => std::process::exit(0),
}
}
diff --git a/src/bin/rbw-agent/sock.rs b/src/bin/rbw-agent/sock.rs
index 6931b13..688f87a 100644
--- a/src/bin/rbw-agent/sock.rs
+++ b/src/bin/rbw-agent/sock.rs
@@ -10,7 +10,7 @@ impl Sock {
pub async fn send(
&mut self,
- res: &rbw::agent::Response,
+ res: &rbw::protocol::Response,
) -> anyhow::Result<()> {
let Self(sock) = self;
sock.write_all(
@@ -26,7 +26,7 @@ impl Sock {
Ok(())
}
- pub async fn recv(&mut self) -> anyhow::Result<rbw::agent::Request> {
+ pub async fn recv(&mut self) -> anyhow::Result<rbw::protocol::Request> {
let Self(sock) = self;
let mut buf = tokio::io::BufStream::new(sock);
let mut line = String::new();
diff --git a/src/bin/rbw/actions.rs b/src/bin/rbw/actions.rs
index 87ecbc8..5951185 100644
--- a/src/bin/rbw/actions.rs
+++ b/src/bin/rbw/actions.rs
@@ -1,27 +1,27 @@
use anyhow::Context as _;
pub fn login() -> anyhow::Result<()> {
- simple_action(rbw::agent::Action::Login, "login")
+ simple_action(rbw::protocol::Action::Login, "login")
}
pub fn unlock() -> anyhow::Result<()> {
- simple_action(rbw::agent::Action::Unlock, "unlock")
+ simple_action(rbw::protocol::Action::Unlock, "unlock")
}
pub fn sync() -> anyhow::Result<()> {
- simple_action(rbw::agent::Action::Sync, "sync")
+ simple_action(rbw::protocol::Action::Sync, "sync")
}
pub fn lock() -> anyhow::Result<()> {
- simple_action(rbw::agent::Action::Lock, "lock")
+ simple_action(rbw::protocol::Action::Lock, "lock")
}
pub fn quit() -> anyhow::Result<()> {
match crate::sock::Sock::connect() {
Ok(mut sock) => {
- sock.send(&rbw::agent::Request {
+ sock.send(&rbw::protocol::Request {
tty: std::env::var("TTY").ok(),
- action: rbw::agent::Action::Quit,
+ action: rbw::protocol::Action::Quit,
})?;
Ok(())
}
@@ -38,17 +38,17 @@ pub fn quit() -> anyhow::Result<()> {
pub fn decrypt(cipherstring: &str) -> anyhow::Result<String> {
let mut sock = crate::sock::Sock::connect()
.context("failed to connect to rbw-agent")?;
- sock.send(&rbw::agent::Request {
+ sock.send(&rbw::protocol::Request {
tty: std::env::var("TTY").ok(),
- action: rbw::agent::Action::Decrypt {
+ action: rbw::protocol::Action::Decrypt {
cipherstring: cipherstring.to_string(),
},
})?;
let res = sock.recv()?;
match res {
- rbw::agent::Response::Decrypt { plaintext } => Ok(plaintext),
- rbw::agent::Response::Error { error } => {
+ rbw::protocol::Response::Decrypt { plaintext } => Ok(plaintext),
+ rbw::protocol::Response::Error { error } => {
Err(anyhow::anyhow!("failed to decrypt: {}", error))
}
_ => Err(anyhow::anyhow!("unexpected message: {:?}", res)),
@@ -56,21 +56,21 @@ pub fn decrypt(cipherstring: &str) -> anyhow::Result<String> {
}
fn simple_action(
- action: rbw::agent::Action,
+ action: rbw::protocol::Action,
desc: &str,
) -> anyhow::Result<()> {
let mut sock = crate::sock::Sock::connect()
.context("failed to connect to rbw-agent")?;
- sock.send(&rbw::agent::Request {
+ sock.send(&rbw::protocol::Request {
tty: std::env::var("TTY").ok(),
action,
})?;
let res = sock.recv()?;
match res {
- rbw::agent::Response::Ack => Ok(()),
- rbw::agent::Response::Error { error } => {
+ rbw::protocol::Response::Ack => Ok(()),
+ rbw::protocol::Response::Error { error } => {
Err(anyhow::anyhow!("failed to {}: {}", desc, error))
}
_ => Err(anyhow::anyhow!("unexpected message: {:?}", res)),
diff --git a/src/bin/rbw/sock.rs b/src/bin/rbw/sock.rs
index 8dca169..1ba13ec 100644
--- a/src/bin/rbw/sock.rs
+++ b/src/bin/rbw/sock.rs
@@ -10,7 +10,10 @@ impl Sock {
)?))
}
- pub fn send(&mut self, msg: &rbw::agent::Request) -> anyhow::Result<()> {
+ pub fn send(
+ &mut self,
+ msg: &rbw::protocol::Request,
+ ) -> anyhow::Result<()> {
let Self(sock) = self;
sock.write_all(
serde_json::to_string(msg)
@@ -23,7 +26,7 @@ impl Sock {
Ok(())
}
- pub fn recv(&mut self) -> anyhow::Result<rbw::agent::Response> {
+ pub fn recv(&mut self) -> anyhow::Result<rbw::protocol::Response> {
let Self(sock) = self;
let mut buf = std::io::BufReader::new(sock);
let mut line = String::new();
diff --git a/src/lib.rs b/src/lib.rs
index e5d887a..f1460c5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,7 +6,6 @@
#![allow(clippy::similar_names)]
pub mod actions;
-pub mod agent;
pub mod api;
pub mod cipherstring;
pub mod config;
@@ -17,4 +16,5 @@ pub mod identity;
pub mod locked;
pub mod pinentry;
mod prelude;
+pub mod protocol;
pub mod pwgen;
diff --git a/src/agent.rs b/src/protocol.rs
index 8d7cd69..8d7cd69 100644
--- a/src/agent.rs
+++ b/src/protocol.rs