Crate oid_registry

source ·
Expand description

License: MIT Apache License 2.0 docs.rs crates.io Github CI Minimum rustc version

§OID Registry

This crate is a helper crate, containing a database of OID objects. These objects are intended for use when manipulating ASN.1 grammars and BER/DER encodings, for example.

This crate provides only a simple registry (similar to a HashMap) by default. This object can be used to get names and descriptions from OID.

This crate provides default lists of known OIDs, that can be selected using the build features. By default, the registry has no feature enabled, to avoid embedding a huge database in crates.

It also declares constants for most of these OIDs.

use oid_registry::OidRegistry;

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

let e = registry.get(&oid_registry::OID_PKCS1_SHA256WITHRSA);
if let Some(entry) = e {
    // get sn: sha256WithRSAEncryption
    println!("sn: {}", entry.sn());
    // get description: SHA256 with RSA encryption
    println!("description: {}", entry.description());
}

§Extending the registry

These provided lists are often incomplete, or may lack some specific OIDs. This is why the registry allows adding new entries after construction:

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

let mut registry = OidRegistry::default();

// 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"));

§Versions and compatibility with asn1-rs

Versions of oid-registry must be chosen specifically, to depend on a precise version of asn1-rs. The following table summarizes the matching versions:

  • oid-registry 0.7.x depends on asn1-rs 0.6.0
  • oid-registry 0.6.x depends on asn1-rs 0.5.0
  • oid-registry 0.5.x depends on asn1-rs 0.4.0

§Contributing OIDs

All OID values, constants, and features are derived from files in the assets directory in the build script (see build.rs). See load_file for documentation of the file format.

Re-exports§

Structs§

  • Temporary structure, created when reading a file containing OID declarations
  • Object ID (OID) representation which can be relative or non-relative. An example for an OID in string representation is "1.2.840.113549.1.1.5".
  • An entry stored in the OID registry
  • Registry of known OIDs

Constants§

Functions§

  • Format a OID to a String, using the provided registry to get the short name if present.
  • Generate a file containing a with_<feat> method for OidRegistry
  • Load a file to an OID description map

Type Aliases§

  • Temporary structure, created when reading a file containing OID declarations