aboutsummaryrefslogtreecommitdiffstats
path: root/src/pinentry.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/pinentry.rs')
-rw-r--r--src/pinentry.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/pinentry.rs b/src/pinentry.rs
index ce1227f..e2a83ed 100644
--- a/src/pinentry.rs
+++ b/src/pinentry.rs
@@ -34,18 +34,18 @@ pub async fn getpin(
.map_err(|source| Error::WriteStdin { source })?;
ncommands += 1;
stdin
- .write_all(format!("SETPROMPT {}\n", prompt).as_bytes())
+ .write_all(format!("SETPROMPT {prompt}\n").as_bytes())
.await
.map_err(|source| Error::WriteStdin { source })?;
ncommands += 1;
stdin
- .write_all(format!("SETDESC {}\n", desc).as_bytes())
+ .write_all(format!("SETDESC {desc}\n").as_bytes())
.await
.map_err(|source| Error::WriteStdin { source })?;
ncommands += 1;
if let Some(err) = err {
stdin
- .write_all(format!("SETERROR {}\n", err).as_bytes())
+ .write_all(format!("SETERROR {err}\n").as_bytes())
.await
.map_err(|source| Error::WriteStdin { source })?;
ncommands += 1;
@@ -77,15 +77,13 @@ pub async fn getpin(
Ok(crate::locked::Password::new(buf))
}
-async fn read_password<
- R: tokio::io::AsyncRead + tokio::io::AsyncReadExt + Unpin,
->(
+async fn read_password<R>(
mut ncommands: u8,
data: &mut [u8],
mut r: R,
) -> Result<usize>
where
- R: Send,
+ R: tokio::io::AsyncRead + tokio::io::AsyncReadExt + Unpin + Send,
{
let mut len = 0;
loop {
@@ -120,7 +118,7 @@ where
});
}
return Err(Error::PinentryErrorMessage {
- error: format!("unknown error ({})", code),
+ error: format!("unknown error ({code})"),
});
}
None => {
@@ -139,6 +137,14 @@ where
.read(&mut data[len..])
.await
.map_err(|source| Error::PinentryReadOutput { source })?;
+ if bytes == 0 {
+ return Err(Error::PinentryReadOutput {
+ source: std::io::Error::new(
+ std::io::ErrorKind::UnexpectedEof,
+ "unexpected EOF",
+ ),
+ });
+ }
len += bytes;
}
}
@@ -162,7 +168,6 @@ fn percent_decode(buf: &mut [u8]) -> usize {
if c == b'%' && read_idx + 2 < len {
if let Some(h) = char::from(buf[read_idx + 1]).to_digit(16) {
- #[allow(clippy::cast_possible_truncation)]
if let Some(l) = char::from(buf[read_idx + 2]).to_digit(16) {
// h and l were parsed from a single hex digit, so they
// must be in the range 0-15, so these unwraps are safe