Struct oid_registry::OidRegistry

source ·
pub struct OidRegistry<'a> { /* private fields */ }
Expand description

Registry of known OIDs

Use OidRegistry::default() to create an empty registry. If the corresponding features have been selected, the with_xxx() methods can be used to add sets of known objets to the database.

§Example

use asn1_rs::{oid, Oid};
use oid_registry::{OidEntry, OidRegistry};

let mut registry = OidRegistry::default()
    .with_crypto() // only if the 'crypto' feature is enabled
;

// entries can be added by creating an OidEntry object:
let entry = OidEntry::new("shortName", "description");
registry.insert(oid!(1.2.3.4), entry);

// when using static strings, a tuple can also be used directly for the entry:
registry.insert(oid!(1.2.3.5), ("shortName", "A description"));

// To query an entry, use the `get` method:
const OID_1234: Oid<'static> = oid!(1.2.3.4);
let e = registry.get(&OID_1234);
assert!(e.is_some());
if let Some(e) = e {
    assert_eq!(e.sn(), "shortName");
}

Implementations§

source§

impl<'a> OidRegistry<'a>

source

pub fn insert<E>(&mut self, oid: Oid<'a>, entry: E) -> Option<OidEntry>
where E: Into<OidEntry>,

Insert a new entry

source

pub fn get(&self, oid: &Oid<'a>) -> Option<&OidEntry>

Returns a reference to the registry entry, if found for this OID.

source

pub fn keys(&self) -> impl Iterator<Item = &Oid<'a>>

Return an Iterator over references to the OID numbers (registry keys)

source

pub fn values(&self) -> impl Iterator<Item = &OidEntry>

Return an Iterator over references to the OidEntry values

source

pub fn iter(&self) -> impl Iterator<Item = (&Oid<'a>, &OidEntry)>

Return an Iterator over references to the (Oid, OidEntry) key/value pairs

source

pub fn iter_by_sn<S: Into<String>>( &self, sn: S, ) -> impl Iterator<Item = (&Oid<'a>, &OidEntry)>

Return the (Oid, OidEntry) key/value pairs, matching a short name

The registry should not contain entries with same short name to avoid ambiguity, but it is not mandatory.

This function returns an iterator over the key/value pairs. In most cases, it will have 0 (not found) or 1 item, but can contain more if there are multiple definitions.

// iterate all entries matching "shortName"
for (oid, entry) in registry.iter_by_sn("shortName") {
    // do something
}

// if you are *sure* that there is at most one entry:
let opt_sn = registry.iter_by_sn("shortName").next();
if let Some((oid, entry)) = opt_sn {
    // do something
}
source

pub fn with_crypto(self) -> Self

Available on crate feature crypto only.

Populate registry with common crypto OIDs (encryption, hash algorithms)

source

pub fn with_all_crypto(self) -> Self

Available on crate feature crypto only.

Populate registry with all known crypto OIDs (encryption, hash algorithms, PKCS constants, etc.)

source§

impl<'a> OidRegistry<'a>

source

pub fn with_kdf(self) -> Self

Available on crate features registry and kdf only.

Load all known OIDs for feature kdf in the registry.

source

pub fn with_ms_spc(self) -> Self

Available on crate features registry and ms_spc only.

Load all known OIDs for feature ms_spc in the registry.

source

pub fn with_nist_algs(self) -> Self

Available on crate features registry and nist_algs only.

Load all known OIDs for feature nist_algs in the registry.

source

pub fn with_pkcs1(self) -> Self

Available on crate features registry and pkcs1 only.

Load all known OIDs for feature pkcs1 in the registry.

source

pub fn with_pkcs12(self) -> Self

Available on crate features registry and pkcs12 only.

Load all known OIDs for feature pkcs12 in the registry.

source

pub fn with_pkcs7(self) -> Self

Available on crate features registry and pkcs7 only.

Load all known OIDs for feature pkcs7 in the registry.

source

pub fn with_pkcs9(self) -> Self

Available on crate features registry and pkcs9 only.

Load all known OIDs for feature pkcs9 in the registry.

source

pub fn with_x500(self) -> Self

Available on crate features registry and x500 only.

Load all known OIDs for feature x500 in the registry.

source

pub fn with_x509(self) -> Self

Available on crate features registry and x509 only.

Load all known OIDs for feature x509 in the registry.

source

pub fn with_x962(self) -> Self

Available on crate features registry and x962 only.

Load all known OIDs for feature x962 in the registry.

Trait Implementations§

source§

impl<'a> Debug for OidRegistry<'a>

source§

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

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

impl<'a> Default for OidRegistry<'a>

source§

fn default() -> OidRegistry<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for OidRegistry<'a>

§

impl<'a> RefUnwindSafe for OidRegistry<'a>

§

impl<'a> Send for OidRegistry<'a>

§

impl<'a> Sync for OidRegistry<'a>

§

impl<'a> Unpin for OidRegistry<'a>

§

impl<'a> UnwindSafe for OidRegistry<'a>

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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