Tag

Struct Tag 

Source
pub struct Tag(/* private fields */);
Expand description

The tag of a BER encoded value.

Each BER encoded value starts with a sequence of one or more octets called the identifier octets. They encode both the tag of the value as well as whether the value uses primitive or constructed encoding. The Tag type represents the tag only. The distinction between primitive and constructed encoding is captured by the decoder types Primitive and Constructed instead.

The tag in turn consists of two parts: the class and the number – the Tag type includes both of them.

§Limitations

We can only decode up to four identifier octets. That is, we only support tag numbers between 0 and 1fffff.

Implementations§

Source§

impl Tag

§Constants for Often Used Tag Values

Source

pub const END_OF_VALUE: Self

The tag marking the end-of-value in an indefinite length value.

This is UNIVERSAL 0.

Source

pub const BOOLEAN: Self

The tag for the BOOLEAN type, UNIVERSAL 1.

Source

pub const INTEGER: Self

The tag for the INTEGER type, UNIVERSAL 2.

Source

pub const BIT_STRING: Self

The tag for the BIT STRING type, UNIVERSAL 3.

Source

pub const OCTET_STRING: Self

The tag for the OCTET STRING type, UNIVERSAL 4.

Source

pub const NULL: Self

The tag for the NULL type, UNIVERSAL 5.

Source

pub const OID: Self

The tag for the OBJECT IDENTIFIER type, UNIVERSAL 6.

Source

pub const OBJECT_DESCRIPTOR: Self

The tag for the ObjectDescriptor type, UNIVERSAL 7.

Source

pub const EXTERNAL: Self

The tag for the EXTERNAL and Instance-of types, UNIVERSAL 8.

Source

pub const REAL: Self

The tag for the REAL type, UNIVERSAL 9.

Source

pub const ENUMERATED: Self

The tag for the ENUMERATED type, UNIVERSAL 10.

Source

pub const EMBEDDED_PDV: Self

The tag for the EMBEDDED PDV type, UNIVERSAL 11.

Source

pub const UTF8_STRING: Self

The tag for the UTF8String type, UNIVERSAL 12

Source

pub const RELATIVE_OID: Self

The tag for the RELATIVE-OID type, UNIVERSAL 13.

Source

pub const TIME: Self

The tag for the TIME type, UNIVERSAL 14.

Source

pub const SEQUENCE: Self

The tag for the SEQUENCE and SEQUENCE OF types, UNIVERSAL 16.

Source

pub const SET: Self

The tag for the SET and SET OF types, UNIVERSAL 17.

Source

pub const NUMERIC_STRING: Self

The tag for the NumericString type, UNIVERSAL 18.

Source

pub const PRINTABLE_STRING: Self

The tag for the PrintableString type, UNIVERSAL 19.

Source

pub const TELETEX_STRING: Self

The tag for the TeletexString type, UNIVERSAL 20.

Source

pub const VIDEOTEX_STRING: Self

The tag for the VideotexString type, UNIVERSAL 21.

Source

pub const IA5_STRING: Self

The tag for the IA5String type, UNIVERSAL 22.

Source

pub const UTC_TIME: Self

The tag for the UTCTime type, UNIVERSAL 23.

Source

pub const GENERALIZED_TIME: Self

The tag for the GeneralizedType type, UNIVERSAL 24.

Source

pub const GRAPHIC_STRING: Self

The tag for the GraphicString type, UNIVERSAL 25.

Source

pub const VISIBLE_STRING: Self

The tag for the VisibleString type, UNIVERSAL 26.

Source

pub const GENERAL_STRING: Self

The tag for the GeneralString type, UNIVERSAL 27.

Source

pub const UNIVERSAL_STRING: Self

The tag for the UniversalString type, UNIVERSAL 28.

Source

pub const CHARACTER_STRING: Self

The tag for the CHARACTER STRING type, UNIVERSAL 29.

Source

pub const BMP_STRING: Self

The tag for the BMPString type, UNIVERSAL 30.

Source

pub const DATE: Self

The tag for the DATE type, UNIVERSAL 31.

Source

pub const TIME_OF_DAY: Self

The tag for the TIME-OF-DAY type, UNIVERSAL 32.

Source

pub const DATE_TIME: Self

The tag for the DATE-TIME type, UNIVERSAL 33.

Source

pub const DURATION: Self

The tag for the DURATION type, UNIVERSAL 34.

Source

pub const OID_IRI: Self

The tag for the OID-IRI type, UNIVERSAL 35.

Source

pub const RELATIVE_OID_IRI: Self

The tag for the RELATIVE-OID-IRI type, UNIVERSAL 36.

Source

pub const CTX_0: Self

The tag context specific tag [0].

Source

pub const CTX_1: Self

The tag context specific tag [1].

Source

pub const CTX_2: Self

The tag context specific tag [2].

Source

pub const CTX_3: Self

The tag context specific tag [3].

Source

pub const CTX_4: Self

The tag context specific tag [4].

Source

pub const CTX_5: Self

The tag context specific tag [5].

Source

pub const CTX_6: Self

The tag context specific tag [6].

Source§

impl Tag

Source

pub fn universal(number: u32) -> Self

Creates a new tag in the universal class with the given tag number.

§Panics

Currently, this function panics if the tag number is greater than MAX_VAL_SPAN_3_OCTETS.

Source

pub fn application(number: u32) -> Self

Creates a new tag in the application class with the given tag number.

§Panics

Currently, this function panics if the tag number is greater than MAX_VAL_SPAN_3_OCTETS.

Source

pub fn ctx(number: u32) -> Self

Creates a new tag in the context specific class.

§Panics

Currently, this function panics if the provided tag number is greater than MAX_VAL_SPAN_3_OCTETS.

Source

pub fn private(number: u32) -> Self

Creates a new tag in the private class with the given tag number.

§Panics

Currently, this function panics if the provided tag number is greater than MAX_VAL_SPAN_3_OCTETS.

Source

pub fn is_universal(self) -> bool

Returns whether the tag is of the universal class.

Source

pub fn is_application(self) -> bool

Returns whether the tag is of the application class.

Source

pub fn is_context_specific(self) -> bool

Returns whether the tag is of the context specific class.

Source

pub fn is_private(self) -> bool

Returns whether the tag is of the private class.

Source

pub fn number(self) -> u32

Returns the number of the tag.

Source

pub fn take_opt_from<S: Source>( source: &mut S, ) -> Result<Option<(Self, bool)>, DecodeError<S::Error>>

Takes an optional tag from the beginning of a source.

Upon success, returns both the tag and whether the value is constructed.

Source

pub fn take_from<S: Source>( source: &mut S, ) -> Result<(Self, bool), DecodeError<S::Error>>

Takes a tag from the beginning of a source.

Upon success, returns both the tag and whether the value is constructed. If there are no more octets available in the source, an error is returned.

Source

pub fn take_from_if<S: Source>( self, source: &mut S, ) -> Result<Option<bool>, DecodeError<S::Error>>

Takes a tag from the beginning of a resource if it matches this tag.

If there is no more data available in the source or if the tag is something else, returns Ok(None). If the tag matches self, returns whether the value is constructed.

Source

pub fn encoded_len(&self) -> usize

Returns the number of octets of the encoded form of the tag.

Source

pub fn write_encoded<W: Write>( &self, constructed: bool, target: &mut W, ) -> Result<(), Error>

Encodes the tag into a target.

If constructed is true, the encoded tag will signal a value in constructed encoding and primitive encoding otherwise.

Trait Implementations§

Source§

impl Clone for Tag

Source§

fn clone(&self) -> Tag

Returns a duplicate 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 Tag

Source§

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

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

impl Display for Tag

Source§

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

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

impl PartialEq for Tag

Source§

fn eq(&self, other: &Tag) -> 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 Copy for Tag

Source§

impl Eq for Tag

Source§

impl StructuralPartialEq for Tag

Auto Trait Implementations§

§

impl Freeze for Tag

§

impl RefUnwindSafe for Tag

§

impl Send for Tag

§

impl Sync for Tag

§

impl Unpin for Tag

§

impl UnwindSafe for Tag

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.