Struct Tlv

Source
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

Source

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).

Source

pub fn tag(&self) -> &Tag

Get BER-TLV tag.

Source

pub fn length(&self) -> usize

Get BER-TLV value length

Source

pub fn value(&self) -> &Value

Get BER-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 BER-TLV structure. This also returns the unprocessed data.

Source

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

Parses a byte array into a vector of BER-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 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.

Source

pub fn find(&self, tag: &Tag) -> Option<&Self>

Finds first occurence of a TLV object with given tag in self.

Source

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.

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 Display 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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 Freeze for Tlv

§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.