diff options
author | Rob Austein <sra@hactrn.net> | 2012-08-07 21:54:43 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2012-08-07 21:54:43 +0000 |
commit | 0ffc84f40bf25c778e20d49be33eebab3c7612e5 (patch) | |
tree | 5c8697f03aeebe645f4d8c84274c9c96f5ceb243 /rpkid/rpki/oids.py | |
parent | 0d561ccb89555aae11482449dc8477c6cf4d0799 (diff) |
Safe mapping functions for OIDs, now that we're using the same code to
deal with BPKI certificates with all the whacky distinguished name
fields allowed by X.509, or at least by PKIX. See #279.
svn path=/trunk/; revision=4621
Diffstat (limited to 'rpkid/rpki/oids.py')
-rw-r--r-- | rpkid/rpki/oids.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/rpkid/rpki/oids.py b/rpkid/rpki/oids.py index 1e67dff9..2b8302aa 100644 --- a/rpkid/rpki/oids.py +++ b/rpkid/rpki/oids.py @@ -69,9 +69,39 @@ oid2name = { (2, 5, 4, 3) : "commonName", (2, 5, 4, 5) : "serialNumber", (2, 5, 4, 6) : "countryName", + (2, 5, 4, 7) : "localityName", + (2, 5, 4, 8) : "stateOrProvinceName", + (2, 5, 4, 9) : "streetAddress", + (2, 5, 4, 10) : "organizationName", + (2, 5, 4, 11) : "organizationalUnitName", } ## @var name2oid # Mapping table of string names to OIDs name2oid = dict((v, k) for k, v in oid2name.items()) + +def safe_name2oid(name): + """ + Map name to OID, also parsing numeric (dotted decimal) format. + """ + + try: + return name2oid[name] + except KeyError: + fields = name.split(".") + if all(field.isdigit() for field in fields): + return tuple(int(field) for field in fields) + else: + raise + +def safe_oid2name(oid): + """ + Map OID to name. If we have no mapping, generate numeric (dotted + decimal) format. + """ + + try: + return oid2name[oid] + except KeyError: + return ".".join(str(field) for field in oid) |