aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/error.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-01-09 16:34:53 -0800
committerDaniel Mueller <deso@posteo.net>2019-01-09 16:34:53 -0800
commitac7025cbe1bc46d25dd978138c6b397d77853232 (patch)
treecf4724fd70de53cfe732901ba36545d0bf8d5103 /nitrocli/src/error.rs
parent4e83e8f9a79bcd26435b66d9faed72ff98a45555 (diff)
downloadnitrocli-ac7025cbe1bc46d25dd978138c6b397d77853232.tar.gz
nitrocli-ac7025cbe1bc46d25dd978138c6b397d77853232.tar.bz2
Make pinentry::inquire_pin return String directly
The inquire_pin function of the pinentry module used to return a vector of bytes, as that is what is ultimately read from the gpg-agent process. All clients of this function, however, work with a string and, hence, convert this vector into a string. As it turns out, for better or worse, the pinentry::parse_pinentry_pin function (which produces the result of inquire_pin) internally already works with a string but then converts it back. That is both not useful and a waste of resources. This change adjusts both functions of interest to simply return a String object instead, removing the need for conversions at the clients. While at it, the patch also removes the need for a bunch of unnecessary allocations caused by sub-par parameter type choice.
Diffstat (limited to 'nitrocli/src/error.rs')
-rw-r--r--nitrocli/src/error.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/nitrocli/src/error.rs b/nitrocli/src/error.rs
index c2a16a2..ffcc56b 100644
--- a/nitrocli/src/error.rs
+++ b/nitrocli/src/error.rs
@@ -19,6 +19,7 @@
use std::fmt;
use std::io;
+use std::str;
use std::string;
#[derive(Debug)]
@@ -26,7 +27,7 @@ pub enum Error {
ArgparseError(i32),
CommandError(nitrokey::CommandError),
IoError(io::Error),
- Utf8Error(string::FromUtf8Error),
+ Utf8Error(str::Utf8Error),
Error(String),
}
@@ -42,9 +43,15 @@ impl From<io::Error> for Error {
}
}
+impl From<str::Utf8Error> for Error {
+ fn from(e: str::Utf8Error) -> Error {
+ Error::Utf8Error(e)
+ }
+}
+
impl From<string::FromUtf8Error> for Error {
fn from(e: string::FromUtf8Error) -> Error {
- Error::Utf8Error(e)
+ Error::Utf8Error(e.utf8_error())
}
}