Struct iso7816_tlv::ber::Tag
source · pub struct Tag { /* private fields */ }
Expand description
Tag for BER-TLV data as defined in [ISO7816-4].
Tags can be generated using the TryFrom
trait
from integer types (see Trait Implementations for valid input types)
or hex str.
Tags are now imported in a more permissivie way.
Invalid tags in ISO7816 meaning can be checked, see Self::iso7816_compliant
§Example
use std::convert::TryFrom;
use iso7816_tlv::ber::Tag;
assert!(Tag::try_from("80").is_ok());
assert!(Tag::try_from(8u8).is_ok());
assert!(Tag::try_from(8u16).is_ok());
assert!(Tag::try_from(8u32).is_ok());
assert!(Tag::try_from(8i32).is_ok());
assert!(Tag::try_from("7f22").is_ok());
assert!(Tag::try_from("error ").is_err());
assert!(Tag::try_from("7fffff01").is_err());
assert!(Tag::try_from("7f80ff").is_err());
// now more permissive interface :
assert!(Tag::try_from("7f00").is_ok());
assert!(Tag::try_from("7f1e").is_ok());
Implementations§
source§impl Tag
impl Tag
sourcepub fn len_as_bytes(&self) -> usize
pub fn len_as_bytes(&self) -> usize
length of the tag as byte array
§Example
use std::convert::TryFrom;
use iso7816_tlv::ber::Tag;
let tag = Tag::try_from("80")?;
assert_eq!(1, tag.len_as_bytes());
let tag = Tag::try_from("7f22")?;
assert_eq!(2, tag.len_as_bytes());
let tag = Tag::try_from("7f8122")?;
assert_eq!(3, tag.len_as_bytes());
let tag = Tag::try_from("5fff22")?;
assert_eq!(3, tag.len_as_bytes());
let tag = Tag::try_from("5f2d")?;
assert_eq!(2, tag.len_as_bytes());
sourcepub fn is_constructed(&self) -> bool
pub fn is_constructed(&self) -> bool
Wether the tag is constructed or not
Bit 6 of the first byte of the tag field indicates an encoding.
- The value 0 indicates a primitive encoding of the data object, i.e., the value field is not encoded in BER - TLV .
- The value 1 indicates a constructed encoding of the data object, i.e., the value field is encoded in BER - TLV
§Example
use std::convert::TryFrom;
use iso7816_tlv::ber::Tag;
let valid = Tag::try_from(0b0010_0000)?;
assert!(valid.is_constructed());
let invalid = Tag::try_from(0b0000_0001)?;
assert!(!invalid.is_constructed());
sourcepub fn iso7816_compliant(&self) -> bool
pub fn iso7816_compliant(&self) -> bool
Valid tags are defined as follow:
ISO/IEC 7816 supports tag fields of one, two and three bytes; longer tag fields are reserved for future use
In tag fields of two or more bytes, the values ‘00’ to ‘1E’ and ‘80’ are invalid for the second byte.
- In two-byte tag fields, the second byte consists of bit 8 set to 0 and bits 7 to 1 encoding a number greater than thirty. The second byte is valued from ‘1F’ to ’7F; the tag number is from 31 to 127.
- In three-byte tag fields, the second byte consists of bit 8 set to 1 and bits 7 to 1 not all set to 0; the third byte consists of bit 8 set to 0 and bits 7 to 1 with any value.
§Example
use std::convert::TryFrom;
use iso7816_tlv::ber::Tag;
let t = Tag::try_from("7f00")?;
assert!(!t.iso7816_compliant());
// 9f1e is a valid EMV tag, but not ISO7816-4 compliant
let t = Tag::try_from("9f1e")?;
assert!(!t.iso7816_compliant());
Trait Implementations§
impl StructuralPartialEq for Tag
Auto Trait Implementations§
impl RefUnwindSafe for Tag
impl Send for Tag
impl Sync for Tag
impl Unpin for Tag
impl UnwindSafe for Tag
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more