Add YubiKey::disconnect (#462)
This exposes `pcsc::Card::disconnect` to allow alternate disposition methods.
This commit is contained in:
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
### Added
|
### Added
|
||||||
|
- `YubiKey::disconnect`
|
||||||
- `impl Debug for {Context, YubiKey}`
|
- `impl Debug for {Context, YubiKey}`
|
||||||
|
|
||||||
## 0.7.0 (2022-11-14)
|
## 0.7.0 (2022-11-14)
|
||||||
|
|||||||
+33
-1
@@ -42,7 +42,7 @@ use crate::{
|
|||||||
transaction::Transaction,
|
transaction::Transaction,
|
||||||
};
|
};
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use pcsc::Card;
|
use pcsc::{Card, Disposition};
|
||||||
use rand_core::{OsRng, RngCore};
|
use rand_core::{OsRng, RngCore};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Display},
|
fmt::{self, Display},
|
||||||
@@ -248,6 +248,38 @@ impl YubiKey {
|
|||||||
Ok(())
|
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.
|
/// Begin a transaction.
|
||||||
pub(crate) fn begin_transaction(&mut self) -> Result<Transaction<'_>> {
|
pub(crate) fn begin_transaction(&mut self) -> Result<Transaction<'_>> {
|
||||||
// TODO(tarcieri): reconnect support
|
// TODO(tarcieri): reconnect support
|
||||||
|
|||||||
Reference in New Issue
Block a user