Add partial Debug impls for Context and YubiKey (#457)

This enables `yubikey::Result<T>` to be debug-formatted, for example
when wrapping the output of an API method in `dbg!()`.
This commit is contained in:
str4d
2023-01-01 18:16:10 +00:00
committed by GitHub
parent 002491193e
commit 10941bfb5b
3 changed files with 21 additions and 0 deletions
+7
View File
@@ -4,6 +4,7 @@ use crate::{Result, YubiKey};
use std::{
borrow::Cow,
ffi::CStr,
fmt,
sync::{Arc, Mutex},
};
@@ -19,6 +20,12 @@ pub struct Context {
reader_names: Vec<u8>,
}
impl fmt::Debug for Context {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Context").finish_non_exhaustive()
}
}
impl Context {
/// Open a PC/SC context, which can be used to enumerate available PC/SC
/// readers (which can be used to connect to YubiKeys).
+10
View File
@@ -156,6 +156,16 @@ pub struct YubiKey {
pub(crate) serial: Serial,
}
impl fmt::Debug for YubiKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("YubiKey")
.field("name", &self.name)
.field("version", &self.version)
.field("serial", &self.serial)
.finish_non_exhaustive()
}
}
impl YubiKey {
/// Open a connection to a YubiKey.
///