feat: v1.5.8, opt piv-meta

This commit is contained in:
2023-05-17 00:53:17 +08:00
parent 0ad8c12c38
commit 9fb0da7d33
4 changed files with 8 additions and 3 deletions

2
Cargo.lock generated
View File

@@ -342,7 +342,7 @@ dependencies = [
[[package]]
name = "card-cli"
version = "1.5.7"
version = "1.5.8"
dependencies = [
"authenticator",
"base64 0.13.1",

View File

@@ -1,6 +1,6 @@
[package]
name = "card-cli"
version = "1.5.7"
version = "1.5.8"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"

View File

@@ -12,6 +12,7 @@ use yubikey::certificate::PublicKeyInfo;
use yubikey::piv::{AlgorithmId, ManagementAlgorithmId, metadata, Origin};
use crate::pivutil;
use crate::pivutil::slot_equals;
use crate::pkiutil::bytes_to_pem;
pub struct CommandImpl;
@@ -116,7 +117,7 @@ impl Command for CommandImpl {
Err(e) => warning!("List keys failed: {}", e),
Ok(keys) => for k in &keys {
let slot_str = format!("{:x}", Into::<u8>::into(k.slot()));
if slot_str == slot {
if slot_equals(&slot_id, &slot_str) {
if !json.contains_key("pk_point_hex") {
let public_key_hex = &k.certificate().subject_pki().public_key();
json.insert("pk_point_hex", hex::encode(&public_key_hex));

View File

@@ -4,6 +4,10 @@ use rust_util::XResult;
use yubikey::piv::RetiredSlotId;
use yubikey::piv::SlotId;
pub fn slot_equals(slot_id: &SlotId, slot: &str) -> bool {
get_slot_id(slot).map(|sid| &sid == slot_id).unwrap_or(false)
}
pub fn get_slot_id(slot: &str) -> XResult<SlotId> {
Ok(match slot {
"9a" => SlotId::Authentication,