diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-05-02 18:45:50 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-05-02 18:59:11 -0400 |
commit | f035ac5470c7fbcf791e361cb2d611de7edafb0f (patch) | |
tree | 8d75832af542bb27ca32163fbadc67758dde50cb /src/bin/rbw/actions.rs | |
parent | bcf1df8dd65fb24c767ca91159fc5639dbd5375f (diff) | |
download | rbw-f035ac5470c7fbcf791e361cb2d611de7edafb0f.tar.gz rbw-f035ac5470c7fbcf791e361cb2d611de7edafb0f.zip |
check protocol version before agent communication
Diffstat (limited to 'src/bin/rbw/actions.rs')
-rw-r--r-- | src/bin/rbw/actions.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/bin/rbw/actions.rs b/src/bin/rbw/actions.rs index 273b038..399b7f3 100644 --- a/src/bin/rbw/actions.rs +++ b/src/bin/rbw/actions.rs @@ -82,6 +82,24 @@ pub fn encrypt(plaintext: &str) -> anyhow::Result<String> { } } +pub fn version() -> anyhow::Result<u32> { + 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::Version, + })?; + + let res = sock.recv()?; + match res { + rbw::protocol::Response::Version { version } => Ok(version), + rbw::protocol::Response::Error { error } => { + Err(anyhow::anyhow!("failed to get version: {}", error)) + } + _ => Err(anyhow::anyhow!("unexpected message: {:?}", res)), + } +} + fn simple_action( action: rbw::protocol::Action, desc: &str, |