Struct iso7816_tlv::simple::Tlv
source · pub struct Tlv { /* private fields */ }
Expand description
SIMPLE-TLV data object representation.
Each SIMPLE-TLV data object shall consist of two or three consecutive fields: a mandatory tag field, a mandatory length field and a conditional value field
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 SIMPLE-TLV data object from valid tag and value.
A value has a maximum size of 65_535
bytes.
§Errors
Fails with TlvError::InvalidLength
if value is longer than 65_535
bytes.
sourcepub fn parse(input: &[u8]) -> (Result<Self, TlvError>, &[u8])
pub fn parse(input: &[u8]) -> (Result<Self, TlvError>, &[u8])
Parses a byte array into a SIMPLE-TLV structure. This also returns the unprocessed data.
§Example (parse mulitple tlv in input)
use iso7816_tlv::simple::Tlv;
use hex_literal::hex;
let in_data = hex!(
"03 01 01"
"04 01 04"
"07 07 85 66 C9 6A 14 49 04"
"01 08 57 5F 93 6E 01 00 00 00"
"09 01 00");
let mut buf: &[u8] = &in_data;
let mut parsed_manual = Vec::new();
while !buf.is_empty() {
let (r, remaining) = Tlv::parse(buf);
buf = remaining;
if r.map(|res| parsed_manual.push(res)).is_err() {
break;
}
}
Trait Implementations§
impl StructuralPartialEq for Tlv
Auto Trait Implementations§
impl RefUnwindSafe for Tlv
impl Send for Tlv
impl Sync for Tlv
impl Unpin for Tlv
impl UnwindSafe for Tlv
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