Add UndefinedValue(u8) to Sex struct; implement Display
This commit is contained in:
parent
c4b2de2b0c
commit
db9c6e120f
1 changed files with 39 additions and 23 deletions
|
@ -737,13 +737,51 @@ pub struct CardholderRelatedData {
|
||||||
sex: Option<Sex>,
|
sex: Option<Sex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 4.4.3.5 Sex (according to ISO 5218)
|
/// 4.4.3.5 Sex
|
||||||
|
/// Encoded in accordance with https://en.wikipedia.org/wiki/ISO/IEC_5218
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub enum Sex {
|
pub enum Sex {
|
||||||
NotKnown,
|
NotKnown,
|
||||||
Male,
|
Male,
|
||||||
Female,
|
Female,
|
||||||
NotApplicable,
|
NotApplicable,
|
||||||
|
UndefinedValue(u8), // ISO 5218 doesn't define this value
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Sex {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::NotKnown => write!(f, "Not known"),
|
||||||
|
Self::Male => write!(f, "Male"),
|
||||||
|
Self::Female => write!(f, "Female"),
|
||||||
|
Self::NotApplicable => write!(f, "Not applicable"),
|
||||||
|
Self::UndefinedValue(v) => write!(f, "Undefined value {:x?}", v),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Sex> for u8 {
|
||||||
|
fn from(sex: &Sex) -> u8 {
|
||||||
|
match sex {
|
||||||
|
Sex::NotKnown => 0x30,
|
||||||
|
Sex::Male => 0x31,
|
||||||
|
Sex::Female => 0x32,
|
||||||
|
Sex::NotApplicable => 0x39,
|
||||||
|
Sex::UndefinedValue(v) => *v,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u8> for Sex {
|
||||||
|
fn from(s: u8) -> Self {
|
||||||
|
match s {
|
||||||
|
0x30 => Self::NotKnown,
|
||||||
|
0x31 => Self::Male,
|
||||||
|
0x32 => Self::Female,
|
||||||
|
0x39 => Self::NotApplicable,
|
||||||
|
v => Self::UndefinedValue(v),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
|
@ -798,28 +836,6 @@ impl From<&[u8; 2]> for Lang {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Sex> for u8 {
|
|
||||||
fn from(sex: &Sex) -> u8 {
|
|
||||||
match sex {
|
|
||||||
Sex::NotKnown => 0x30,
|
|
||||||
Sex::Male => 0x31,
|
|
||||||
Sex::Female => 0x32,
|
|
||||||
Sex::NotApplicable => 0x39,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u8> for Sex {
|
|
||||||
fn from(s: u8) -> Self {
|
|
||||||
match s {
|
|
||||||
0x31 => Sex::Male,
|
|
||||||
0x32 => Sex::Female,
|
|
||||||
0x39 => Sex::NotApplicable,
|
|
||||||
_ => Sex::NotKnown,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// PW status Bytes (see spec page 23)
|
/// PW status Bytes (see spec page 23)
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct PWStatusBytes {
|
pub struct PWStatusBytes {
|
||||||
|
|
Loading…
Reference in a new issue