From ac7025cbe1bc46d25dd978138c6b397d77853232 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Wed, 9 Jan 2019 16:34:53 -0800 Subject: 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. --- nitrocli/src/error.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'nitrocli/src/error.rs') 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 for Error { } } +impl From for Error { + fn from(e: str::Utf8Error) -> Error { + Error::Utf8Error(e) + } +} + impl From for Error { fn from(e: string::FromUtf8Error) -> Error { - Error::Utf8Error(e) + Error::Utf8Error(e.utf8_error()) } } -- cgit v1.2.1