aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/commands.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/commands.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/commands.rs')
-rw-r--r--nitrocli/src/commands.rs6
1 files changed, 0 insertions, 6 deletions
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs
index 1d5c67c..e719039 100644
--- a/nitrocli/src/commands.rs
+++ b/nitrocli/src/commands.rs
@@ -186,10 +186,6 @@ where
Ok(pin) => pin,
Err(err) => return Err((data, err)),
};
- let pin = match String::from_utf8(pin) {
- Ok(pin) => pin,
- Err(err) => return Err((data, Error::from(err))),
- };
match op(data, &pin) {
Ok(result) => return Ok(result),
Err((new_data, err)) => match err {
@@ -580,12 +576,10 @@ fn choose_pin(pin_type: pinentry::PinType) -> Result<String> {
pinentry::clear_pin(pin_type)?;
let new_pin = pinentry::inquire_pin(pin_type, pinentry::Mode::Choose, None)?;
pinentry::clear_pin(pin_type)?;
- let new_pin = String::from_utf8(new_pin)?;
check_pin(pin_type, &new_pin)?;
let confirm_pin = pinentry::inquire_pin(pin_type, pinentry::Mode::Confirm, None)?;
pinentry::clear_pin(pin_type)?;
- let confirm_pin = String::from_utf8(confirm_pin)?;
if new_pin != confirm_pin {
Err(Error::Error("Entered PINs do not match".to_string()))