Skip to content

Commit

Permalink
feat(const-oid): add additional RFCs to the OID DB (#456)
Browse files Browse the repository at this point in the history
* RFC 5911
* RFC 5912
* RFC 6268
* RFC 7107
* RFC 7299

Signed-off-by: Nathaniel McCallum <nathaniel@profian.com>
  • Loading branch information
npmccallum committed Mar 2, 2022
1 parent 2ac1e97 commit 497991f
Show file tree
Hide file tree
Showing 8 changed files with 15,517 additions and 21 deletions.
3,307 changes: 3,307 additions & 0 deletions const-oid/oiddbgen/rfc5911.txt

Large diffs are not rendered by default.

6,555 changes: 6,555 additions & 0 deletions const-oid/oiddbgen/rfc5912.txt

Large diffs are not rendered by default.

1,851 changes: 1,851 additions & 0 deletions const-oid/oiddbgen/rfc6268.txt

Large diffs are not rendered by default.

1,011 changes: 1,011 additions & 0 deletions const-oid/oiddbgen/rfc7107.txt

Large diffs are not rendered by default.

1,683 changes: 1,683 additions & 0 deletions const-oid/oiddbgen/rfc7299.txt

Large diffs are not rendered by default.

29 changes: 14 additions & 15 deletions const-oid/oiddbgen/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use regex::Regex;

#[derive(Clone, Debug)]
pub struct Asn1Parser {
spec: String,
tree: BTreeMap<String, (Option<String>, Option<String>)>,
}

impl Asn1Parser {
const DEF: &'static str = r"(?mx)
(?P<name>[a-z][a-zA-Z0-9-]*) # name
(?P<name>[a-zA-Z][a-zA-Z0-9-]*) # name
\s+
OBJECT
\s+
Expand All @@ -20,11 +19,11 @@ impl Asn1Parser {
\s*
\{
\s*
(?:(?P<base>[a-z][a-zA-Z0-9-]*)\s+)? # base
(?:(?P<base>[a-zA-Z][a-zA-Z0-9-]*)\s+)? # base
(?P<tail> # tail
(?:
(?:
[a-z][a-zA-Z0-9-]*\([0-9]+\)\s+
[a-zA-Z][a-zA-Z0-9-]*\([0-9]+\)\s+
)
|
(?:
Expand All @@ -37,15 +36,15 @@ impl Asn1Parser {

const ARC: &'static str = r"(?mx)
(?:
[a-z][a-zA-Z0-9-]*\(([0-9]+)\)
[a-zA-Z][a-zA-Z0-9-]*\(([0-9]+)\)
)
|
(?:
([0-9]+)
)
";

pub fn new(spec: String, asn1: &str) -> Self {
pub fn new(asn1: &str) -> Self {
let def = Regex::new(Self::DEF).unwrap();
let arc = Regex::new(Self::ARC).unwrap();

Expand All @@ -64,10 +63,15 @@ impl Asn1Parser {
.join(".")
});

let tail = match tail.as_deref() {
Some("") => None,
_ => tail,
};

tree.insert(name, (base, tail));
}

Self { spec, tree }
Self { tree }
}

pub fn resolve(&self, name: &str) -> Option<String> {
Expand All @@ -84,7 +88,7 @@ impl Asn1Parser {
}
}

pub fn iter(&self) -> impl '_ + Iterator<Item = (String, String, String)> {
pub fn iter(&self) -> impl '_ + Iterator<Item = (String, String)> {
let bases: HashSet<&String> = self
.tree
.values()
Expand All @@ -94,26 +98,21 @@ impl Asn1Parser {
self.tree
.keys()
.filter(move |n| !bases.contains(n))
.filter_map(|n| self.resolve(n).map(|p| (self.spec.clone(), n.clone(), p)))
.filter_map(|n| self.resolve(n).map(|p| (n.clone(), p)))
}
}

#[test]
fn test() {
let asn1 = super::Asn1Parser::new(
"none".into(),
r"
foo OBJECT IDENTIFIER ::= { bar(1) baz(2) 3 }
bat OBJECT IDENTIFIER ::= { foo qux(4) 5 }
quz OBJECT IDENTIFIER ::= { bat 6 }
",
);

let answer = (
"none".to_string(),
"quz".to_string(),
"1.2.3.4.5.6".to_string(),
);
let answer = ("quz".to_string(), "1.2.3.4.5.6".to_string());

let mut iter = asn1.iter();
assert_eq!(Some(answer), iter.next());
Expand Down
21 changes: 15 additions & 6 deletions const-oid/oiddbgen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@ use oiddbgen::{Asn1Parser, LdapParser, Root};
// https://www.iana.org/assignments/ldap-parameters/ldap-parameters.xhtml#ldap-parameters-3
const LDAP: &str = include_str!("../ldap-parameters-3.csv");

// Downloaded from:
// https://www.rfc-editor.org/rfc/rfc5280.txt
const RFC5280: &str = include_str!("../rfc5280.txt");
// All RFCs downloaded from:
// https://www.rfc-editor.org/rfc/rfcNNNN.txt
const RFCS: &[(&str, &str)] = &[
("rfc5280", include_str!("../rfc5280.txt")),
("rfc5911", include_str!("../rfc5911.txt")),
("rfc5912", include_str!("../rfc5912.txt")),
("rfc6268", include_str!("../rfc6268.txt")),
("rfc7107", include_str!("../rfc7107.txt")),
("rfc7299", include_str!("../rfc7299.txt")),
];

fn main() {
let mut root = Root::default();

for (spec, name, obid) in LdapParser::new(LDAP).iter() {
root.add(&spec, &name, &obid)
root.add(&spec, &name, &obid);
}

for (spec, name, obid) in Asn1Parser::new("rfc5280".into(), RFC5280).iter() {
root.add(&spec, &name, &obid)
for (spec, body) in RFCS {
for (name, obid) in Asn1Parser::new(body).iter() {
root.add(spec, &name, &obid);
}
}

println!("{}", root.module());
Expand Down
Loading

0 comments on commit 497991f

Please sign in to comment.