diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-04-12 01:40:46 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-04-12 01:40:46 -0400 |
commit | e45e35125e623a8fb683a28f55ad96d42d01a1d0 (patch) | |
tree | ffdf2130cb2197bc3e0769b732dfb4fc933b4618 /src/bin/rbw | |
parent | 14b647f9d6dbb76960e6cad6f51531ea6a8dbf3a (diff) | |
download | rbw-e45e35125e623a8fb683a28f55ad96d42d01a1d0.tar.gz rbw-e45e35125e623a8fb683a28f55ad96d42d01a1d0.zip |
rename some stuff to be less confusing
Diffstat (limited to 'src/bin/rbw')
-rw-r--r-- | src/bin/rbw/actions.rs | 28 | ||||
-rw-r--r-- | src/bin/rbw/sock.rs | 7 |
2 files changed, 19 insertions, 16 deletions
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(); |