From 1d0fe631a2943b85b66951c74577822ad3a277ea Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Thu, 5 Oct 2023 21:56:48 +0800 Subject: [PATCH] feat: piv-summary --- src/cmd_pivsummary.rs | 45 +++++++++++++++++++++++++++++-------------- src/pivutil.rs | 11 ++++++++++- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/cmd_pivsummary.rs b/src/cmd_pivsummary.rs index da4b79a..474a3b7 100644 --- a/src/cmd_pivsummary.rs +++ b/src/cmd_pivsummary.rs @@ -10,11 +10,15 @@ use yubikey::piv::{metadata, SlotId}; use crate::pivutil::{get_algorithm_id, ToStr}; +const NA: &str = "N/A"; + #[derive(Tabled)] struct PivSlot { name: String, id: String, algorithm: String, + origin: String, + retries: String, subject: String, pin_policy: String, touch_policy: String, @@ -75,12 +79,20 @@ impl Command for CommandImpl { fn print_summary_info(yubikey: &mut YubiKey, slot: SlotId, piv_slots: &mut Vec, show_all: bool, show_table: bool) -> XResult<()> { let slot_id: u8 = slot.into(); - let mut pin_policy = Some("N/A".to_string()); - let mut touch_policy = Some("N/A".to_string()); + let mut origin = NA.to_string(); + let mut retries = NA.to_string(); + let mut pin_policy = NA.to_string(); + let mut touch_policy = NA.to_string(); if let Ok(metadata) = metadata(yubikey, slot) { if let Some((p_policy, t_policy)) = &metadata.policy { - pin_policy = Some(p_policy.to_str().to_string()); - touch_policy = Some(t_policy.to_str().to_string()); + pin_policy = p_policy.to_str().to_string(); + touch_policy = t_policy.to_str().to_string(); + } + if let Some(o) = &metadata.origin { + origin = o.to_str().to_string(); + } + if let Some(r) = &metadata.retries { + retries = format!("{}/{}", r.retry_count, r.remaining_count); } } let cert = match Certificate::read(yubikey, slot) { @@ -91,10 +103,12 @@ fn print_summary_info(yubikey: &mut YubiKey, slot: SlotId, piv_slots: &mut Vec

&str { + match self { + Origin::Imported => "imported", + Origin::Generated => "generated", + } + } +} + pub fn get_algorithm_id(public_key_info: &SubjectPublicKeyInfoOwned) -> XResult { if public_key_info.algorithm.oid == RSA { let rsa_public_key = opt_result!(