Add YubiKey::disconnect (#462)

This exposes `pcsc::Card::disconnect` to allow alternate disposition
methods.
This commit is contained in:
str4d
2023-01-02 18:15:31 +00:00
committed by GitHub
parent 10941bfb5b
commit 18eb4bf4f4
2 changed files with 34 additions and 1 deletions
+1
View File
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Added
- `YubiKey::disconnect`
- `impl Debug for {Context, YubiKey}`
## 0.7.0 (2022-11-14)
+33 -1
View File
@@ -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