aboutsummaryrefslogtreecommitdiffstats
path: root/src/pinentry.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-06 13:18:29 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-06 13:18:29 -0500
commit9e77724efff281f0fe6d05440ad65c5ab561f380 (patch)
treeee5983d46b9f040a9c9880df9eb02b8d36956628 /src/pinentry.rs
parentabc01f5a3865da5bd962402a8f7d9fd95c149622 (diff)
downloadrbw-9e77724efff281f0fe6d05440ad65c5ab561f380.tar.gz
rbw-9e77724efff281f0fe6d05440ad65c5ab561f380.zip
switch to thiserror
Diffstat (limited to 'src/pinentry.rs')
-rw-r--r--src/pinentry.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/pinentry.rs b/src/pinentry.rs
index 683a880..b055b77 100644
--- a/src/pinentry.rs
+++ b/src/pinentry.rs
@@ -17,7 +17,7 @@ pub async fn getpin(
} else {
opts.args(&["-o", "0"]);
}
- let mut child = opts.spawn().context(crate::error::Spawn)?;
+ let mut child = opts.spawn().map_err(|source| Error::Spawn { source })?;
// unwrap is safe because we specified stdin as piped in the command opts
// above
let mut stdin = child.stdin.take().unwrap();
@@ -26,29 +26,29 @@ pub async fn getpin(
stdin
.write_all(b"SETTITLE rbw\n")
.await
- .context(crate::error::WriteStdin)?;
+ .map_err(|source| Error::WriteStdin { source })?;
ncommands += 1;
stdin
.write_all(format!("SETPROMPT {}\n", prompt).as_bytes())
.await
- .context(crate::error::WriteStdin)?;
+ .map_err(|source| Error::WriteStdin { source })?;
ncommands += 1;
stdin
.write_all(format!("SETDESC {}\n", desc).as_bytes())
.await
- .context(crate::error::WriteStdin)?;
+ .map_err(|source| Error::WriteStdin { source })?;
ncommands += 1;
if let Some(err) = err {
stdin
.write_all(format!("SETERROR {}\n", err).as_bytes())
.await
- .context(crate::error::WriteStdin)?;
+ .map_err(|source| Error::WriteStdin { source })?;
ncommands += 1;
}
stdin
.write_all(b"GETPIN\n")
.await
- .context(crate::error::WriteStdin)?;
+ .map_err(|source| Error::WriteStdin { source })?;
ncommands += 1;
drop(stdin);
@@ -64,7 +64,10 @@ pub async fn getpin(
.await?;
buf.truncate(len);
- child.wait().await.context(crate::error::PinentryWait)?;
+ child
+ .wait()
+ .await
+ .map_err(|source| Error::PinentryWait { source })?;
Ok(crate::locked::Password::new(buf))
}
@@ -130,7 +133,7 @@ where
let bytes = r
.read(&mut data[len..])
.await
- .context(crate::error::PinentryReadOutput)?;
+ .map_err(|source| Error::PinentryReadOutput { source })?;
len += bytes;
}
}