[][src]Struct iso7816_tlv::ber::Tag

pub struct Tag { /* fields omitted */ }

Tag for BER-TLV data as defined in [ISO7816-4]. 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.
  • 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.

Tags can be generated using the TryFrom trait from integer types (see Trait Implementations for valid input types) or hex str.

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("7f00").is_err());
assert!(Tag::try_from("7f80ff").is_err());
assert!(Tag::try_from("7f1e").is_err());

Methods

impl Tag[src]

#[must_use]pub fn to_bytes(&self) -> &[u8][src]

serializes the tag as byte array

#[must_use]pub fn len_as_bytes(&self) -> usize[src]

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("7f8022")?;
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());

#[must_use]pub fn is_constructed(&self) -> bool[src]

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());

#[must_use]pub fn class(&self) -> Class[src]

Get the tag class.

Example

use std::convert::TryFrom;
use iso7816_tlv::ber::{Tag, Class};

let tag = Tag::try_from(0b0010_0000)?;
assert_eq!(Class::Universal, tag.class());
let tag = Tag::try_from(0b1100_0000)?;
assert_eq!(Class::Private, tag.class());

Trait Implementations

impl Clone for Tag[src]

impl Debug for Tag[src]

impl Display for Tag[src]

impl Into<u64> for Tag[src]

impl PartialEq<Tag> for Tag[src]

impl StructuralPartialEq for Tag[src]

impl<'_> TryFrom<&'_ str> for Tag[src]

type Error = TlvError

The type returned in the event of a conversion error.

impl TryFrom<i16> for Tag[src]

type Error = TlvError

The type returned in the event of a conversion error.

impl TryFrom<i32> for Tag[src]

type Error = TlvError

The type returned in the event of a conversion error.

impl TryFrom<i8> for Tag[src]

type Error = TlvError

The type returned in the event of a conversion error.

impl TryFrom<u16> for Tag[src]

type Error = TlvError

The type returned in the event of a conversion error.

impl TryFrom<u32> for Tag[src]

type Error = TlvError

The type returned in the event of a conversion error.

impl TryFrom<u64> for Tag[src]

type Error = TlvError

The type returned in the event of a conversion error.

impl TryFrom<u8> for Tag[src]

type Error = TlvError

The type returned in the event of a conversion error.

impl TryFrom<usize> for Tag[src]

type Error = TlvError

The type returned in the event of a conversion error.

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.