diff --git a/card-functionality/src/tests.rs b/card-functionality/src/tests.rs index 8fa01d3..8a6ea4a 100644 --- a/card-functionality/src/tests.rs +++ b/card-functionality/src/tests.rs @@ -320,7 +320,7 @@ pub fn test_set_user_data( let mut admin = tx.to_admin_card("12345678")?; // name - admin.set_name("Bar<, _param: &[&str]) -> Result, _param: &[&str]) -> Result, _param: &[&str]) -> Result Result<(), Box> { println!(); - admin.set_name("Bar< Card> { s.iter().map(|&c| c as char).collect() } - /// Get cardholder name as a String (this also normalizes the "<" and "<<" filler chars) - pub fn cardholder_name(&mut self) -> Result, Error> { + /// Get cardholder name. + /// + /// This is an ISO 8859-1 (Latin 1) String of up to 39 characters. + /// + /// Note that the standard specifies that this field should be encoded + /// according to ISO/IEC 7501-1: + /// + /// "The data element consists of surname (e. g. family name and given + /// name(s)) and forename(s) (including name suffix, e. g., Jr. and number). + /// Each item is separated by a ´<´ filler character (3C), the family- and + /// fore-name(s) are separated by two ´<<´ filler characters." + /// + /// This library doesn't perform this encoding. + pub fn cardholder_name(&mut self) -> Result { let crd = self.state.opt.cardholder_related_data()?; - if let Some(name) = crd.name() { - let name = Self::latin1_to_string(name); - // re-format name ("last< = name.split("<<").collect(); - let name = name.iter().cloned().rev().collect::>().join(" "); - - // replace item separators with spaces - let name = name.replace('<', " "); - - Ok(Some(name)) - } else { - Ok(None) + match crd.name() { + Some(name) => Ok(Self::latin1_to_string(name)), + None => Ok("".to_string()), } } @@ -996,7 +999,20 @@ impl<'app, 'open> Card> { } impl Card> { - pub fn set_name(&mut self, name: &str) -> Result<(), Error> { + /// Set cardholder name. + /// + /// This is an ISO 8859-1 (Latin 1) String of max. 39 characters. + /// + /// Note that the standard specifies that this field should be encoded according + /// to ISO/IEC 7501-1: + /// + /// "The data element consists of surname (e. g. family name and given + /// name(s)) and forename(s) (including name suffix, e. g., Jr. and number). + /// Each item is separated by a ´<´ filler character (3C), the family- and + /// fore-name(s) are separated by two ´<<´ filler characters." + /// + /// This library doesn't perform this encoding. + pub fn set_cardholder_name(&mut self, name: &str) -> Result<(), Error> { // All chars must be in ASCII7 if name.chars().any(|c| !c.is_ascii()) { return Err(Error::InternalError("Invalid char in name".into()));