[−][src]Struct iso7816_tlv::ber::Tag
Tag for BER-TLV data as defined in [ISO7819-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]
pub fn to_bytes(&self) -> &[u8]
[src]
serializes the tag as byte array
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());
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());
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 PartialEq<Tag> for Tag
[src]
impl Debug for Tag
[src]
impl Display for Tag
[src]
impl TryFrom<u64> for Tag
[src]
type Error = TlvError
The type returned in the event of a conversion error.
fn try_from(v: u64) -> Result<Self, TlvError>
[src]
impl TryFrom<usize> for Tag
[src]
type Error = TlvError
The type returned in the event of a conversion error.
fn try_from(v: usize) -> Result<Self, TlvError>
[src]
impl TryFrom<u32> for Tag
[src]
type Error = TlvError
The type returned in the event of a conversion error.
fn try_from(v: u32) -> Result<Self, TlvError>
[src]
impl TryFrom<u16> for Tag
[src]
type Error = TlvError
The type returned in the event of a conversion error.
fn try_from(v: u16) -> Result<Self, TlvError>
[src]
impl TryFrom<u8> for Tag
[src]
type Error = TlvError
The type returned in the event of a conversion error.
fn try_from(v: u8) -> Result<Self, TlvError>
[src]
impl TryFrom<i32> for Tag
[src]
type Error = TlvError
The type returned in the event of a conversion error.
fn try_from(v: i32) -> Result<Self, TlvError>
[src]
impl TryFrom<i16> for Tag
[src]
type Error = TlvError
The type returned in the event of a conversion error.
fn try_from(v: i16) -> Result<Self, TlvError>
[src]
impl TryFrom<i8> for Tag
[src]
type Error = TlvError
The type returned in the event of a conversion error.
fn try_from(v: i8) -> Result<Self, TlvError>
[src]
impl<'_> TryFrom<&'_ str> for Tag
[src]
Auto Trait Implementations
impl Send for Tag
impl Unpin for Tag
impl Sync for Tag
impl UnwindSafe for Tag
impl RefUnwindSafe for Tag
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,