pub struct Tlv { /* private fields */ }
Expand description
BER-TLV structure, following ISO/IEC 7816-4.
§BER-TLV data objects
Each BER-TLV data object consists of two or three consecutive fields (see the basic encoding rules of ASN.1 in ISO/IEC 8825-1): a mandatory tag field, a mandatory length field and a conditional value field.
- The tag field consists of one or more consecutive bytes. It indicates a class and an encoding and it encodes a tag number. The value ‘00’ is invalid for the first byte of tag fields (see ISO/IEC 8825-1).
- The length field consists of one or more consecutive bytes. It encodes a length, i.e., a number denoted N.
- If N is zero, there is no value field, i.e., the data object is empty. Otherwise (N > 0), the value field consists of N consecutive bytes.
Implementations§
Source§impl Tlv
impl Tlv
Sourcepub fn new(tag: Tag, value: Value) -> Result<Self, TlvError>
pub fn new(tag: Tag, value: Value) -> Result<Self, TlvError>
Create a BER-TLV data object from valid tag and value.alloc
§Errors
Fails with TlvError::Inconsistant
if the tag indicates a contructed value (resp. primitive) and the
value is primitive (resp. contructed).
Sourcepub fn parse(input: &[u8]) -> (Result<Self, TlvError>, &[u8])
pub fn parse(input: &[u8]) -> (Result<Self, TlvError>, &[u8])
Parses a byte array into a BER-TLV structure. This also returns the unprocessed data.
Sourcepub fn from_bytes(input: &[u8]) -> Result<Self, TlvError>
pub fn from_bytes(input: &[u8]) -> Result<Self, TlvError>
Parses a byte array into a BER-TLV structure. Input must exactly match a BER-TLV object.
§Errors
Fails with TlvError::InvalidInput
if input does not match a BER-TLV object.
Sourcepub fn find(&self, tag: &Tag) -> Option<&Self>
pub fn find(&self, tag: &Tag) -> Option<&Self>
Finds first occurence of a TLV object with given tag in self.
Sourcepub fn find_all(&self, tag: &Tag) -> Vec<&Self>
pub fn find_all(&self, tag: &Tag) -> Vec<&Self>
find all occurences of TLV objects with given given tag in self.
Note that searching ContextSpecific
class tag (0x80 for instance) will return
a vector of possibly unrelated tlv data.