From 777b810db4675305854c373dcd57aedc40061e5d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 18 Apr 2020 01:28:48 -0400 Subject: add encryption to the agent protocol --- src/bin/rbw/actions.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/bin/rbw/actions.rs') 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 { } } +pub fn encrypt(plaintext: &str) -> anyhow::Result { + 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, -- cgit v1.2.3-54-g00ecf