aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYiming Jing <yimingjing@google.com>2021-07-29 20:29:12 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-07-29 20:29:12 +0000
commit67449b272d0c0a1ede5a7b4d2a65e0de767e406c (patch)
tree32253837eb994169888da15e1420347cac82ab1a
parentd97449c10fa4821f84428882349a11f062ceeea8 (diff)
parente26ec07e6f22126865bf35b80413e86b18bb6524 (diff)
downloadoid-registry-67449b272d0c0a1ede5a7b4d2a65e0de767e406c.tar.gz
Initial import of oid-registry 0.1.4 am: a9f0d29527 am: b7b7778a46 am: e26ec07e6f
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/oid-registry/+/1775449 Change-Id: I476ddae5524bdf24f497a939e7a80b5ad879b769
-rw-r--r--.cargo_vcs_info.json5
-rw-r--r--.gitignore2
-rw-r--r--Cargo.toml43
-rw-r--r--Cargo.toml.orig42
l---------LICENSE1
-rw-r--r--LICENSE-APACHE201
-rw-r--r--LICENSE-MIT25
-rw-r--r--METADATA20
-rw-r--r--MODULE_LICENSE_APACHE20
-rw-r--r--OWNERS4
-rw-r--r--README.md86
-rw-r--r--assets/oid_db.txt147
-rw-r--r--build.rs15
-rw-r--r--src/lib.rs281
-rw-r--r--src/load.rs100
15 files changed, 972 insertions, 0 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
new file mode 100644
index 0000000..ff0e9a2
--- /dev/null
+++ b/.cargo_vcs_info.json
@@ -0,0 +1,5 @@
+{
+ "git": {
+ "sha1": "3b34fad1c1c5a63cb8231b8fe266f8c5c3d4fdb1"
+ }
+}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..96ef6c0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/target
+Cargo.lock
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..5b537b8
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,43 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies
+#
+# If you believe there's an error in this file please file an
+# issue against the rust-lang/cargo repository. If you're
+# editing this file be aware that the upstream Cargo.toml
+# will likely look very different (and much more reasonable)
+
+[package]
+edition = "2018"
+name = "oid-registry"
+version = "0.1.4"
+authors = ["Pierre Chifflier <chifflier@wzdftpd.net>"]
+build = "build.rs"
+include = ["LICENSE-*", "README.md", ".gitignore", "Cargo.toml", "assets/*.txt", "build.rs", "src/*.rs"]
+description = "Object Identifier (OID) database"
+homepage = "https://github.com/rusticata/oid-registry"
+readme = "README.md"
+keywords = ["BER", "DER", "OID"]
+license = "MIT/Apache-2.0"
+repository = "https://github.com/rusticata/oid-registry.git"
+[package.metadata.docs.rs]
+all-features = true
+rustdoc-args = ["--cfg", "docsrs"]
+[dependencies.der-parser]
+version = "5.1"
+
+[features]
+crypto = ["kdf", "pkcs1", "pkcs7", "pkcs9", "pkcs12", "nist_algs", "x962"]
+default = []
+kdf = []
+ms_spc = []
+nist_algs = []
+pkcs1 = []
+pkcs12 = []
+pkcs7 = []
+pkcs9 = []
+x509 = []
+x962 = []
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
new file mode 100644
index 0000000..0235cdf
--- /dev/null
+++ b/Cargo.toml.orig
@@ -0,0 +1,42 @@
+[package]
+name = "oid-registry"
+version = "0.1.4"
+authors = ["Pierre Chifflier <chifflier@wzdftpd.net>"]
+license = "MIT/Apache-2.0"
+description = "Object Identifier (OID) database"
+keywords = ["BER", "DER", "OID"]
+homepage = "https://github.com/rusticata/oid-registry"
+repository = "https://github.com/rusticata/oid-registry.git"
+edition = "2018"
+build = "build.rs"
+readme = "README.md"
+
+include = [
+ "LICENSE-*",
+ "README.md",
+ ".gitignore",
+ "Cargo.toml",
+ "assets/*.txt",
+ "build.rs",
+ "src/*.rs",
+]
+
+[package.metadata.docs.rs]
+all-features = true
+rustdoc-args = ["--cfg", "docsrs"]
+
+[features]
+default = []
+crypto = ["kdf","pkcs1","pkcs7","pkcs9","pkcs12","nist_algs","x962"]
+kdf = []
+ms_spc = []
+nist_algs = []
+pkcs1 = []
+pkcs7 = []
+pkcs9 = []
+pkcs12 = []
+x509 = []
+x962 = []
+
+[dependencies]
+der-parser = "5.1"
diff --git a/LICENSE b/LICENSE
new file mode 120000
index 0000000..6b579aa
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1 @@
+LICENSE-APACHE \ No newline at end of file
diff --git a/LICENSE-APACHE b/LICENSE-APACHE
new file mode 100644
index 0000000..16fe87b
--- /dev/null
+++ b/LICENSE-APACHE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644
index 0000000..290e7b9
--- /dev/null
+++ b/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2017 Pierre Chifflier
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..0ed645b
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,20 @@
+name: "oid-registry"
+description: "Object Identifier (OID) database"
+third_party {
+ url {
+ type: HOMEPAGE
+ value: "https://crates.io/crates/oid-registry"
+ }
+ url {
+ type: ARCHIVE
+ value: "https://static.crates.io/crates/oid-registry/oid-registry-0.1.4.crate"
+ }
+ version: "0.1.4"
+ # Dual-licensed, using the least restrictive per go/thirdpartylicenses#same.
+ license_type: NOTICE
+ last_upgrade_date {
+ year: 2021
+ month: 7
+ day: 16
+ }
+}
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..3f9a6ad
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,4 @@
+include platform/prebuilts/rust:master:/OWNERS
+# Android Auto
+skeys@google.com
+yimingjing@google.com
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..26da74f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,86 @@
+<!-- cargo-sync-readme start -->
+
+[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE-MIT)
+[![Apache License 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](./LICENSE-APACHE)
+[![docs.rs](https://docs.rs/oid-registry/badge.svg)](https://docs.rs/oid-registry)
+[![crates.io](https://img.shields.io/crates/v/oid-registry.svg)](https://crates.io/crates/oid-registry)
+[![Github CI](https://github.com/rusticata/oid-registry/workflows/Continuous%20integration/badge.svg)](https://github.com/rusticata/oid-registry/actions)
+[![Minimum rustc version](https://img.shields.io/badge/rustc-1.45.0+-lightgray.svg)](#rust-version-requirements)
+# 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.
+
+```rust
+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:
+
+```rust
+use oid_registry::{OidEntry, OidRegistry};
+use der_parser::oid;
+
+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"));
+
+```
+
+## 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.
+<!-- cargo-sync-readme end -->
+
+## Rust version requirements
+
+`oid-registry` requires **Rustc version 1.45 or greater**, based on proc-macro
+attributes support.
+
+# License
+
+Licensed under either of
+
+ * Apache License, Version 2.0
+ ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
+ * MIT license
+ ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
+
+at your option.
+
+## Contribution
+
+Unless you explicitly state otherwise, any contribution intentionally submitted
+for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
+dual licensed as above, without any additional terms or conditions.
diff --git a/assets/oid_db.txt b/assets/oid_db.txt
new file mode 100644
index 0000000..32540f0
--- /dev/null
+++ b/assets/oid_db.txt
@@ -0,0 +1,147 @@
+#
+# format: tab-separated values
+# <feature> <name> <oid> <short name> <description>
+#
+# if <name> is "" then no constant will be written
+#
+
+x509 OID_DOMAIN_COMPONENT 0.9.2342.19200300.100.1.25 domainComponent Domain component
+
+x962 OID_KEY_TYPE_EC_PUBLIC_KEY 1.2.840.10045.2.1 id-ecPublicKey Elliptic curve public key cryptography
+
+x962 OID_SIG_ECDSA_WITH_SHA224 1.2.840.10045.4.3.1 ecdsa-with-SHA224 Elliptic curve Digital Signature Algorithm (DSA) coupled with the Secure Hash Algorithm 224 (SHA224) algorithm
+x962 OID_SIG_ECDSA_WITH_SHA256 1.2.840.10045.4.3.2 ecdsa-with-SHA256 Elliptic curve Digital Signature Algorithm (DSA) coupled with the Secure Hash Algorithm 256 (SHA256) algorithm
+x962 OID_SIG_ECDSA_WITH_SHA384 1.2.840.10045.4.3.3 ecdsa-with-SHA384 Elliptic curve Digital Signature Algorithm (DSA) coupled with the Secure Hash Algorithm 384 (SHA384) algorithm
+
+pkcs1 OID_PKCS1_RSAENCRYPTION 1.2.840.113549.1.1.1 rsaEncryption RSAES-PKCS1-v1_5 encryption scheme
+pkcs1 OID_PKCS1_MD2WITHRSAENC 1.2.840.113549.1.1.2 md2WithRSAEncryption MD2 with RSA encryption
+pkcs1 OID_PKCS1_MD4WITHRSAENC 1.2.840.113549.1.1.3 md4WithRSAEncryption MD4 with RSA encryption
+pkcs1 OID_PKCS1_MD5WITHRSAENC 1.2.840.113549.1.1.4 md5WithRSAEncryption MD5 with RSA encryption
+pkcs1 OID_PKCS1_SHA1WITHRSA 1.2.840.113549.1.1.5 sha1WithRSAEncryption SHA1 with RSA encryption
+
+pkcs1 OID_PKCS1_RSASSAPSS 1.2.840.113549.1.1.10 rsassa-pss RSA Signature Scheme with Probabilistic Signature Scheme (RSASSA-PSS)
+pkcs1 OID_PKCS1_SHA256WITHRSA 1.2.840.113549.1.1.11 sha256WithRSAEncryption SHA256 with RSA encryption
+pkcs1 OID_PKCS1_SHA384WITHRSA 1.2.840.113549.1.1.12 sha384WithRSAEncryption SHA384 with RSA encryption
+pkcs1 OID_PKCS1_SHA512WITHRSA 1.2.840.113549.1.1.13 sha512WithRSAEncryption SHA512 with RSA encryption
+pkcs1 OID_PKCS1_SHA224WITHRSA 1.2.840.113549.1.1.14 sha224WithRSAEncryption SHA224 with RSA encryption
+
+pkcs7 OID_PKCS7_ID_DATA 1.2.840.113549.1.7.1 pkcs7-data pkcs7-data
+pkcs7 OID_PKCS7_ID_SIGNED_DATA 1.2.840.113549.1.7.2 pkcs7-signedData PKCS#7 Signed Data
+pkcs7 OID_PKCS7_ID_ENVELOPED_DATA 1.2.840.113549.1.7.3 pkcs7-envelopedData PKCS#7 Enveloped Data
+pkcs7 OID_PKCS7_ID_SIGNED_ENVELOPED_DATA 1.2.840.113549.1.7.4 pkcs7-signedAndEnvelopedData PKCS#7 Signed and Enveloped Data
+pkcs7 OID_PKCS7_ID_DIGESTED_DATA 1.2.840.113549.1.7.5 pkcs7-digestedData PKCS#7 Digested Data
+pkcs7 OID_PKCS7_ID_ENCRYPTED_DATA 1.2.840.113549.1.7.6 pkcs7-encryptedData PKCS#7 Encrypted Data
+
+pkcs9 OID_PKCS9_EMAIL_ADDRESS 1.2.840.113549.1.9.1 emailAddress Email Address attribute for use in signatures
+pkcs9 OID_PKCS9_UNSTRUCTURED_NAME 1.2.840.113549.1.9.2 unstructuredName PKCS#9 unstructuredName
+pkcs9 OID_PKCS9_CONTENT_TYPE 1.2.840.113549.1.9.3 contentType id-contentType
+pkcs9 OID_PKCS9_ID_MESSAGE_DIGEST 1.2.840.113549.1.9.4 id-messageDigest id-messageDigest
+pkcs9 OID_PKCS9_SIGNING_TIME 1.2.840.113549.1.9.5 signing-time id-signingTime
+
+pkcs9 OID_PKCS9_EXTENSION_REQUEST 1.2.840.113549.1.9.14 extensionRequest Extension list for Certification Requests
+pkcs9 OID_PKCS9_SMIME_CAPABILITIES 1.2.840.113549.1.9.15 smimeCapabilities aa-smimeCapabilities
+
+pkcs12 OID_PKCS12 1.2.840.113549.1.12 pkcs-12 Public-Key Cryptography Standard (PKCS) #12
+pkcs12 OID_PKCS12_PBEIDS 1.2.840.113549.1.12.1 pkcs-12PbeIds PKCS #12 Password Based Encryption IDs
+pkcs12 OID_PKCS12_PBE_SHA1_128RC4 1.2.840.113549.1.12.1.1 pbeWithSHAAnd128BitRC4 PKCS #12 Password Based Encryption With SHA-1 and 128-bit RC4
+pkcs12 OID_PKCS12_PBE_SHA1_40RC4 1.2.840.113549.1.12.1.2 pbeWithSHAAnd40BitRC4 PKCS #12 Password Based Encryption With SHA-1 and 40-bit RC4
+pkcs12 OID_PKCS12_PBE_SHA1_3K_3DES_CBC 1.2.840.113549.1.12.1.3 pbeWithSHAAnd3-KeyTripleDES-CBC PKCS #12 Password Based Encryption With SHA-1 and 3-key Triple DES in CBC mode
+pkcs12 OID_PKCS12_PBE_SHA1_2K_3DES_CBC 1.2.840.113549.1.12.1.4 pbeWithSHAAnd2-KeyTripleDES-CBC PKCS #12 Password Based Encryption With SHA-1 and 2-key Triple DES in CBC mode
+pkcs12 OID_PKCS12_PBE_SHA1_128RC2_CBC 1.2.840.113549.1.12.1.5 pbeWithSHAAnd128BitRC2-CBC PKCS #12 Password Based Encryption With SHA-1 and 128-bit RC2-CBC
+pkcs12 OID_PKCS12_PBE_SHA1_40RC2_CBC 1.2.840.113549.1.12.1.6 pbeWithSHAAnd40BitRC2-CBC PKCS #12 Password Based Encryption With SHA-1 and 40-bit RC2-CBC
+
+x509 OID_SIG_ED25519 1.3.101.112 ed25519 Edwards-curve Digital Signature Algorithm (EdDSA) Ed25519
+
+kdf OID_KDF_SHA1_SINGLE 1.3.133.16.840.63.0.2 dhSinglePass-stdDH-sha1kdf-scheme Single pass Secure Hash Algorithm 1 (SHA1) key derivation
+
+ms-spc SPC_INDIRECT_DATA_OBJID 1.3.6.1.4.1.311.2.1.4 spcIndirectData The SPC_INDIRECT_DATA_CONTENT structure is used in Authenticode signatures to store the digest and other attributes of the signed file
+ms-spc SPC_STATEMENT_TYPE_OBJID 1.3.6.1.4.1.311.2.1.11 spcStatementType spcStatementType
+ms-spc SPC_SP_OPUS_INFO_OBJID 1.3.6.1.4.1.311.2.1.12 spcSpOpusInfo SpcSpOpusInfo
+ms-spc SPC_PE_IMAGE_DATA 1.3.6.1.4.1.311.2.1.15 spcPEImageData spcPEImageData
+ms-spc SPC_INDIVIDUAL_SP_KEY_PURPOSE_OBJID 1.3.6.1.4.1.311.2.1.21 msCodeInd MsCodeInd (SPC_INDIVIDUAL_SP_KEY_PURPOSE_OBJID) is a ExtendedKeyUsage for Certificate Extensions which indicates Microsoft Individual Code Signing (authenticode)
+
+ms-spc MS_CTL 1.3.6.1.4.1.311.10.1 szOID_CTL MS_CTL
+
+# Certificate Transparency: https://tools.ietf.org/html/rfc6962#section-3.3
+x509 OID_CT_LIST_SCT 1.3.6.1.4.1.11129.2.4.2 ctSCTList Certificate Transparency Signed Certificate Timestamp List
+
+# PKIX Certificate Extension
+# https://www.iana.org/assignments/smi-numbers/smi-numbers.xhtml#smi-numbers-1.3.6.1.5.5.7.1
+x509 OID_PKIX_AUTHORITY_INFO_ACCESS 1.3.6.1.5.5.7.1.1 authorityInfoAccess Certificate Authority Information Access
+
+# PKIX Access Descriptor
+# https://www.iana.org/assignments/smi-numbers/smi-numbers.xhtml#smi-numbers-1.3.6.1.5.5.7.48
+x509 OID_PKIX_ACCESS_DESCRIPTOR_OCSP 1.3.6.1.5.5.7.48.1 id-ad-ocsp PKIX Access Descriptor OCSP
+x509 OID_PKIX_ACCESS_DESCRIPTOR_CA_ISSUERS 1.3.6.1.5.5.7.48.2 id-ad-caIssuers PKIX Access Descriptor CA Issuers
+x509 OID_PKIX_ACCESS_DESCRIPTOR_TIMESTAMPING 1.3.6.1.5.5.7.48.3 id-ad-timestamping PKIX Access Descriptor Timestamping
+x509 OID_PKIX_ACCESS_DESCRIPTOR_DVCS 1.3.6.1.5.5.7.48.4 id-ad-dvcs PKIX Access Descriptor DVCS
+x509 OID_PKIX_ACCESS_DESCRIPTOR_CA_REPOSITORY 1.3.6.1.5.5.7.48.5 id-ad-caRepository PKIX Access Descriptor CA Repository
+x509 OID_PKIX_ACCESS_DESCRIPTOR_HTTP_CERTS 1.3.6.1.5.5.7.48.6 id-ad-http-certs PKIX Access Descriptor HTTP Certificates
+x509 OID_PKIX_ACCESS_DESCRIPTOR_HTTP_CRLS 1.3.6.1.5.5.7.48.7 id-ad-http-crls PKIX Access Descriptor HTTP Certificate Revocation Lists
+#
+x509 OID_PKIX_ACCESS_DESCRIPTOR_RPKI_MANIFEST 1.3.6.1.5.5.7.48.10 id-ad-rpki-manifest PKIX Access Descriptor RPKI Manifest
+x509 OID_PKIX_ACCESS_DESCRIPTOR_SIGNED_OBJECT 1.3.6.1.5.5.7.48.11 id-ad-signed-object PKIX Access Descriptor Signed Object
+x509 OID_PKIX_ACCESS_DESCRIPTOR_CMC 1.3.6.1.5.5.7.48.12 id-ad-cmc PKIX Access Descriptor CMC
+x509 OID_PKIX_ACCESS_DESCRIPTOR_RPKI_NOTIFY 1.3.6.1.5.5.7.48.13 id-ad-rpki-notify PKIX Access Descriptor RPKI Notify
+x509 OID_PKIX_ACCESS_DESCRIPTOR_STIRTNLIST 1.3.6.1.5.5.7.48.14 id-ad-stirTNList PKIX Access Descriptor STIRTNLIST
+
+nist-algs OID_HASH_SHA1 1.3.14.3.2.26 id-SHA1 SHA-1 hash algorithm
+
+x500 OID_X500 2.5 x500 X.500
+x509 OID_X509 2.5.4 x509 X.509
+x509 OID_X509_OBJECT_CLASS 2.5.4.0 objectClass Object classes
+x509 OID_X509_ALIASED_ENTRY_NAME 2.5.4.1 aliasedEntryName Aliased entry/object name
+x509 OID_X509_KNOWLEDGE_INFORMATION 2.5.4.2 knowledgeInformation 'knowledgeInformation' attribute type
+x509 OID_X509_COMMON_NAME 2.5.4.3 commonName Common Name
+x509 OID_X509_SURNAME 2.5.4.4 surname Surname
+x509 OID_X509_COUNTRY_NAME 2.5.4.6 countryName Country Name
+x509 OID_X509_LOCALITY_NAME 2.5.4.7 localityName Locality Name
+x509 OID_X509_STATE_OR_PROVINCE_NAME 2.5.4.8 stateOrProvinceName State or Province name
+x509 OID_X509_STREET_ADDRESS 2.5.4.9 streetAddress Street Address
+x509 OID_X509_ORGANIZATION_NAME 2.5.4.10 organizationName Organization Name
+x509 OID_X509_ORGANIZATIONAL_UNIT 2.5.4.11 organizationalUnit Organizational Unit
+x509 OID_X509_TITLE 2.5.4.12 title Title
+x509 OID_X509_DESCRIPTION 2.5.4.13 description Description
+x509 OID_X509_SEARCH_GUIDE 2.5.4.14 searchGuide Search Guide
+x509 OID_X509_BUSINESS_CATEGORY 2.5.4.15 businessCategory Business Category
+x509 OID_X509_POSTAL_ADDRESS 2.5.4.16 postalAddress Postal Address
+x509 OID_X509_POSTAL_CODE 2.5.4.17 postalCode Postal Code
+#
+x509 OID_X509_GIVEN_NAME 2.5.4.42 givenName Given Name
+#
+x509 OID_X509_UNIQUE_IDENTIFIER 2.5.4.45 uniqueIdentifier Bit String Unique Identifier
+
+# https://www.alvestrand.no/objectid/2.5.29.html
+x509 OID_X509_EXT_SUBJECT_KEY_IDENTIFIER 2.5.29.14 subjectKeyIdentifier X509v3 Subject Key Identifier
+x509 OID_X509_EXT_KEY_USAGE 2.5.29.15 keyUsage X509v3 Key Usage
+x509 OID_X509_EXT_PRIVATE_KEY_USAGE_PERIOD 2.5.29.16 privateKeyUsagePeriod X509v3 Private Key Usage Period
+x509 OID_X509_EXT_SUBJECT_ALT_NAME 2.5.29.17 subjectAltName X509v3 Subject Alternative Name
+x509 OID_X509_EXT_ISSUER_ALT_NAME 2.5.29.18 issuerAltName X509v3 Issuer Alternative Name
+x509 OID_X509_EXT_BASIC_CONSTRAINTS 2.5.29.19 basicConstraints X509v3 Basic Constraints
+x509 OID_X509_EXT_CRL_NUMBER 2.5.29.20 crlNumber X509v3 CRL Number
+x509 OID_X509_EXT_REASON_CODE 2.5.29.21 reasonCode X509v3 Reason Code
+# no 2.5.29.22
+x509 OID_X509_EXT_HOLD_INSTRUCTION_CODE 2.5.29.23 holdInstructionCode X509v3 Hold Instruction Code
+x509 OID_X509_EXT_INVALIDITY_DATE 2.5.29.24 invalidityDate X509v3 Invalidity Date
+# no 2.5.29.25 2.5.29.26
+x509 OID_X509_EXT_DELTA_CRL_INDICATOR 2.5.29.27 deltaCRLIndicator X509v3 Delta CRL Indicator
+x509 OID_X509_EXT_ISSUER_DISTRIBUTION_POINT 2.5.29.28 issuerDistributionPoint X509v3 Issuer Distribution Point
+x509 OID_X509_EXT_ISSUER 2.5.29.29 issuer X509v3 Issuer
+x509 OID_X509_EXT_NAME_CONSTRAINTS 2.5.29.30 nameConstraints X509v3 Name Constraints
+x509 OID_X509_EXT_CRL_DISTRIBUTION_POINTS 2.5.29.31 crlDistributionPoints X509v3 CRL Distribution Points
+x509 OID_X509_EXT_CERTIFICATE_POLICIES 2.5.29.32 certificatePolicies X509v3 Certificate Policies
+x509 OID_X509_EXT_POLICY_MAPPINGS 2.5.29.33 policyMappings X509v3 Policy Mappings
+# no 2.5.29.34
+x509 OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER 2.5.29.35 authorityKeyIdentifier X509v3 Authority Key Identifier
+x509 OID_X509_EXT_POLICY_CONSTRAINTS 2.5.29.36 policyConstraints X509v3 Policy Constraints
+x509 OID_X509_EXT_EXTENDED_KEY_USAGE 2.5.29.37 extendedKeyUsage X509v3 Extended Key Usage
+#
+x509 OID_X509_EXT_FRESHEST_CRL 2.5.29.46 freshestCRL X509v3 Freshest CRL
+#
+x509 OID_X509_EXT_INHIBITANT_ANY_POLICY 2.5.29.54 inhibitantAnyPolicy X509v3 Inhibit Any-policy
+
+nist-algs OID_NIST_ENC_AES256_CBC 2.16.840.1.101.3.4.1.42 aes-256-cbc 256-bit Advanced Encryption Standard (AES) algorithm with Cipher-Block Chaining (CBC) mode of operation
+
+nist-algs OID_NIST_HASH_SHA256 2.16.840.1.101.3.4.2.1 sha256 Secure Hash Algorithm that uses a 256 bit key (SHA256)
+
+x509 OID_X509_EXT_CERT_TYPE 2.16.840.1.113730.1.1 nsCertType X.509 v3 Certificate Type
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..264a9f3
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,15 @@
+use std::env;
+
+include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/load.rs"));
+
+fn main() -> Result<()> {
+ println!("cargo:rerun-if-changed=assets/oid_db.txt");
+
+ let out_dir = env::var_os("OUT_DIR").unwrap();
+ let dest_path = Path::new(&out_dir).join("oid_db.rs");
+
+ let m = load_file("assets/oid_db.txt")?;
+ generate_file(&m, dest_path)?;
+
+ Ok(())
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..a0e1bd9
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,281 @@
+//! [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE-MIT)
+//! [![Apache License 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](./LICENSE-APACHE)
+//! [![docs.rs](https://docs.rs/oid-registry/badge.svg)](https://docs.rs/oid-registry)
+//! [![crates.io](https://img.shields.io/crates/v/oid-registry.svg)](https://crates.io/crates/oid-registry)
+//! [![Github CI](https://github.com/rusticata/oid-registry/workflows/Continuous%20integration/badge.svg)](https://github.com/rusticata/oid-registry/actions)
+//! [![Minimum rustc version](https://img.shields.io/badge/rustc-1.45.0+-lightgray.svg)](#rust-version-requirements)
+//! # 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.
+//!
+//! ```rust
+//! use oid_registry::OidRegistry;
+//!
+//! let mut registry = OidRegistry::default()
+//! # ;
+//! # #[cfg(feature = "crypto")] {
+//! # registry = registry
+//! .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:
+//!
+//! ```rust
+//! use oid_registry::{OidEntry, OidRegistry};
+//! use der_parser::oid;
+//!
+//! 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"));
+//!
+//! ```
+//!
+//! ## 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.
+
+#![deny(missing_docs, unstable_features, unused_import_braces, unused_qualifications, unreachable_pub)]
+#![forbid(unsafe_code)]
+#![warn(
+ /* missing_docs,
+ rust_2018_idioms,*/
+ missing_debug_implementations,
+ )]
+// pragmas for doc
+// #![deny(intra_doc_link_resolution_failure)]
+#![cfg_attr(docsrs, feature(doc_cfg))]
+
+use der_parser::oid;
+pub use der_parser::oid::Oid;
+use std::borrow::Cow;
+use std::collections::HashMap;
+use std::convert::From;
+
+mod load;
+
+pub use load::*;
+
+/// An entry stored in the OID registry
+#[derive(Debug)]
+pub struct OidEntry {
+ // Short name
+ sn: Cow<'static, str>,
+ description: Cow<'static, str>,
+}
+
+impl OidEntry {
+ /// Create a new entry
+ pub fn new<S, T>(sn: S, description: T) -> OidEntry
+ where
+ S: Into<Cow<'static, str>>,
+ T: Into<Cow<'static, str>>,
+ {
+ let sn = sn.into();
+ let description = description.into();
+ OidEntry { sn, description }
+ }
+
+ /// Get the short name for this entry
+ #[inline]
+ pub fn sn(&self) -> &str {
+ &self.sn
+ }
+
+ /// Get the description for this entry
+ #[inline]
+ pub fn description(&self) -> &str {
+ &self.description
+ }
+}
+
+impl From<(&'static str, &'static str)> for OidEntry {
+ fn from(t: (&'static str, &'static str)) -> Self {
+ Self::new(t.0, t.1)
+ }
+}
+
+/// 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
+///
+/// ```rust
+/// use der_parser::{oid, oid::Oid};
+/// use oid_registry::{OidEntry, OidRegistry};
+///
+/// let mut registry = OidRegistry::default()
+/// # ;
+/// # #[cfg(feature = "crypto")] {
+/// # registry = registry
+/// .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");
+/// }
+/// ```
+#[derive(Debug, Default)]
+pub struct OidRegistry<'a> {
+ map: HashMap<Oid<'a>, OidEntry>,
+}
+
+impl<'a> OidRegistry<'a> {
+ /// Insert a new entry
+ pub fn insert<E>(&mut self, oid: Oid<'a>, entry: E) -> Option<OidEntry>
+ where
+ E: Into<OidEntry>,
+ {
+ self.map.insert(oid, entry.into())
+ }
+
+ /// Returns a reference to the registry entry, if found for this OID.
+ pub fn get(&self, oid: &Oid<'a>) -> Option<&OidEntry> {
+ self.map.get(oid)
+ }
+
+ /// Return an Iterator over references to the OID numbers (registry keys)
+ pub fn keys(&self) -> impl Iterator<Item = &Oid<'a>> {
+ self.map.keys()
+ }
+
+ /// Return an Iterator over references to the `OidEntry` values
+ pub fn values(&self) -> impl Iterator<Item = &OidEntry> {
+ self.map.values()
+ }
+
+ /// Return an Iterator over references to the `(Oid, OidEntry)` key/value pairs
+ pub fn iter(&self) -> impl Iterator<Item = (&Oid<'a>, &OidEntry)> {
+ self.map.iter()
+ }
+
+ /// 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.
+ ///
+ /// ```rust
+ /// # use oid_registry::OidRegistry;
+ /// #
+ /// # let registry = OidRegistry::default();
+ /// // 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
+ /// }
+ /// ```
+ pub fn iter_by_sn<S: Into<String>>(&self, sn: S) -> impl Iterator<Item = (&Oid<'a>, &OidEntry)> {
+ let s = sn.into();
+ self.map.iter().filter(move |(_, entry)| entry.sn == s)
+ }
+
+ /// Populate registry with common crypto OIDs (encryption, hash algorithms)
+ #[cfg(feature = "crypto")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "crypto")))]
+ pub fn with_crypto(self) -> Self {
+ self.with_pkcs1().with_x962().with_kdf().with_nist_algs()
+ }
+
+ /// Populate registry with all known crypto OIDs (encryption, hash algorithms, PKCS constants,
+ /// etc.)
+ #[cfg(feature = "crypto")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "crypto")))]
+ pub fn with_all_crypto(self) -> Self {
+ self.with_crypto().with_pkcs7().with_pkcs9().with_pkcs12()
+ }
+}
+
+/// Format a OID to a `String`, using the provided registry to get the short name if present.
+pub fn format_oid(oid: &Oid, registry: &OidRegistry) -> String {
+ if let Some(entry) = registry.map.get(oid) {
+ format!("{} ({})", entry.sn, oid)
+ } else {
+ format!("{}", oid)
+ }
+}
+
+include!(concat!(env!("OUT_DIR"), "/oid_db.rs"));
+
+#[rustfmt::skip::macros(oid)]
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ // This test is mostly a compile test, to ensure the API has not changed
+ #[test]
+ fn test_lifetimes() {
+ fn add_entry(input: &str, oid: Oid<'static>, registry: &mut OidRegistry) {
+ // test insertion of owned string
+ let s = String::from(input);
+ let entry = OidEntry::new("test", s);
+ registry.insert(oid, entry);
+ }
+
+ let mut registry = OidRegistry::default();
+ add_entry("a", oid!(1.2.3.4), &mut registry);
+ add_entry("b", oid!(1.2.3.5), &mut registry);
+
+ // test insertion of owned data
+ let e = OidEntry::new("c", "test_c");
+ registry.insert(oid!(1.2.4.1), e);
+
+ registry.insert(oid!(1.2.5.1), ("a", "b"));
+
+ let iter = registry.iter_by_sn("test");
+ assert_eq!(iter.count(), 2);
+
+ // dbg!(&registry);
+ }
+}
diff --git a/src/load.rs b/src/load.rs
new file mode 100644
index 0000000..f64a6d9
--- /dev/null
+++ b/src/load.rs
@@ -0,0 +1,100 @@
+use std::collections::BTreeMap;
+use std::fs::File;
+use std::io::{BufRead, BufReader, Result, Write};
+use std::path::Path;
+
+/// Temporary structure, created when reading a file containing OID declarations
+#[derive(Debug)]
+pub struct LoadedEntry {
+ /// Name of the global constant for this entry.
+ ///
+ /// If `name` is "", then no global constant is defined
+ pub name: String,
+ /// Textual representation of OID (ex: 2.5.4.3)
+ pub oid: String,
+ /// A short name to describe OID. Should be unique (no check is done)
+ pub sn: String,
+ /// A description for this entry
+ pub description: String,
+}
+
+/// Temporary structure, created when reading a file containing OID declarations
+pub type LoadedMap = BTreeMap<String, Vec<LoadedEntry>>;
+
+/// Load a file to an OID description map
+///
+/// format of the file: tab-separated values
+/// <pre>
+/// feature name oid short_name description (until end of line)
+/// </pre>
+///
+/// `name` is used to declare a global constant when creating output file (see `generate_file`).
+/// If `name` is "" then no constant will be written
+///
+pub fn load_file<P: AsRef<Path>>(path: P) -> Result<LoadedMap> {
+ let mut map = BTreeMap::new();
+
+ let file = File::open(path)?;
+ for line in BufReader::new(file).lines() {
+ let line = line?;
+ if line.is_empty() || line.starts_with('#') {
+ continue;
+ }
+ // split by tabs
+ let mut iter = line.splitn(5, '\t');
+ let feature = iter.next().expect("invalid oid_db format: missing feature").replace("-", "_");
+ let name = iter.next().expect("invalid oid_db format: missing name").to_string();
+ let oid = iter.next().expect("invalid oid_db format: missing OID").to_string();
+ let sn = iter.next().expect("invalid oid_db format: missing short name").to_string();
+ let description = iter.next().expect("invalid oid_db format: missing description").to_string();
+
+ let entry = LoadedEntry {
+ name,
+ oid,
+ sn,
+ description,
+ };
+
+ let v = map.entry(feature.to_string()).or_insert_with(Vec::new);
+
+ v.push(entry);
+ }
+ Ok(map)
+}
+
+/// Generate a file containing a `with_<feat>` method for OidRegistry
+pub fn generate_file<P: AsRef<Path>>(map: &LoadedMap, dest_path: P) -> Result<()> {
+ let mut out_file = File::create(&dest_path)?;
+ for feat_entries in map.values() {
+ for v in feat_entries {
+ if v.name != "\"\"" {
+ writeln!(out_file, "/// {}", v.oid)?;
+ writeln!(out_file, "pub const {}: Oid<'static> = oid!({});", v.name, v.oid)?;
+ }
+ }
+ }
+ writeln!(out_file)?;
+ writeln!(out_file, "impl<'a> OidRegistry<'a> {{")?;
+ for (k, v) in map {
+ writeln!(out_file, r#" #[cfg(feature = "{}")]"#, k)?;
+ writeln!(out_file, r#" #[cfg_attr(docsrs, doc(cfg(feature = "{}")))]"#, k)?;
+ writeln!(
+ out_file,
+ r#" #[doc = "Load all known OIDs for feature `{}` in the registry."]"#,
+ k
+ )?;
+ writeln!(out_file, " pub fn with_{}(mut self) -> Self {{", k)?;
+ for item in v {
+ writeln!(
+ out_file,
+ r#" self.insert(oid!({}), OidEntry::new("{}", "{}"));"#,
+ item.oid, item.sn, item.description
+ )?;
+ }
+ writeln!(out_file, " self")?;
+ writeln!(out_file, " }}")?;
+ writeln!(out_file)?;
+ }
+ writeln!(out_file, "}}")?;
+ Ok(())
+}