Add YubiKey::disconnect (#462)
This exposes `pcsc::Card::disconnect` to allow alternate disposition methods.
This commit is contained in:
+33
-1
@@ -42,7 +42,7 @@ use crate::{
|
||||
transaction::Transaction,
|
||||
};
|
||||
use log::{error, info};
|
||||
use pcsc::Card;
|
||||
use pcsc::{Card, Disposition};
|
||||
use rand_core::{OsRng, RngCore};
|
||||
use std::{
|
||||
fmt::{self, Display},
|
||||
@@ -248,6 +248,38 @@ impl YubiKey {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Disconnect from the YubiKey.
|
||||
///
|
||||
/// In case of error, ownership of the YubiKey is returned to the caller.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// `YubiKey` implements `Drop` which automatically disconnects the card using
|
||||
/// `Disposition::ResetCard`; you only need to call this function if you want to
|
||||
/// handle errors or use a different disposition method.
|
||||
pub fn disconnect(self, disposition: Disposition) -> core::result::Result<(), (Self, Error)> {
|
||||
let Self {
|
||||
card,
|
||||
name,
|
||||
pin,
|
||||
version,
|
||||
serial,
|
||||
} = self;
|
||||
|
||||
card.disconnect(disposition).map_err(|(card, e)| {
|
||||
(
|
||||
Self {
|
||||
card,
|
||||
name,
|
||||
pin,
|
||||
version,
|
||||
serial,
|
||||
},
|
||||
e.into(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// Begin a transaction.
|
||||
pub(crate) fn begin_transaction(&mut self) -> Result<Transaction<'_>> {
|
||||
// TODO(tarcieri): reconnect support
|
||||
|
||||
Reference in New Issue
Block a user