keyfork-shard: parse cardholder name when using smartcards

This commit is contained in:
Ryan Heywood 2023-11-05 01:36:12 -05:00
parent 4b4b85931f
commit 0768339487
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 12 additions and 1 deletions

View File

@ -31,6 +31,17 @@ impl std::fmt::Display for SmartcardFailure {
impl std::error::Error for SmartcardFailure {} impl std::error::Error for SmartcardFailure {}
fn format_name(input: impl AsRef<str>) -> String {
let mut n = input
.as_ref()
.split("<<")
.take(2)
.map(|s| s.replace('>', " "))
.collect::<Vec<_>>();
n.reverse();
n.join(" ")
}
pub struct SmartcardManager { pub struct SmartcardManager {
current_card: Option<Card<Open>>, current_card: Option<Card<Open>>,
root: Option<Cert>, root: Option<Cert>,
@ -178,7 +189,7 @@ impl DecryptionHelper for &mut SmartcardManager {
let Some(fp) = fp else { let Some(fp) = fp else {
return Err(SmartcardFailure::SmartCardHasNoDecrypt.into()); 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 card_id = transaction.application_identifier()?.ident();
let message = if cardholder_name.is_empty() { let message = if cardholder_name.is_empty() {
format!("Unlock card {card_id}") format!("Unlock card {card_id}")