From d83efcbbd0251b3566bb2f49e0177f0e27c4834f Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 11 Jan 2024 22:53:32 -0500 Subject: [PATCH] keyfork-shard: only print one message per key-load attempt --- keyfork-shard/src/openpgp/smartcard.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/keyfork-shard/src/openpgp/smartcard.rs b/keyfork-shard/src/openpgp/smartcard.rs index 04d6f91..4794db3 100644 --- a/keyfork-shard/src/openpgp/smartcard.rs +++ b/keyfork-shard/src/openpgp/smartcard.rs @@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet}; use keyfork_prompt::{ default_terminal, validators::{PinValidator, Validator}, - DefaultTerminal, Error as PromptError, Message, PromptHandler + DefaultTerminal, Error as PromptError, Message, PromptHandler, }; use super::openpgp::{ @@ -93,14 +93,12 @@ impl SmartcardManager { /// Load any backend. pub fn load_any_card(&mut self) -> Result { let card_backend = loop { - self.pm.prompt_message(Message::Text( - "Please plug in a smart card and press enter".to_string(), - ))?; if let Some(c) = PcscBackend::cards(None)?.next().transpose()? { break c; } - self.pm - .prompt_message(Message::Text("No smart card was found".to_string()))?; + self.pm.prompt_message(Message::Text( + "No smart card was found. Please plug in a smart card and press enter".to_string(), + ))?; }; let mut card = Card::::new(card_backend).map_err(Error::OpenSmartCard)?; let transaction = card.transaction().map_err(Error::Transaction)?; @@ -266,9 +264,8 @@ impl DecryptionHelper for &mut SmartcardManager { } // NOTE: This should not be hit, because of the above validator. Err(CardError::CardStatus(StatusBytes::IncorrectParametersCommandDataField)) => { - self.pm.prompt_message(Message::Text( - "Invalid PIN length entered.".to_string(), - ))?; + self.pm + .prompt_message(Message::Text("Invalid PIN length entered.".to_string()))?; } Err(_) => {} }