diff options
author | Fraser Tweedale <frase@frase.id.au> | 2016-11-12 01:28:56 +1000 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-11-11 07:28:56 -0800 |
commit | 01ee6f5e391eee76e6cd3062de8fc84851bd06e3 (patch) | |
tree | 3309443a73201bcec03c5bb14df019e49eae798c /src/cryptography/x509/name.py | |
parent | 44eb89e911db7298a29640c9073c9e2ff4d5f806 (diff) | |
download | cryptography-01ee6f5e391eee76e6cd3062de8fc84851bd06e3.tar.gz cryptography-01ee6f5e391eee76e6cd3062de8fc84851bd06e3.tar.bz2 cryptography-01ee6f5e391eee76e6cd3062de8fc84851bd06e3.zip |
Name: add support for multi-value RDNs (#3202)
Update the Name class to accept and internally store a list of
RelativeDistinguishedName objects. Add the 'rdns' attribute to give
access to the RDNs. Update ASN.1 routines to correctly decode and
encode multi-value RDNs.
Fixes: https://github.com/pyca/cryptography/issues/3199
Diffstat (limited to 'src/cryptography/x509/name.py')
-rw-r--r-- | src/cryptography/x509/name.py | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/cryptography/x509/name.py b/src/cryptography/x509/name.py index 7dc80646..fedfd78f 100644 --- a/src/cryptography/x509/name.py +++ b/src/cryptography/x509/name.py @@ -90,14 +90,25 @@ class RelativeDistinguishedName(object): class Name(object): def __init__(self, attributes): attributes = list(attributes) - if not all(isinstance(x, NameAttribute) for x in attributes): - raise TypeError("attributes must be a list of NameAttribute") - - self._attributes = attributes + if all(isinstance(x, NameAttribute) for x in attributes): + self._attributes = [ + RelativeDistinguishedName([x]) for x in attributes + ] + elif all(isinstance(x, RelativeDistinguishedName) for x in attributes): + self._attributes = attributes + else: + raise TypeError( + "attributes must be a list of NameAttribute" + " or a list RelativeDistinguishedName" + ) def get_attributes_for_oid(self, oid): return [i for i in self if i.oid == oid] + @property + def rdns(self): + return self._attributes + def __eq__(self, other): if not isinstance(other, Name): return NotImplemented @@ -113,10 +124,12 @@ class Name(object): return hash(tuple(self._attributes)) def __iter__(self): - return iter(self._attributes) + for rdn in self._attributes: + for ava in rdn: + yield ava def __len__(self): - return len(self._attributes) + return sum(len(rdn) for rdn in self._attributes) def __repr__(self): - return "<Name({0!r})>".format(self._attributes) + return "<Name({0!r})>".format(list(self)) |