diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-04-18 18:04:14 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-04-18 18:04:14 -0400 |
commit | 766057750f35671fce5b6b1b98542dd60bcf8a48 (patch) | |
tree | cfc6be976e467fc40f1f5a13d3c0c7cf8cddc602 /src/pinentry.rs | |
parent | 6c9fa62a291121ad7d9a1278db8a761cdddd4291 (diff) | |
download | rbw-766057750f35671fce5b6b1b98542dd60bcf8a48.tar.gz rbw-766057750f35671fce5b6b1b98542dd60bcf8a48.zip |
handle pinentry ERR lines
Diffstat (limited to 'src/pinentry.rs')
-rw-r--r-- | src/pinentry.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/pinentry.rs b/src/pinentry.rs index a8d607b..c0a929b 100644 --- a/src/pinentry.rs +++ b/src/pinentry.rs @@ -69,6 +69,33 @@ async fn read_password< data.copy_within(2..nl, 0); len = nl - 2; break; + } else if data.starts_with(b"ERR ") { + let line: Vec<u8> = data.iter().take(nl).copied().collect(); + let line = String::from_utf8(line).unwrap(); + let mut split = line.splitn(3, ' '); + let _ = split.next(); // ERR + let code = split.next(); + match code { + Some("83886179") => { + return Err(Error::PinentryCancelled); + } + Some(code) => { + if let Some(error) = split.next() { + return Err(Error::PinentryErrorMessage { + error: error.to_string(), + }); + } else { + return Err(Error::PinentryErrorMessage { + error: format!("unknown error ({})", code), + }); + } + } + None => { + return Err(Error::PinentryErrorMessage { + error: "unknown error".to_string(), + }); + } + } } else { return Err(Error::FailedToParsePinentry { out: String::from_utf8_lossy(data).to_string(), |