From c67ecea7e22b890a3014a884585d801a2fcc3293 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 11 Dec 2018 12:09:21 +0100 Subject: Show error in pinentry dialog instead of printing to stdout Currently, the error message for a wrong password is printed to the standard output. Yet the standard output might not be visible to the user if they are using the curses frontend for pinentry. Pinentry already supports displaying an error message in the passphrase prompt. This patch moves the error message from the standard output to the pinentry prompt. --- nitrocli/src/pinentry.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'nitrocli/src/pinentry.rs') diff --git a/nitrocli/src/pinentry.rs b/nitrocli/src/pinentry.rs index 028550f..6cf3093 100644 --- a/nitrocli/src/pinentry.rs +++ b/nitrocli/src/pinentry.rs @@ -49,12 +49,14 @@ fn parse_pinentry_passphrase(response: Vec) -> Result, Error> { } -pub fn inquire_passphrase() -> Result, Error> { - const PINENTRY_ERROR_MSG: &str = "+"; +pub fn inquire_passphrase(error_msg: Option<&str>) -> Result, Error> { + const PINENTRY_ERROR_MSG_EMPTY: &str = "+"; const PINENTRY_PROMPT: &str = "PIN"; const PINENTRY_DESCR: &str = "Please+enter+user+PIN"; - let args = vec![CACHE_ID, PINENTRY_ERROR_MSG, PINENTRY_PROMPT, PINENTRY_DESCR].join(" "); + let error_msg = error_msg.map(|msg| msg.replace(" ", "+")) + .unwrap_or(PINENTRY_ERROR_MSG_EMPTY.to_string()); + let args = vec![CACHE_ID, &error_msg, PINENTRY_PROMPT, PINENTRY_DESCR].join(" "); let command = "GET_PASSPHRASE --data ".to_string() + &args; // We could also use the --data parameter here to have a more direct // representation of the passphrase but the resulting response was -- cgit v1.2.1