1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use crate::error::NidError;
use asn1_rs::{oid, Oid};
use lazy_static::lazy_static;
use oid_registry::*;
use std::collections::HashMap;
lazy_static! {
static ref OID_REGISTRY: OidRegistry<'static> = {
let mut reg = OidRegistry::default().with_all_crypto().with_x509();
let entry = OidEntry::new("id-mgf1", "Mask Generator Function 1 (MGF1)");
reg.insert(oid! {1.2.840.113549.1.1.8}, entry);
reg
};
static ref ABBREV_MAP: HashMap<Oid<'static>, &'static str> = {
let mut m = HashMap::new();
m.insert(OID_X509_COMMON_NAME, "CN");
m.insert(OID_X509_COUNTRY_NAME, "C");
m.insert(OID_X509_LOCALITY_NAME, "L");
m.insert(OID_X509_STATE_OR_PROVINCE_NAME, "ST");
m.insert(OID_X509_ORGANIZATION_NAME, "O");
m.insert(OID_X509_ORGANIZATIONAL_UNIT, "OU");
m.insert(OID_DOMAIN_COMPONENT, "DC");
m.insert(OID_PKCS9_EMAIL_ADDRESS, "Email");
m
};
}
pub fn oid2abbrev<'a>(oid: &'a Oid, registry: &'a OidRegistry) -> Result<&'a str, NidError> {
if let Some(abbrev) = ABBREV_MAP.get(oid) {
return Ok(abbrev);
}
registry.get(oid).map(|entry| entry.sn()).ok_or(NidError)
}
pub fn oid2sn<'a>(oid: &'a Oid, registry: &'a OidRegistry) -> Result<&'a str, NidError> {
registry.get(oid).map(|o| o.sn()).ok_or(NidError)
}
pub fn oid2description<'a>(oid: &'a Oid, registry: &'a OidRegistry) -> Result<&'a str, NidError> {
registry.get(oid).map(|o| o.description()).ok_or(NidError)
}
pub fn oid_registry() -> &'static OidRegistry<'static> {
&OID_REGISTRY
}
#[cfg(test)]
mod tests {
use super::*;
use der_parser::oid;
#[test]
fn test_oid_match() {
let oid = oid!(1.2.840 .113549 .1 .1 .5);
if oid == OID_PKCS1_SHA1WITHRSA {
}
}
}