README.md
1<!-- cargo-sync-readme start -->
2
3[](./LICENSE-MIT)
4[](./LICENSE-APACHE)
5[](https://docs.rs/oid-registry)
6[](https://crates.io/crates/oid-registry)
7[](https://github.com/rusticata/oid-registry/actions)
8[](#rust-version-requirements)
9# OID Registry
10
11This crate is a helper crate, containing a database of OID objects. These objects are intended
12for use when manipulating ASN.1 grammars and BER/DER encodings, for example.
13
14This crate provides only a simple registry (similar to a `HashMap`) by default. This object can
15be used to get names and descriptions from OID.
16
17This crate provides default lists of known OIDs, that can be selected using the build features.
18By default, the registry has no feature enabled, to avoid embedding a huge database in crates.
19
20It also declares constants for most of these OIDs.
21
22```rust
23use oid_registry::OidRegistry;
24
25let mut registry = OidRegistry::default()
26 .with_crypto() // only if the 'crypto' feature is enabled
27;
28
29let e = registry.get(&oid_registry::OID_PKCS1_SHA256WITHRSA);
30if let Some(entry) = e {
31 // get sn: sha256WithRSAEncryption
32 println!("sn: {}", entry.sn());
33 // get description: SHA256 with RSA encryption
34 println!("description: {}", entry.description());
35}
36
37```
38
39## Extending the registry
40
41These provided lists are often incomplete, or may lack some specific OIDs.
42This is why the registry allows adding new entries after construction:
43
44```rust
45use oid_registry::{OidEntry, OidRegistry};
46use der_parser::oid;
47
48let mut registry = OidRegistry::default();
49
50// entries can be added by creating an OidEntry object:
51let entry = OidEntry::new("shortName", "description");
52registry.insert(oid!(1.2.3.4), entry);
53
54// when using static strings, a tuple can also be used directly for the entry:
55registry.insert(oid!(1.2.3.5), ("shortName", "A description"));
56
57```
58
59## Contributing OIDs
60
61All OID values, constants, and features are derived from files in the `assets` directory in the
62build script (see `build.rs`).
63See `load_file` for documentation of the file format.
64<!-- cargo-sync-readme end -->
65
66## Rust version requirements
67
68`oid-registry` requires **Rustc version 1.45 or greater**, based on proc-macro
69attributes support.
70
71# License
72
73Licensed under either of
74
75 * Apache License, Version 2.0
76 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
77 * MIT license
78 ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
79
80at your option.
81
82## Contribution
83
84Unless you explicitly state otherwise, any contribution intentionally submitted
85for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
86dual licensed as above, without any additional terms or conditions.
87