card-backend: Add CardTransaction::was_reset()
This can signal to consumers that state on the card may have been reset (e.g. PIN verification state)
This commit is contained in:
parent
84ee2a64f1
commit
f4cc72c37b
4 changed files with 27 additions and 1 deletions
|
@ -65,6 +65,11 @@ pub trait CardTransaction {
|
|||
pin: PinType,
|
||||
card_caps: &Option<CardCaps>,
|
||||
) -> Result<Vec<u8>, SmartcardError>;
|
||||
|
||||
/// Has a reset been detected while starting this transaction?
|
||||
///
|
||||
/// (Backends may choose to always return false)
|
||||
fn was_reset(&self) -> bool;
|
||||
}
|
||||
|
||||
/// Information about the capabilities of a card.
|
||||
|
|
|
@ -124,6 +124,11 @@ impl OpenPgp {
|
|||
let card_caps = &mut self.card_caps;
|
||||
let tx = self.card.transaction(Some(OP_APP))?;
|
||||
|
||||
if tx.was_reset() {
|
||||
// FIXME
|
||||
// Signal state invalidation? (PIN verification, ...)
|
||||
}
|
||||
|
||||
Ok(OpenPgpTransaction { tx, card_caps })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ impl From<PcscBackend> for Box<dyn CardBackend + Sync + Send> {
|
|||
pub struct PcscTransaction<'b> {
|
||||
tx: pcsc::Transaction<'b>,
|
||||
reader_caps: HashMap<u8, Tlv>, // FIXME: gets manually cloned
|
||||
was_reset: bool,
|
||||
}
|
||||
|
||||
impl<'b> PcscTransaction<'b> {
|
||||
|
@ -74,11 +75,17 @@ impl<'b> PcscTransaction<'b> {
|
|||
Ok(tx) => {
|
||||
// A pcsc transaction has been successfully started
|
||||
|
||||
let mut pt = Self { tx, reader_caps };
|
||||
let mut pt = Self {
|
||||
tx,
|
||||
reader_caps,
|
||||
was_reset: false,
|
||||
};
|
||||
|
||||
if was_reset {
|
||||
log::trace!("Card was reset");
|
||||
|
||||
pt.was_reset = true;
|
||||
|
||||
// If the caller expects that an application on the
|
||||
// card has been selected, re-select the application
|
||||
// here.
|
||||
|
@ -401,6 +408,10 @@ impl CardTransaction for PcscTransaction<'_> {
|
|||
|
||||
Ok(res.to_vec())
|
||||
}
|
||||
|
||||
fn was_reset(&self) -> bool {
|
||||
self.was_reset
|
||||
}
|
||||
}
|
||||
|
||||
impl PcscBackend {
|
||||
|
|
|
@ -309,4 +309,9 @@ impl CardTransaction for ScdTransaction<'_> {
|
|||
) -> Result<Vec<u8>, SmartcardError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// Not implemented here
|
||||
fn was_reset(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue