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

source

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.

source

pub fn tag(&self) -> Tag

Get SIMPLE-TLV tag.

source

pub fn length(&self) -> usize

Get SIMPLE-TLV value length

source

pub fn value(&self) -> &[u8]

Get SIMPLE-TLV value

source

pub fn to_vec(&self) -> Vec<u8>

serializes self into a byte vector.

source

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;
  }
}
source

pub fn parse_all(input: &[u8]) -> Vec<Self>

Parses a byte array into a vector of SIMPLE-TLV.

§Note

Errors are discarded and parsing stops at first error Prefer using the parse() method and iterate over returned processed data.

source

pub fn from_bytes(input: &[u8]) -> Result<Self, TlvError>

Parses a byte array into a SIMPLE-TLV structure. Input must exactly match a SIMPLE-TLV object.

§Errors

Fails with TlvError::InvalidInput if input does not match a SIMPLE-TLV object.

Trait Implementations§

source§

impl Clone for Tlv

source§

fn clone(&self) -> Tlv

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Tlv

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Tlv

source§

fn eq(&self, other: &Tlv) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.