Struct const_oid::ObjectIdentifier
source · pub struct ObjectIdentifier<B: AsRef<[u8]> = Buffer<MAX_SIZE>> { /* private fields */ }
Expand description
Object identifier (OID).
OIDs are hierarchical structures consisting of “arcs”, i.e. integer identifiers.
Validity
In order for an OID to be considered valid by this library, it must meet the following criteria:
- The OID MUST have at least 3 arcs
- The first arc MUST be within the range 0-2
- The second arc MUST be within the range 0-39
- The BER/DER encoding of the OID MUST be shorter than
ObjectIdentifier::MAX_SIZE
Implementations§
source§impl<'a> ObjectIdentifier<&'a [u8]>
impl<'a> ObjectIdentifier<&'a [u8]>
sourcepub const fn from_bytes_unchecked(buffer: &'a [u8]) -> Self
pub const fn from_bytes_unchecked(buffer: &'a [u8]) -> Self
Initialize OID from a byte slice without validating that it contains a well-formed BER-encoded OID.
Use with care, e.g. to define compact constants.
source§impl ObjectIdentifier
impl ObjectIdentifier
Buffer
-backed ObjectIdentifier
methods.
sourcepub const fn new_unwrap(s: &str) -> Self
pub const fn new_unwrap(s: &str) -> Self
Parse an ObjectIdentifier
from the dot-delimited string form,
panicking on parse errors.
This function exists as a workaround for unwrap
not yet being
stable in const fn
contexts, and is intended to allow the result to
be bound to a constant value:
use const_oid::ObjectIdentifier;
pub const MY_OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.1");
In future versions of Rust it should be possible to replace this with
ObjectIdentifier::new(...).unwrap()
.
Use ObjectIdentifier::new
for fallible parsing.
sourcepub const fn new(s: &str) -> Result<Self>
pub const fn new(s: &str) -> Result<Self>
Parse an ObjectIdentifier
from the dot-delimited string form.
sourcepub fn from_arcs(arcs: impl IntoIterator<Item = Arc>) -> Result<Self>
pub fn from_arcs(arcs: impl IntoIterator<Item = Arc>) -> Result<Self>
Parse an OID from a slice of Arc
values (i.e. integers).
sourcepub fn from_bytes(ber_bytes: &[u8]) -> Result<Self>
pub fn from_bytes(ber_bytes: &[u8]) -> Result<Self>
Parse an OID from from its BER/DER encoding.
source§impl<B> ObjectIdentifier<B>where
B: AsRef<[u8]>,
impl<B> ObjectIdentifier<B>where B: AsRef<[u8]>,
Generic ObjectIdentifier
methods that work for any buffer.
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Get the BER/DER serialization of this OID as bytes.
Note that this encoding omits the tag/length, and only contains the value portion of the encoded OID.
sourcepub fn arc(&self, index: usize) -> Option<Arc>
pub fn arc(&self, index: usize) -> Option<Arc>
Return the arc with the given index, if it exists.
sourcepub fn arcs(&self) -> Arcs<'_> ⓘ
pub fn arcs(&self) -> Arcs<'_> ⓘ
Iterate over the arcs (a.k.a. nodes) of an ObjectIdentifier
.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the length of this ObjectIdentifier
in arcs.
sourcepub fn starts_with<A>(&self, other: ObjectIdentifier<A>) -> boolwhere
A: AsRef<[u8]>,
pub fn starts_with<A>(&self, other: ObjectIdentifier<A>) -> boolwhere A: AsRef<[u8]>,
Does this OID start with the other OID?
sourcepub fn to_ref(&self) -> ObjectIdentifierRef<'_>
pub fn to_ref(&self) -> ObjectIdentifierRef<'_>
Get an ObjectIdentifierRef
which borrows from self.
Trait Implementations§
source§impl<'a> Arbitrary<'a> for ObjectIdentifier
Available on crate feature arbitrary
only.
impl<'a> Arbitrary<'a> for ObjectIdentifier
arbitrary
only.source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self
from the given unstructured data. Read moresource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured
this type
needs to construct itself. Read moresource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self
from the entirety of the given
unstructured data. Read moresource§impl<B: Clone + AsRef<[u8]>> Clone for ObjectIdentifier<B>
impl<B: Clone + AsRef<[u8]>> Clone for ObjectIdentifier<B>
source§fn clone(&self) -> ObjectIdentifier<B>
fn clone(&self) -> ObjectIdentifier<B>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl FromStr for ObjectIdentifier
impl FromStr for ObjectIdentifier
source§impl<B: Ord + AsRef<[u8]>> Ord for ObjectIdentifier<B>
impl<B: Ord + AsRef<[u8]>> Ord for ObjectIdentifier<B>
source§fn cmp(&self, other: &ObjectIdentifier<B>) -> Ordering
fn cmp(&self, other: &ObjectIdentifier<B>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<A, B> PartialEq<ObjectIdentifier<A>> for ObjectIdentifier<B>where
A: AsRef<[u8]>,
B: AsRef<[u8]>,
impl<A, B> PartialEq<ObjectIdentifier<A>> for ObjectIdentifier<B>where A: AsRef<[u8]>, B: AsRef<[u8]>,
source§fn eq(&self, other: &ObjectIdentifier<A>) -> bool
fn eq(&self, other: &ObjectIdentifier<A>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<B: PartialOrd + AsRef<[u8]>> PartialOrd for ObjectIdentifier<B>
impl<B: PartialOrd + AsRef<[u8]>> PartialOrd for ObjectIdentifier<B>
source§fn partial_cmp(&self, other: &ObjectIdentifier<B>) -> Option<Ordering>
fn partial_cmp(&self, other: &ObjectIdentifier<B>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more