aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/pinentry.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2018-12-17 18:31:42 -0800
committerDaniel Mueller <deso@posteo.net>2018-12-17 18:31:42 -0800
commit97accf1ddd79bb69dfb74742a0518c40830657e4 (patch)
tree2e808cd031e70084f2ae7bce704bd7cab4956b5c /nitrocli/src/pinentry.rs
parent953717e1648359baa8196ae32e01313b82f2561e (diff)
downloadnitrocli-97accf1ddd79bb69dfb74742a0518c40830657e4.tar.gz
nitrocli-97accf1ddd79bb69dfb74742a0518c40830657e4.tar.bz2
Make code conforming to rustfmt's expectations
An automated code formatter can help tremendously in reducing the amount of cognitive energy wasted on thinking about the "best" formatting of code as well as the number of nitpicks reviews typically get -- the format is machine checked (and enforced) and there is usually little to no discussion about the validity. To reach the goal of having such automated enforcement, we want to run the rustfmt tool as part of the CI pipeline. With rustfmt having reached 1.0 recently, the believe is that by now the formatting is reasonably stable and usable for this purpose. In that light, this change formats the code using rustfmt and prepares for such an automated style check.
Diffstat (limited to 'nitrocli/src/pinentry.rs')
-rw-r--r--nitrocli/src/pinentry.rs17
1 files changed, 7 insertions, 10 deletions
diff --git a/nitrocli/src/pinentry.rs b/nitrocli/src/pinentry.rs
index 66ca6be..fc7af2c 100644
--- a/nitrocli/src/pinentry.rs
+++ b/nitrocli/src/pinentry.rs
@@ -21,7 +21,6 @@ use std::process;
use crate::error::Error;
-
/// PIN type requested from pinentry.
///
/// The available PIN types correspond to the PIN types used by the Nitrokey devices: user and
@@ -35,7 +34,6 @@ pub enum PinType {
User,
}
-
impl PinType {
fn cache_id(self) -> &'static str {
match self {
@@ -59,7 +57,6 @@ impl PinType {
}
}
-
fn parse_pinentry_passphrase(response: Vec<u8>) -> Result<Vec<u8>, Error> {
let string = String::from_utf8(response)?;
let lines: Vec<&str> = string.lines().collect();
@@ -84,14 +81,15 @@ fn parse_pinentry_passphrase(response: Vec<u8>) -> Result<Vec<u8>, Error> {
Err(Error::Error("Unexpected response: ".to_string() + &string))
}
-
/// Inquire a PIN of the given type from the user.
///
/// This function inquires a PIN of the given type from the user or returns the cached passphrase,
/// if available. If an error message is set, it is displayed in the passphrase dialog.
pub fn inquire_passphrase(pin_type: PinType, error_msg: Option<&str>) -> Result<Vec<u8>, Error> {
let cache_id = pin_type.cache_id();
- let error_msg = error_msg.map(|msg| msg.replace(" ", "+")).unwrap_or_else(|| String::from("+"));
+ let error_msg = error_msg
+ .map(|msg| msg.replace(" ", "+"))
+ .unwrap_or_else(|| String::from("+"));
let prompt = pin_type.prompt();
let description = pin_type.description().replace(" ", "+");
@@ -103,13 +101,13 @@ pub fn inquire_passphrase(pin_type: PinType, error_msg: Option<&str>) -> Result<
// reported for the GET_PASSPHRASE command does not actually cause
// gpg-connect-agent to exit with a non-zero error code, we have to
// evaluate the output to determine success/failure.
- let output = process::Command::new("gpg-connect-agent").arg(command)
+ let output = process::Command::new("gpg-connect-agent")
+ .arg(command)
.arg("/bye")
.output()?;
parse_pinentry_passphrase(output.stdout)
}
-
fn parse_pinentry_response(response: Vec<u8>) -> Result<(), Error> {
let string = String::from_utf8(response)?;
let lines: Vec<&str> = string.lines().collect();
@@ -121,18 +119,17 @@ fn parse_pinentry_response(response: Vec<u8>) -> Result<(), Error> {
Err(Error::Error("Unexpected response: ".to_string() + &string))
}
-
/// Clear the cached passphrase of the given type.
pub fn clear_passphrase(pin_type: PinType) -> Result<(), Error> {
let command = "CLEAR_PASSPHRASE ".to_string() + pin_type.cache_id();
- let output = process::Command::new("gpg-connect-agent").arg(command)
+ let output = process::Command::new("gpg-connect-agent")
+ .arg(command)
.arg("/bye")
.output()?;
parse_pinentry_response(output.stdout)
}
-
#[cfg(test)]
mod tests {
use super::*;