| 1 | #![no_std] |
| 2 | #![cfg_attr(docsrs, feature(doc_cfg))] |
| 3 | #![doc = include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("../README.md")] |
| 4 | #![doc( |
| 5 | html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", |
| 6 | html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg" |
| 7 | )] |
| 8 | #![allow(clippy::len_without_is_empty)] |
| 9 | #![deny(unsafe_code)] |
| 10 | #![warn( |
| 11 | clippy::arithmetic_side_effects, |
| 12 | clippy::mod_module_files, |
| 13 | clippy::panic, |
| 14 | clippy::panic_in_result_fn, |
| 15 | clippy::unwrap_used, |
| 16 | missing_docs, |
| 17 | rust_2018_idioms, |
| 18 | unused_lifetimes, |
| 19 | unused_qualifications |
| 20 | )] |
| 21 | |
| 22 | #[macro_use] |
| 23 | mod checkedrust-analyzer cargo const-oid 0.10.2 checked/; |
| 24 | |
| 25 | mod arcsrust-analyzer cargo const-oid 0.10.2 arcs/; |
| 26 | mod bufferrust-analyzer cargo const-oid 0.10.2 buffer/; |
| 27 | mod encoderrust-analyzer cargo const-oid 0.10.2 encoder/; |
| 28 | mod errorrust-analyzer cargo const-oid 0.10.2 error/; |
| 29 | mod parserrust-analyzer cargo const-oid 0.10.2 parser/; |
| 30 | mod traitsrust-analyzer cargo const-oid 0.10.2 traits/; |
| 31 | |
| 32 | #[cfg(feature = "db")] |
| 33 | pub mod dbrust-analyzer cargo const-oid 0.10.2 db/; |
| 34 | |
| 35 | pub use craterust-analyzer cargo const-oid 0.10.2 crate/::{ |
| 36 | arcsrust-analyzer cargo const-oid 0.10.2 arcs/::{Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#, Arcsrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#}, |
| 37 | bufferrust-analyzer cargo const-oid 0.10.2 buffer/::Bufferrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#, |
| 38 | errorrust-analyzer cargo const-oid 0.10.2 error/::{Errorrust-analyzer cargo const-oid 0.10.2 error/Error#, Resultrust-analyzer cargo const-oid 0.10.2 error/Result#}, |
| 39 | traitsrust-analyzer cargo const-oid 0.10.2 traits/::{AssociatedOidrust-analyzer cargo const-oid 0.10.2 traits/AssociatedOid#, DynAssociatedOidrust-analyzer cargo const-oid 0.10.2 traits/DynAssociatedOid#}, |
| 40 | }; |
| 41 | |
| 42 | use craterust-analyzer cargo const-oid 0.10.2 crate/::encoderrust-analyzer cargo const-oid 0.10.2 encoder/::Encoderrust-analyzer cargo const-oid 0.10.2 encoder/Encoder#; |
| 43 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/::Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#, fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/, opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#}; |
| 44 | |
| 45 | /// Default maximum size. |
| 46 | /// |
| 47 | /// Makes `ObjectIdentifier` 40-bytes total w\ 1-byte length. |
| 48 | const DEFAULT_MAX_SIZErust-analyzer cargo const-oid 0.10.2 DEFAULT_MAX_SIZE.: usize = 39; |
| 49 | |
| 50 | /// Object identifier (OID). |
| 51 | /// |
| 52 | /// OIDs are hierarchical structures consisting of "arcs", i.e. integer |
| 53 | /// identifiers. |
| 54 | /// |
| 55 | /// # Validity |
| 56 | /// |
| 57 | /// In order for an OID to be considered valid by this library, it must meet |
| 58 | /// the following criteria: |
| 59 | /// |
| 60 | /// - The OID MUST have at least 3 arcs |
| 61 | /// - The first arc MUST be within the range 0-2 |
| 62 | /// - The second arc MUST be within the range 0-39 |
| 63 | /// - The BER/DER encoding of the OID MUST be shorter than |
| 64 | /// [`ObjectIdentifier::MAX_SIZE`] |
| 65 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 66 | pub struct ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<const MAX_SIZE: usize = DEFAULT_MAX_SIZErust-analyzer cargo const-oid 0.10.2 DEFAULT_MAX_SIZE.> { |
| 67 | /// Buffer containing BER/DER-serialized bytes (sans ASN.1 tag/length) |
| 68 | berrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#ber.: Bufferrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#<MAX_SIZE>, |
| 69 | } |
| 70 | |
| 71 | impl ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier# { |
| 72 | /// Maximum size of a BER/DER-encoded OID in bytes. |
| 73 | pub const MAX_SIZErust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]MAX_SIZE.: usize = DEFAULT_MAX_SIZErust-analyzer cargo const-oid 0.10.2 DEFAULT_MAX_SIZE.; |
| 74 | |
| 75 | /// Parse an [`ObjectIdentifier`] from the dot-delimited string form, |
| 76 | /// panicking on parse errors. |
| 77 | /// |
| 78 | /// This function exists as a workaround for `unwrap` not yet being |
| 79 | /// stable in `const fn` contexts, and is intended to allow the result to |
| 80 | /// be bound to a constant value: |
| 81 | /// |
| 82 | /// ``` |
| 83 | /// use const_oid::ObjectIdentifier; |
| 84 | /// |
| 85 | /// pub const MY_OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.1"); |
| 86 | /// ``` |
| 87 | /// |
| 88 | /// In future versions of Rust it should be possible to replace this with |
| 89 | /// `ObjectIdentifier::new(...).unwrap()`. |
| 90 | /// |
| 91 | /// Use [`ObjectIdentifier::new`] for fallible parsing. |
| 92 | // TODO(tarcieri): remove this when `Result::unwrap` is `const fn` |
| 93 | pub const fn new_unwraprust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]new_unwrap().(s: &str) -> Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier] { |
| 94 | match Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]::newrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]new().(s) { |
| 95 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(oid) => oid, |
| 96 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => err.panicrust-analyzer cargo const-oid 0.10.2 error/impl#[Error]panic().(), |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /// Parse an [`ObjectIdentifier`] from the dot-delimited string form. |
| 101 | pub const fn newrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]new().(s: &str) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]> { |
| 102 | // TODO(tarcieri): use `?` when stable in `const fn` |
| 103 | match parserrust-analyzer cargo const-oid 0.10.2 parser/::Parserrust-analyzer cargo const-oid 0.10.2 parser/Parser#::parserust-analyzer cargo const-oid 0.10.2 parser/impl#[Parser]parse().(s) { |
| 104 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(parser) => parser.finishrust-analyzer cargo const-oid 0.10.2 parser/impl#[Parser]finish().(), |
| 105 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err), |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /// Parse an OID from a slice of [`Arc`] values (i.e. integers). |
| 110 | pub fn from_arcsrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]from_arcs().(arcs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#>) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]> { |
| 111 | let mut encoder = Encoderrust-analyzer cargo const-oid 0.10.2 encoder/Encoder#::newrust-analyzer cargo const-oid 0.10.2 encoder/impl#[`Encoder<MAX_SIZE>`]new().(); |
| 112 | |
| 113 | for arc in arcs { |
| 114 | encoder = encoder.arcrust-analyzer cargo const-oid 0.10.2 encoder/impl#[`Encoder<MAX_SIZE>`]arc().(arc)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 115 | } |
| 116 | |
| 117 | encoder.finishrust-analyzer cargo const-oid 0.10.2 encoder/impl#[`Encoder<MAX_SIZE>`]finish().() |
| 118 | } |
| 119 | |
| 120 | /// Parse an OID from from its BER/DER encoding. |
| 121 | pub fn from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]from_bytes().(ber_bytes: &[u8]) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]> { |
| 122 | Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]::from_bytes_sizedrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]from_bytes_sized().(ber_bytes) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | impl<const MAX_SIZE: usize> ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE> { |
| 127 | /// Parse an OID from from its BER/DER encoding. |
| 128 | /// |
| 129 | /// Returns `Err(Error::Length)` if bytes do not fit in `MAX_SIZE`. |
| 130 | pub fn from_bytes_sizedrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]from_bytes_sized().(ber_bytes: &[u8]) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]> { |
| 131 | ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(ber_bytes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().() |
| 132 | } |
| 133 | |
| 134 | /// Get the BER/DER serialization of this OID as bytes. |
| 135 | /// |
| 136 | /// Note that this encoding omits the ASN.1 tag/length, and only contains the value portion of |
| 137 | /// the encoded OID. |
| 138 | pub const fn as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_bytes().(&self) -> &[u8] { |
| 139 | self.berrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#ber..as_bytesrust-analyzer cargo const-oid 0.10.2 buffer/impl#[`Buffer<SIZE>`]as_bytes().() |
| 140 | } |
| 141 | |
| 142 | /// Borrow an [`ObjectIdentifierRef`] which corresponds to this [`ObjectIdentifier`]. |
| 143 | pub const fn as_oid_refrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_oid_ref().(&self) -> &ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 144 | ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytes_uncheckedrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes_unchecked().(self.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_bytes().()) |
| 145 | } |
| 146 | |
| 147 | /// Get the parent OID of this one (if applicable). |
| 148 | pub fn parentrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]parent().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]> { |
| 149 | let num_arcs = self.lenrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]len().().checked_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_sub().(1)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 150 | let mut encoder = Encoderrust-analyzer cargo const-oid 0.10.2 encoder/Encoder#::newrust-analyzer cargo const-oid 0.10.2 encoder/impl#[`Encoder<MAX_SIZE>`]new().(); |
| 151 | |
| 152 | for arc in self.arcsrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arcs().().takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(num_arcs) { |
| 153 | encoder = encoder.arcrust-analyzer cargo const-oid 0.10.2 encoder/impl#[`Encoder<MAX_SIZE>`]arc().(arc).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 154 | } |
| 155 | |
| 156 | encoder.finishrust-analyzer cargo const-oid 0.10.2 encoder/impl#[`Encoder<MAX_SIZE>`]finish().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() |
| 157 | } |
| 158 | |
| 159 | /// Push an additional arc onto this OID, returning the child OID. |
| 160 | pub const fn push_arcrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]push_arc().(self, arc: Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]> { |
| 161 | // TODO(tarcieri): use `?` when stable in `const fn` |
| 162 | match Encoderrust-analyzer cargo const-oid 0.10.2 encoder/Encoder#::extendrust-analyzer cargo const-oid 0.10.2 encoder/impl#[`Encoder<MAX_SIZE>`]extend().(self).arcrust-analyzer cargo const-oid 0.10.2 encoder/impl#[`Encoder<MAX_SIZE>`]arc().(arc) { |
| 163 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(encoder) => encoder.finishrust-analyzer cargo const-oid 0.10.2 encoder/impl#[`Encoder<MAX_SIZE>`]finish().(), |
| 164 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err), |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /// Does this OID start with the other OID? |
| 169 | pub const fn starts_withrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]starts_with().<const SIZE: usize>(&self, other: ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<SIZE>) -> bool { |
| 170 | let len = other.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_bytes().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 171 | |
| 172 | if self.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_bytes().().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][`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().len { |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | let mut i = 0; |
| 177 | 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().len { |
| 178 | if self.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_bytes().()[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(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().other.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_bytes().()[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(). { |
| 179 | return false; |
| 180 | } |
| 181 | |
| 182 | match i.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(1) { |
| 183 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(succ) => i = succ, |
| 184 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return false, |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | true |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | impl<const MAX_SIZE: usize> AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]> for ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE> { |
| 193 | fn as_refrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][`AsRef<[u8]>`]as_ref().(&self) -> &[u8] { |
| 194 | self.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_bytes().() |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | impl<const MAX_SIZE: usize> AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#> for ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE> { |
| 199 | fn as_refrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][`AsRef<ObjectIdentifierRef>`]as_ref().(&self) -> &ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 200 | self.as_oid_refrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_oid_ref().() |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | impl<const MAX_SIZE: usize> Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#> for ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE> { |
| 205 | fn borrowrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][`Borrow<ObjectIdentifierRef>`]borrow().(&self) -> &ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 206 | self.as_oid_refrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_oid_ref().() |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | impl<const MAX_SIZE: usize> Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE> { |
| 211 | type Targetrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][Deref]Target# = ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#; |
| 212 | |
| 213 | fn derefrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][Deref]deref().(&self) -> &ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 214 | self.as_oid_refrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_oid_ref().() |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier# { |
| 219 | type Errrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][FromStr]Err# = Errorrust-analyzer cargo const-oid 0.10.2 error/Error#; |
| 220 | |
| 221 | fn from_strrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][FromStr]from_str().(string: &str) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][FromStr]> { |
| 222 | Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][FromStr]::newrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]new().(string) |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&[u8]> for ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier# { |
| 227 | type Errorrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][`TryFrom<&[u8]>`]Error# = Errorrust-analyzer cargo const-oid 0.10.2 error/Error#; |
| 228 | |
| 229 | fn try_fromrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][`TryFrom<&[u8]>`]try_from().(ber_bytes: &[u8]) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][`TryFrom<&[u8]>`]> { |
| 230 | Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][`TryFrom<&[u8]>`]::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]from_bytes().(ber_bytes) |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | impl<const MAX_SIZE: usize> TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#> for ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE> { |
| 235 | type Errorrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][`TryFrom<&ObjectIdentifierRef>`]Error# = Errorrust-analyzer cargo const-oid 0.10.2 error/Error#; |
| 236 | |
| 237 | fn try_fromrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][`TryFrom<&ObjectIdentifierRef>`]try_from().(oid_ref: &ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][`TryFrom<&ObjectIdentifierRef>`]> { |
| 238 | let len = oid_ref.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]as_bytes().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 239 | |
| 240 | if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().MAX_SIZE { |
| 241 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Lengthrust-analyzer cargo const-oid 0.10.2 error/Error#Length#); |
| 242 | } |
| 243 | |
| 244 | let mut bytes = [0u8; MAX_SIZE]; |
| 245 | bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(oid_ref.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]as_bytes().()); |
| 246 | |
| 247 | let ber = Bufferrust-analyzer cargo const-oid 0.10.2 buffer/Buffer# { |
| 248 | bytesrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#bytes., |
| 249 | lengthrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#length.: len as u8, |
| 250 | }; |
| 251 | |
| 252 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][`TryFrom<&ObjectIdentifierRef>`] { berrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#ber. }) |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | impl<const MAX_SIZE: usize> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE> { |
| 257 | fn fmtrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 258 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "ObjectIdentifier({self})") |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | impl<const MAX_SIZE: usize> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE> { |
| 263 | fn fmtrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 264 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.as_oid_refrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_oid_ref().()) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // Implement by hand because the derive would create invalid values. |
| 269 | // Use the constructor to create a valid oid with at least 3 arcs. |
| 270 | #[cfg(feature = "arbitrary")] |
| 271 | impl<'a> arbitraryrust-analyzer cargo arbitrary 1.4.2 crate/::Arbitraryrust-analyzer cargo arbitrary 1.4.2 Arbitrary#<'a> for ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier# { |
| 272 | fn arbitraryrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][`Arbitrary<'a>`]arbitrary().(u: &mut arbitraryrust-analyzer cargo arbitrary 1.4.2 crate/::Unstructuredrust-analyzer cargo arbitrary 1.4.2 unstructured/Unstructured#<'a>) -> arbitraryrust-analyzer cargo arbitrary 1.4.2 crate/::Resultrust-analyzer cargo arbitrary 1.4.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][`Arbitrary<'a>`]> { |
| 273 | let first = u.int_in_rangerust-analyzer cargo arbitrary 1.4.2 unstructured/impl#[`Unstructured<'a>`]int_in_range().(0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#arcsrust-analyzer cargo const-oid 0.10.2 arcs/::ARC_MAX_FIRSTrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_FIRST.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 274 | let second = u.int_in_rangerust-analyzer cargo arbitrary 1.4.2 unstructured/impl#[`Unstructured<'a>`]int_in_range().(0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#arcsrust-analyzer cargo const-oid 0.10.2 arcs/::ARC_MAX_SECONDrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_SECOND.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 275 | let third = u.arbitraryrust-analyzer cargo arbitrary 1.4.2 unstructured/impl#[`Unstructured<'a>`]arbitrary().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 276 | |
| 277 | let mut oid = Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][`Arbitrary<'a>`]::from_arcsrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier]from_arcs().([first, second, third]) |
| 278 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| arbitraryrust-analyzer cargo arbitrary 1.4.2 crate/::Errorrust-analyzer cargo arbitrary 1.4.2 error/Error#::IncorrectFormatrust-analyzer cargo arbitrary 1.4.2 error/Error#IncorrectFormat#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 279 | |
| 280 | for arc in u.arbitrary_iterrust-analyzer cargo arbitrary 1.4.2 unstructured/impl#[`Unstructured<'a>`]arbitrary_iter().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 281 | oid = oid |
| 282 | .push_arcrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]push_arc().(arc?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 283 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| arbitraryrust-analyzer cargo arbitrary 1.4.2 crate/::Errorrust-analyzer cargo arbitrary 1.4.2 error/Error#::IncorrectFormatrust-analyzer cargo arbitrary 1.4.2 error/Error#IncorrectFormat#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 284 | } |
| 285 | |
| 286 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(oid) |
| 287 | } |
| 288 | |
| 289 | fn size_hintrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifier][`Arbitrary<'a>`]size_hint().(depth: usize) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 290 | (Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#::size_hintrust-analyzer cargo arbitrary 1.4.2 foreign/core/num/impl#[u32][`Arbitrary<'a>`]size_hint().(depth).0.saturating_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_mul().(3), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | /// OID reference type: wrapper for the BER serialization. |
| 295 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 296 | #[repr(transparent)] |
| 297 | pub struct ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 298 | /// BER/DER-serialized bytes (sans ASN.1 tag/length). |
| 299 | berrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#ber.: [u8], |
| 300 | } |
| 301 | |
| 302 | impl ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 303 | /// Create an [`ObjectIdentifierRef`], validating that the provided byte slice contains a valid |
| 304 | /// BER/DER encoding. |
| 305 | // TODO(tarcieri): `const fn` support |
| 306 | pub fn from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(ber: &[u8]) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<&Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]> { |
| 307 | // Ensure arcs are well-formed |
| 308 | let mut arcs = Arcsrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#::newrust-analyzer cargo const-oid 0.10.2 arcs/impl#[`Arcs<'a>`]new().(ber); |
| 309 | while arcs.try_nextrust-analyzer cargo const-oid 0.10.2 arcs/impl#[`Arcs<'a>`]try_next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {} |
| 310 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]::from_bytes_uncheckedrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes_unchecked().(ber)) |
| 311 | } |
| 312 | |
| 313 | /// Create an [`ObjectIdentifierRef`] from the given byte slice without first checking that it |
| 314 | /// contains valid BER/DER. |
| 315 | pub(craterust-analyzer cargo const-oid 0.10.2 crate/) const fn from_bytes_uncheckedrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes_unchecked().(ber: &[u8]) -> &Selfrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef] { |
| 316 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ber.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().()); |
| 317 | |
| 318 | // SAFETY: `ObjectIdentifierRef` is a `repr(transparent)` newtype for `[u8]`. |
| 319 | #[allow(unsafe_code)] |
| 320 | unsafe { |
| 321 | &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().(ber as *const [u8] as *const ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#) |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /// Get the BER/DER serialization of this OID as bytes. |
| 326 | /// |
| 327 | /// Note that this encoding omits the ASN.1 tag/length, and only contains the value portion of |
| 328 | /// the encoded OID. |
| 329 | pub const fn as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]as_bytes().(&self) -> &[u8] { |
| 330 | &self.berrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#ber. |
| 331 | } |
| 332 | |
| 333 | /// Return the arc with the given index, if it exists. |
| 334 | pub fn arcrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arc().(&self, index: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#> { |
| 335 | self.arcsrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arcs().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(index) |
| 336 | } |
| 337 | |
| 338 | /// Iterate over the arcs (a.k.a. nodes) of an [`ObjectIdentifier`]. |
| 339 | /// |
| 340 | /// Returns [`Arcs`], an iterator over [`Arc`] values. |
| 341 | pub fn arcsrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arcs().(&self) -> Arcsrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#<'_> { |
| 342 | Arcsrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#::newrust-analyzer cargo const-oid 0.10.2 arcs/impl#[`Arcs<'a>`]new().(self.berrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#ber..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`[T]`][`AsRef<Self>`]as_ref().()) |
| 343 | } |
| 344 | |
| 345 | /// Get the length of this [`ObjectIdentifier`] in arcs. |
| 346 | pub fn lenrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]len().(&self) -> usize { |
| 347 | self.arcsrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arcs().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]> for ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 352 | fn as_refrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef][`AsRef<[u8]>`]as_ref().(&self) -> &[u8] { |
| 353 | self.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]as_bytes().() |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | impl<'a, const MAX_SIZE: usize> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE>> for &'a ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 358 | fn fromrust-analyzer cargo const-oid 0.10.2 impl#[`&'a ObjectIdentifierRef`][`From<&'a ObjectIdentifier<MAX_SIZE>>`]from().(oid: &'a ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE>) -> &'a ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 359 | oid.as_oid_refrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_oid_ref().() |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | impl<'a> TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&'a [u8]> for &'a ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 364 | type Errorrust-analyzer cargo const-oid 0.10.2 impl#[`&'a ObjectIdentifierRef`][`TryFrom<&'a [u8]>`]Error# = Errorrust-analyzer cargo const-oid 0.10.2 error/Error#; |
| 365 | |
| 366 | fn try_fromrust-analyzer cargo const-oid 0.10.2 impl#[`&'a ObjectIdentifierRef`][`TryFrom<&'a [u8]>`]try_from().(ber_bytes: &'a [u8]) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 impl#[`&'a ObjectIdentifierRef`][`TryFrom<&'a [u8]>`]> { |
| 367 | ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef#::from_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]from_bytes().(ber_bytes) |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 372 | fn fmtrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 373 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "ObjectIdentifierRef({self})") |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 378 | fn fmtrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 379 | let len = self.arcsrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arcs().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(); |
| 380 | |
| 381 | for (i, arc) in self.arcsrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]arcs().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 382 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{arc}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 383 | |
| 384 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(j) = i.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(1) { |
| 385 | if j 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().len { |
| 386 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ".")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | impl<const MAX_SIZE: usize> PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE>> for ObjectIdentifierRefrust-analyzer cargo const-oid 0.10.2 ObjectIdentifierRef# { |
| 396 | fn eqrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef][`PartialEq<ObjectIdentifier<MAX_SIZE>>`]eq().(&self, other: &ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#<MAX_SIZE>) -> bool { |
| 397 | self.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[ObjectIdentifierRef]as_bytes().().eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][`PartialEq<[U]>`]eq().(other.as_bytesrust-analyzer cargo const-oid 0.10.2 impl#[`ObjectIdentifier<MAX_SIZE>`]as_bytes().()) |
| 398 | } |
| 399 | } |