aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-04-18 18:04:14 -0400
committerJesse Luehrs <doy@tozt.net>2020-04-18 18:04:14 -0400
commit766057750f35671fce5b6b1b98542dd60bcf8a48 (patch)
treecfc6be976e467fc40f1f5a13d3c0c7cf8cddc602 /src
parent6c9fa62a291121ad7d9a1278db8a761cdddd4291 (diff)
downloadrbw-766057750f35671fce5b6b1b98542dd60bcf8a48.tar.gz
rbw-766057750f35671fce5b6b1b98542dd60bcf8a48.zip
handle pinentry ERR lines
Diffstat (limited to 'src')
-rw-r--r--src/error.rs6
-rw-r--r--src/pinentry.rs27
2 files changed, 33 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index 8c253c9..806d85c 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -70,6 +70,12 @@ pub enum Error {
#[snafu(display("failed to load db: {}", source))]
LoadDbJson { source: serde_json::Error },
+ #[snafu(display("pinentry cancelled"))]
+ PinentryCancelled,
+
+ #[snafu(display("pinentry error: {}", error))]
+ PinentryErrorMessage { error: String },
+
#[snafu(display("error reading pinentry output: {}", source))]
PinentryReadOutput { source: tokio::io::Error },
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(),