summaryrefslogtreecommitdiffstats
path: root/vendor/const-oid/src/db.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/const-oid/src/db.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/const-oid/src/db.rs')
-rw-r--r--vendor/const-oid/src/db.rs38
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)]