aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/rbw/actions.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-04-18 01:28:48 -0400
committerJesse Luehrs <doy@tozt.net>2020-04-18 01:28:48 -0400
commit777b810db4675305854c373dcd57aedc40061e5d (patch)
treeed35c77e39416073fb5222aebdb5ef484c238dd3 /src/bin/rbw/actions.rs
parent3babc8801c0d09b7868be9be7751f7cfdf32c8bb (diff)
downloadrbw-777b810db4675305854c373dcd57aedc40061e5d.tar.gz
rbw-777b810db4675305854c373dcd57aedc40061e5d.zip
add encryption to the agent protocol
Diffstat (limited to 'src/bin/rbw/actions.rs')
-rw-r--r--src/bin/rbw/actions.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/bin/rbw/actions.rs b/src/bin/rbw/actions.rs
index 5951185..b3a9f1b 100644
--- a/src/bin/rbw/actions.rs
+++ b/src/bin/rbw/actions.rs
@@ -55,6 +55,26 @@ pub fn decrypt(cipherstring: &str) -> anyhow::Result<String> {
}
}
+pub fn encrypt(plaintext: &str) -> anyhow::Result<String> {
+ let mut sock = crate::sock::Sock::connect()
+ .context("failed to connect to rbw-agent")?;
+ sock.send(&rbw::protocol::Request {
+ tty: std::env::var("TTY").ok(),
+ action: rbw::protocol::Action::Encrypt {
+ plaintext: plaintext.to_string(),
+ },
+ })?;
+
+ let res = sock.recv()?;
+ match res {
+ rbw::protocol::Response::Encrypt { cipherstring } => Ok(cipherstring),
+ rbw::protocol::Response::Error { error } => {
+ Err(anyhow::anyhow!("failed to encrypt: {}", error))
+ }
+ _ => Err(anyhow::anyhow!("unexpected message: {:?}", res)),
+ }
+}
+
fn simple_action(
action: rbw::protocol::Action,
desc: &str,