Implement Display for CardholderRelatedData
This commit is contained in:
parent
db9c6e120f
commit
02b42081b9
3 changed files with 26 additions and 0 deletions
|
@ -737,6 +737,23 @@ pub struct CardholderRelatedData {
|
|||
sex: Option<Sex>,
|
||||
}
|
||||
|
||||
impl Display for CardholderRelatedData {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
if let Some(name) = &self.name {
|
||||
writeln!(f, "Name: {}", Self::latin1_to_string(name))?;
|
||||
}
|
||||
if let Some(sex) = self.sex {
|
||||
writeln!(f, "Sex: {}", sex)?;
|
||||
}
|
||||
if let Some(lang) = &self.lang {
|
||||
for (n, l) in lang.iter().enumerate() {
|
||||
writeln!(f, "Lang {}: {}", n + 1, l)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// 4.4.3.5 Sex
|
||||
/// Encoded in accordance with https://en.wikipedia.org/wiki/ISO/IEC_5218
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
|
|
|
@ -13,6 +13,14 @@ impl CardholderRelatedData {
|
|||
self.name.as_deref()
|
||||
}
|
||||
|
||||
/// The name field is defined as latin1 encoded,
|
||||
/// with ´<´ and ´<<´ filler characters to separate elements and name-parts.
|
||||
///
|
||||
/// (The filler/separation characters are not processed by this fn)
|
||||
pub(crate) fn latin1_to_string(s: &[u8]) -> String {
|
||||
s.iter().map(|&c| c as char).collect()
|
||||
}
|
||||
|
||||
pub fn lang(&self) -> Option<&[Lang]> {
|
||||
self.lang.as_deref()
|
||||
}
|
||||
|
|
|
@ -419,6 +419,7 @@ fn print_status(ident: Option<String>, verbose: bool) -> Result<()> {
|
|||
let crd = open.cardholder_related_data()?;
|
||||
|
||||
if let Some(name) = crd.name() {
|
||||
// FIXME: decoding as utf8 is wrong (the spec defines this field as latin1 encoded)
|
||||
let name = String::from_utf8_lossy(name).to_string();
|
||||
|
||||
print!("Cardholder: ");
|
||||
|
|
Loading…
Reference in a new issue