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
use crate::error::NidError;
use der_parser::oid::Oid;
use lazy_static::lazy_static;
use oid_registry::*;
use std::collections::HashMap;
lazy_static! {
static ref OID_REGISTRY: OidRegistry<'static> = {
let reg = OidRegistry::default().with_all_crypto().with_x509();
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) -> Result<&'a str, NidError> {
if let Some(abbrev) = ABBREV_MAP.get(oid) {
return Ok(abbrev);
}
OID_REGISTRY
.get(oid)
.map(|entry| entry.sn())
.ok_or(NidError)
}
pub fn oid2sn<'a>(oid: &'a Oid) -> Result<&'a str, NidError> {
OID_REGISTRY.get(oid).map(|ref o| o.sn()).ok_or(NidError)
}
#[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 {
}
}
}