From 0768339487aa49de85d6860e6cc908dcf7989d84 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 5 Nov 2023 01:36:12 -0500 Subject: [PATCH] keyfork-shard: parse cardholder name when using smartcards --- keyfork-shard/src/openpgp/smartcard.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/keyfork-shard/src/openpgp/smartcard.rs b/keyfork-shard/src/openpgp/smartcard.rs index 4b6b06e..8565a3e 100644 --- a/keyfork-shard/src/openpgp/smartcard.rs +++ b/keyfork-shard/src/openpgp/smartcard.rs @@ -31,6 +31,17 @@ impl std::fmt::Display for SmartcardFailure { impl std::error::Error for SmartcardFailure {} +fn format_name(input: impl AsRef) -> String { + let mut n = input + .as_ref() + .split("<<") + .take(2) + .map(|s| s.replace('>', " ")) + .collect::>(); + n.reverse(); + n.join(" ") +} + pub struct SmartcardManager { current_card: Option>, root: Option, @@ -178,7 +189,7 @@ impl DecryptionHelper for &mut SmartcardManager { let Some(fp) = fp else { return Err(SmartcardFailure::SmartCardHasNoDecrypt.into()); }; - let cardholder_name = transaction.cardholder_name()?; + let cardholder_name = format_name(transaction.cardholder_name()?); let card_id = transaction.application_identifier()?.ident(); let message = if cardholder_name.is_empty() { format!("Unlock card {card_id}")