keyfork-shard: add prompt for loading any smartcard
This commit is contained in:
parent
4384964ea5
commit
1b33e3cf0e
|
@ -24,7 +24,7 @@ pub enum Error {
|
||||||
#[error("Smart card could not decrypt any matching PKESK packets")]
|
#[error("Smart card could not decrypt any matching PKESK packets")]
|
||||||
SmartCardCouldNotDecrypt,
|
SmartCardCouldNotDecrypt,
|
||||||
|
|
||||||
#[error("No smart card backend was stored")]
|
#[error("No smart card was found")]
|
||||||
SmartCardNotFound,
|
SmartCardNotFound,
|
||||||
|
|
||||||
#[error("Selected smart card has no decryption key")]
|
#[error("Selected smart card has no decryption key")]
|
||||||
|
@ -92,12 +92,18 @@ impl SmartcardManager {
|
||||||
|
|
||||||
/// Load any backend.
|
/// Load any backend.
|
||||||
pub fn load_any_card(&mut self) -> Result<Fingerprint> {
|
pub fn load_any_card(&mut self) -> Result<Fingerprint> {
|
||||||
PcscBackend::cards(None)?
|
let card_backend = loop {
|
||||||
.next()
|
self.pm.prompt_message(&Message::Text(
|
||||||
.transpose()?
|
"Please plug in a smart card and press enter".to_string(),
|
||||||
.ok_or(Error::SmartCardNotFound)
|
))?;
|
||||||
.and_then(|backend| {
|
if let Some(c) = PcscBackend::cards(None)?.next().transpose()? {
|
||||||
let mut card = Card::<Open>::new(backend).map_err(Error::OpenSmartCard)?;
|
break c;
|
||||||
|
}
|
||||||
|
self.pm.prompt_message(&Message::Text(
|
||||||
|
"No smart card was found".to_string(),
|
||||||
|
))?;
|
||||||
|
};
|
||||||
|
let mut card = Card::<Open>::new(card_backend).map_err(Error::OpenSmartCard)?;
|
||||||
let transaction = card.transaction().map_err(Error::Transaction)?;
|
let transaction = card.transaction().map_err(Error::Transaction)?;
|
||||||
let fingerprint = transaction
|
let fingerprint = transaction
|
||||||
.fingerprints()
|
.fingerprints()
|
||||||
|
@ -108,7 +114,6 @@ impl SmartcardManager {
|
||||||
drop(transaction);
|
drop(transaction);
|
||||||
self.current_card.replace(card);
|
self.current_card.replace(card);
|
||||||
Ok(fingerprint)
|
Ok(fingerprint)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load a backend if any [`Fingerprint`] has been matched by a currently active card.
|
/// Load a backend if any [`Fingerprint`] has been matched by a currently active card.
|
||||||
|
@ -150,8 +155,9 @@ impl SmartcardManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
self.pm.prompt_message(&Message::Text(
|
||||||
self.pm.prompt_message(&Message::Text("Please plug in a smart card and press enter".to_string()))?;
|
"Please plug in a smart card and press enter".to_string(),
|
||||||
|
))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|
Loading…
Reference in New Issue