diff options
Diffstat (limited to 'vendor/const-oid/src/db.rs')
-rw-r--r-- | vendor/const-oid/src/db.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/const-oid/src/db.rs b/vendor/const-oid/src/db.rs index 971990de0..e4b7a47b4 100644 --- a/vendor/const-oid/src/db.rs +++ b/vendor/const-oid/src/db.rs @@ -54,6 +54,7 @@ const fn eq_case(lhs: &[u8], rhs: &[u8]) -> bool { } /// A query interface for OIDs/Names. +#[derive(Copy, Clone)] pub struct Database<'a>(&'a [(&'a ObjectIdentifier, &'a str)]); impl<'a> Database<'a> { @@ -99,6 +100,43 @@ impl<'a> Database<'a> { None } + + /// Return the list of matched name for the OID. + pub const fn find_names_for_oid(&self, oid: ObjectIdentifier) -> Names<'a> { + Names { + database: *self, + oid, + position: 0, + } + } +} + +/// Iterator returning the multiple names that may be associated with an OID. +pub struct Names<'a> { + database: Database<'a>, + oid: ObjectIdentifier, + position: usize, +} + +impl<'a> Iterator for Names<'a> { + type Item = &'a str; + + fn next(&mut self) -> Option<&'a str> { + let mut i = self.position; + + while i < self.database.0.len() { + let lhs = self.database.0[i].0; + + if lhs.as_bytes().eq(self.oid.as_bytes()) { + self.position = i + 1; + return Some(self.database.0[i].1); + } + + i += 1; + } + + None + } } #[cfg(test)] |