keyfork-shard: only print one message per key-load attempt

This commit is contained in:
Ryan Heywood 2024-01-11 22:53:32 -05:00
parent 3ef6c96a7e
commit d83efcbbd0
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 6 additions and 9 deletions

View File

@ -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<Fingerprint> {
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::<Open>::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(_) => {}
}