pub struct Oid<T = Bytes>(pub T)
where
    T: AsRef<[u8]>;
Expand description

An object identifer.

Object identifiers are globally unique, hierarchical values that are used to identify objects or their type. When written, they are presented as a sequence of integers separated by dots such as ‘1.3.6.1.5.5.7.1’ or with the integers separated by white space and enclosed in curly braces such as ‘{ 1 3 6 1 5 5 7 1 }’. Individual integers or sequences of integers can also be given names which then are used instead of the integers.

Values of this type keep a single object identifer in its BER encoding, i.e., in some form of byte sequence. Because different representations may be useful, the type is actually generic over something that can become a reference to a bytes slice. Parsing is only defined for Bytes values, though.

The only use for object identifiers currently is to compare them to predefined values. For this purpose, you typically define your known object identifiers in a oid submodule as contants of Oid<&'static [u8]> – or its type alias ConstOid. This is also the reason why the wrapped value is pub for now. This will change once const fn is stable.

Unfortunately, there is currently no proc macro to generate the object identifier constants in the code. Instead, the crate ships with a mkoid binary which accepts object identifiers in ‘dot integer’ notation and produces the u8 array for their encoded value. You can install this binary via cargo install ber.

Tuple Fields§

§0: T

Implementations§

source§

impl Oid

source

pub fn skip_in<S>( cons: &mut Constructed<'_, S> ) -> Result<(), DecodeError<<S as Source>::Error>>
where S: Source,

Skips over an object identifier value.

If the source has reached its end, if the next value does not have the Tag::OID, or if it is not a primitive value containing a correctly encoded OID, returns a malformed error.

source

pub fn skip_opt_in<S>( cons: &mut Constructed<'_, S> ) -> Result<Option<()>, DecodeError<<S as Source>::Error>>
where S: Source,

Skips over an optional object identifier value.

If the source has reached its end of if the next value does not have the Tag::OID, returns Ok(None). If the next value has the right tag but is not a primitive value containing a correctly encoded OID, returns a malformed error.

source

pub fn take_from<S>( constructed: &mut Constructed<'_, S> ) -> Result<Oid, DecodeError<<S as Source>::Error>>
where S: Source,

Takes an object identifier value from the source.

If the source has reached its end, if the next value does not have the Tag::OID, or if it is not a primitive value, returns a malformed error.

source

pub fn take_opt_from<S>( constructed: &mut Constructed<'_, S> ) -> Result<Option<Oid>, DecodeError<<S as Source>::Error>>
where S: Source,

Takes an optional object identifier value from the source.

If the source has reached its end of if the next value does not have the Tag::OID, returns Ok(None). If the next value has the right tag but is not a primitive value, returns a malformed error.

source

pub fn skip_primitive<S>( prim: &mut Primitive<'_, S> ) -> Result<(), DecodeError<<S as Source>::Error>>
where S: Source,

Skips an object identifier in the content of a primitive value.

source

pub fn from_primitive<S>( prim: &mut Primitive<'_, S> ) -> Result<Oid, DecodeError<<S as Source>::Error>>
where S: Source,

Constructs an object identifier from the content of a primitive value.

source§

impl<T> Oid<T>
where T: AsRef<[u8]>,

source

pub fn skip_if<S>( &self, constructed: &mut Constructed<'_, S> ) -> Result<(), DecodeError<<S as Source>::Error>>
where S: Source,

Skip over an object identifier if it matches self.

source§

impl<T> Oid<T>
where T: AsRef<[u8]>,

source

pub fn iter(&self) -> Iter<'_>

Returns an iterator to the components of this object identifiers.

Panics

The returned identifier will eventually panic if self does not contain a correctly encoded object identifier.

Trait Implementations§

source§

impl<T> AsRef<[u8]> for Oid<T>
where T: AsRef<[u8]>,

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> Clone for Oid<T>
where T: Clone + AsRef<[u8]>,

source§

fn clone(&self) -> Oid<T>

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<T> Debug for Oid<T>
where T: Debug + AsRef<[u8]>,

source§

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

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

impl<T> Display for Oid<T>
where T: AsRef<[u8]>,

source§

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

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

impl From<DigestAlgorithm> for Oid

source§

fn from(alg: DigestAlgorithm) -> Oid

Converts to this type from the input type.
source§

impl From<KeyAlgorithm> for Oid

source§

fn from(alg: KeyAlgorithm) -> Oid

Converts to this type from the input type.
source§

impl From<SignatureAlgorithm> for Oid

source§

fn from(alg: SignatureAlgorithm) -> Oid

Converts to this type from the input type.
source§

impl<T> FromStr for Oid<T>
where T: AsRef<[u8]> + From<Vec<u8>>,

§

type Err = &'static str

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Oid<T>, <Oid<T> as FromStr>::Err>

Parses a string s to return a value of this type. Read more
source§

impl<T> Hash for Oid<T>
where T: AsRef<[u8]>,

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T, U> PartialEq<Oid<U>> for Oid<T>
where T: AsRef<[u8]>, U: AsRef<[u8]>,

source§

fn eq(&self, other: &Oid<U>) -> 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<T> PrimitiveContent for Oid<T>
where T: AsRef<[u8]>,

source§

const TAG: Tag = Tag::OID

The natural tag of an encoded value of this type.
source§

fn encoded_len(&self, _: Mode) -> usize

Returns the length of the encoded content of this type.
source§

fn write_encoded<W>(&self, _: Mode, target: &mut W) -> Result<(), Error>
where W: Write,

Writes the encoded content to a writer.
source§

fn to_encoded_bytes(&self, mode: Mode) -> Bytes

Encodes the value to bytes (useful when you need to sign a structure)
source§

fn encode(self) -> Primitive<Self>

Returns a value encoder for this content using the natural tag. Read more
source§

fn encode_as(self, tag: Tag) -> Primitive<Self>

Returns a value encoder for this content using the given tag. Read more
source§

fn encode_ref(&self) -> Primitive<&Self>

Returns a value encoder for a reference using the natural tag.
source§

fn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>

Returns a value encoder for a reference using the given tag.
source§

impl<T> Eq for Oid<T>
where T: AsRef<[u8]>,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Oid<T>
where T: RefUnwindSafe,

§

impl<T> Send for Oid<T>
where T: Send,

§

impl<T> Sync for Oid<T>
where T: Sync,

§

impl<T> Unpin for Oid<T>
where T: Unpin,

§

impl<T> UnwindSafe for Oid<T>
where T: UnwindSafe,

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToHex for T
where T: AsRef<[u8]>,

source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
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> ToString for T
where T: Display + ?Sized,

source§

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

§

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more