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
+4
View File
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
- `impl Debug for {Context, YubiKey}`
## 0.7.0 (2022-11-14) ## 0.7.0 (2022-11-14)
### Added ### Added
- Display inner PC/SC errors ([#420]) - Display inner PC/SC errors ([#420])
+7
View File
@@ -4,6 +4,7 @@ use crate::{Result, YubiKey};
use std::{ use std::{
borrow::Cow, borrow::Cow,
ffi::CStr, ffi::CStr,
fmt,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
@@ -19,6 +20,12 @@ pub struct Context {
reader_names: Vec<u8>, 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 { impl Context {
/// Open a PC/SC context, which can be used to enumerate available PC/SC /// Open a PC/SC context, which can be used to enumerate available PC/SC
/// readers (which can be used to connect to YubiKeys). /// readers (which can be used to connect to YubiKeys).
+10
View File
@@ -156,6 +156,16 @@ pub struct YubiKey {
pub(crate) serial: Serial, 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 { impl YubiKey {
/// Open a connection to a YubiKey. /// Open a connection to a YubiKey.
/// ///