From 766057750f35671fce5b6b1b98542dd60bcf8a48 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 18 Apr 2020 18:04:14 -0400 Subject: handle pinentry ERR lines --- src/pinentry.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/pinentry.rs') 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 = 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(), -- cgit v1.2.3-54-g00ecf