def TraverseRdn(rdn):
"""Traverses RDN structure and returns string encoding of the DN.
Args:
rdn: ASN.1 SET (or SEQUENCE) containing RDNs (relative distinguished
names), as identified by type / value pairs. A typical input would
be of type X.509 RelativeDistinguishedName.
Returns:
A dict representing the Distinguished Name.
"""
val = dict()
for n in rdn:
# Note that this does not work for e.g. DC which is present
# multiple times.
# For a real DN parser, make sure to follow the spec in regards
# to multiple occurence of a field in subsequent RDNs, maintaining
# original ordering etc.
# TODO(user): What about elements other than [0]??
name = DistinguishedName.OidToName(n[0]['type'])
value = decoder.decode(n[0]['value'])
if name in val:
val[name] = str(value[0]) + ', ' + val.get(name, '')
else:
val[name] = str(value[0])
return val
评论列表
文章目录