| 1 | //! OID Names Database |
| 2 | //! |
| 3 | //! The contents of this database are generated from the official IANA |
| 4 | //! [Object Identifier Descriptors] Registry CSV file and from [RFC 5280]. |
| 5 | //! If we are missing values you care about, please contribute a patch to |
| 6 | //! `oiddbgen` (a subcrate in the source code) to generate the values from |
| 7 | //! the relevant standard. |
| 8 | //! |
| 9 | //! [RFC 5280]: https://datatracker.ietf.org/doc/html/rfc5280 |
| 10 | //! [Object Identifier Descriptors]: https://www.iana.org/assignments/ldap-parameters/ldap-parameters.xhtml#ldap-parameters-3 |
| 11 | |
| 12 | #![allow(clippy::arithmetic_side_effects, missing_docs)] |
| 13 | |
| 14 | mod generatedrust-analyzer cargo const-oid 0.10.2 db/generated/; |
| 15 | |
| 16 | pub use generatedrust-analyzer cargo const-oid 0.10.2 db/generated/::*; |
| 17 | |
| 18 | use craterust-analyzer cargo const-oid 0.10.2 crate/::{Errorrust-analyzer cargo const-oid 0.10.2 error/Error#, ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#}; |
| 19 | |
| 20 | /// A const implementation of case-insensitive ASCII equals. |
| 21 | const fn eq_caserust-analyzer cargo const-oid 0.10.2 db/eq_case().(lhs: &[u8], rhs: &[u8]) -> bool { |
| 22 | if lhs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().rhs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | let mut i = 0usize; |
| 27 | while i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().lhs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 28 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().lhs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]eq_ignore_ascii_case().(&rhs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) { |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 33 | } |
| 34 | |
| 35 | true |
| 36 | } |
| 37 | |
| 38 | /// A query interface for OIDs/Names. |
| 39 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 40 | pub struct Databaserust-analyzer cargo const-oid 0.10.2 db/Database#<'a>(&'a [(&'a ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#, &'a str)]); |
| 41 | |
| 42 | impl<'a> Databaserust-analyzer cargo const-oid 0.10.2 db/Database#<'a> { |
| 43 | /// Looks up a name for an OID. |
| 44 | /// |
| 45 | /// Errors if the input is not a valid OID. |
| 46 | /// Returns the input if no name is found. |
| 47 | pub fn resolverust-analyzer cargo const-oid 0.10.2 db/impl#[`Database<'a>`]resolve().<'b>(&self, oid: &'b str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'b str, Errorrust-analyzer cargo const-oid 0.10.2 error/Error#> |
| 48 | where |
| 49 | 'a: 'b, |
| 50 | { |
| 51 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.by_oidrust-analyzer cargo const-oid 0.10.2 db/impl#[`Database<'a>`]by_oid().(&oid.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(oid)) |
| 52 | } |
| 53 | |
| 54 | /// Finds a named oid by its associated OID. |
| 55 | pub const fn by_oidrust-analyzer cargo const-oid 0.10.2 db/impl#[`Database<'a>`]by_oid().(&self, oid: &ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str> { |
| 56 | let mut i = 0; |
| 57 | |
| 58 | while i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.0rust-analyzer cargo const-oid 0.10.2 db/Database#0..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 59 | let lhs = self.0rust-analyzer cargo const-oid 0.10.2 db/Database#0.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..0; |
| 60 | |
| 61 | if lhs.berrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#ber..eqrust-analyzer cargo const-oid 0.10.2 buffer/impl#[`Buffer<SIZE>`]eq().(&oid.berrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#ber.) { |
| 62 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.0rust-analyzer cargo const-oid 0.10.2 db/Database#0.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..1); |
| 63 | } |
| 64 | |
| 65 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 66 | } |
| 67 | |
| 68 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 69 | } |
| 70 | |
| 71 | /// Finds a named oid by its associated name. |
| 72 | pub const fn by_namerust-analyzer cargo const-oid 0.10.2 db/impl#[`Database<'a>`]by_name().(&self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#> { |
| 73 | let mut i = 0; |
| 74 | |
| 75 | while i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.0rust-analyzer cargo const-oid 0.10.2 db/Database#0..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 76 | let lhs = self.0rust-analyzer cargo const-oid 0.10.2 db/Database#0.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..1; |
| 77 | if eq_caserust-analyzer cargo const-oid 0.10.2 db/eq_case().(lhs.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), name.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) { |
| 78 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.0rust-analyzer cargo const-oid 0.10.2 db/Database#0.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..0); |
| 79 | } |
| 80 | |
| 81 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 82 | } |
| 83 | |
| 84 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 85 | } |
| 86 | |
| 87 | /// Return the list of matched name for the OID. |
| 88 | pub const fn find_names_for_oidrust-analyzer cargo const-oid 0.10.2 db/impl#[`Database<'a>`]find_names_for_oid().(&self, oid: ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#) -> Namesrust-analyzer cargo const-oid 0.10.2 db/Names#<'a> { |
| 89 | Namesrust-analyzer cargo const-oid 0.10.2 db/Names# { |
| 90 | databaserust-analyzer cargo const-oid 0.10.2 db/Names#database.: *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self, |
| 91 | oidrust-analyzer cargo const-oid 0.10.2 db/Names#oid., |
| 92 | positionrust-analyzer cargo const-oid 0.10.2 db/Names#position.: 0, |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /// Iterator returning the multiple names that may be associated with an OID. |
| 98 | pub struct Namesrust-analyzer cargo const-oid 0.10.2 db/Names#<'a> { |
| 99 | databaserust-analyzer cargo const-oid 0.10.2 db/Names#database.: Databaserust-analyzer cargo const-oid 0.10.2 db/Database#<'a>, |
| 100 | oidrust-analyzer cargo const-oid 0.10.2 db/Names#oid.: ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#, |
| 101 | positionrust-analyzer cargo const-oid 0.10.2 db/Names#position.: usize, |
| 102 | } |
| 103 | |
| 104 | impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Namesrust-analyzer cargo const-oid 0.10.2 db/Names#<'a> { |
| 105 | type Itemrust-analyzer cargo const-oid 0.10.2 db/impl#[`Names<'a>`][Iterator]Item# = &'a str; |
| 106 | |
| 107 | fn nextrust-analyzer cargo const-oid 0.10.2 db/impl#[`Names<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str> { |
| 108 | let mut i = self.positionrust-analyzer cargo const-oid 0.10.2 db/Names#position.; |
| 109 | |
| 110 | while i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.databaserust-analyzer cargo const-oid 0.10.2 db/Names#database..0rust-analyzer cargo const-oid 0.10.2 db/Database#0..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 111 | let lhs = self.databaserust-analyzer cargo const-oid 0.10.2 db/Names#database..0rust-analyzer cargo const-oid 0.10.2 db/Database#0.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..0; |
| 112 | |
| 113 | if lhs.berrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#ber..eqrust-analyzer cargo const-oid 0.10.2 buffer/impl#[`Buffer<SIZE>`]eq().(&self.oidrust-analyzer cargo const-oid 0.10.2 db/Names#oid..berrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#ber.) { |
| 114 | self.positionrust-analyzer cargo const-oid 0.10.2 db/Names#position. = i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1; |
| 115 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.databaserust-analyzer cargo const-oid 0.10.2 db/Names#database..0rust-analyzer cargo const-oid 0.10.2 db/Database#0.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..1); |
| 116 | } |
| 117 | |
| 118 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 119 | } |
| 120 | |
| 121 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | #[cfg(test)] |
| 126 | mod testsrust-analyzer cargo const-oid 0.10.2 db/tests/ { |
| 127 | use craterust-analyzer cargo const-oid 0.10.2 crate/::ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#; |
| 128 | |
| 129 | use superrust-analyzer cargo const-oid 0.10.2 db/::rfc4519rust-analyzer cargo const-oid 0.10.2 db/generated/rfc4519/::CNrust-analyzer cargo const-oid 0.10.2 db/generated/rfc4519/CN.; |
| 130 | |
| 131 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 132 | fn by_oidrust-analyzer cargo const-oid 0.10.2 db/tests/by_oid().() { |
| 133 | let cn = superrust-analyzer cargo const-oid 0.10.2 db/::DBrust-analyzer cargo const-oid 0.10.2 db/generated/DB..by_oidrust-analyzer cargo const-oid 0.10.2 db/impl#[`Database<'a>`]by_oid().(&CNrust-analyzer cargo const-oid 0.10.2 db/generated/rfc4519/CN.).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("cn not found"); |
| 134 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("cn", cn); |
| 135 | |
| 136 | let none = ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#::new_unwraprust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]new_unwrap().("0.1.2.3.4.5.6.7.8.9"); |
| 137 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, superrust-analyzer cargo const-oid 0.10.2 db/::DBrust-analyzer cargo const-oid 0.10.2 db/generated/DB..by_oidrust-analyzer cargo const-oid 0.10.2 db/impl#[`Database<'a>`]by_oid().(&none)); |
| 138 | } |
| 139 | |
| 140 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 141 | fn by_namerust-analyzer cargo const-oid 0.10.2 db/tests/by_name().() { |
| 142 | let cn = superrust-analyzer cargo const-oid 0.10.2 db/::DBrust-analyzer cargo const-oid 0.10.2 db/generated/DB..by_namerust-analyzer cargo const-oid 0.10.2 db/impl#[`Database<'a>`]by_name().("CN").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("cn not found"); |
| 143 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&CNrust-analyzer cargo const-oid 0.10.2 db/generated/rfc4519/CN., cn); |
| 144 | |
| 145 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, superrust-analyzer cargo const-oid 0.10.2 db/::DBrust-analyzer cargo const-oid 0.10.2 db/generated/DB..by_namerust-analyzer cargo const-oid 0.10.2 db/impl#[`Database<'a>`]by_name().("purplePeopleEater")); |
| 146 | } |
| 147 | } |