aboutsummaryrefslogtreecommitdiffstats
path: root/src/cryptography/x509
diff options
context:
space:
mode:
authorMarti <marti@juffo.org>2016-08-26 04:26:31 +0300
committerPaul Kehrer <paul.l.kehrer@gmail.com>2016-08-26 09:26:31 +0800
commit40f1999de74a3bf44f000486a0ce1a58c82827e6 (patch)
treed7c3cb6ea4f0b3846cc8685669c75d963f43db64 /src/cryptography/x509
parenteafc4ee77f92d4e6e208351fd17e9cb1ae045677 (diff)
downloadcryptography-40f1999de74a3bf44f000486a0ce1a58c82827e6.tar.gz
cryptography-40f1999de74a3bf44f000486a0ce1a58c82827e6.tar.bz2
cryptography-40f1999de74a3bf44f000486a0ce1a58c82827e6.zip
Allow passing iterators where collections are expected (#3078)
Iterators can only be enumerated once, breaking code like this in Python 3 for example: san = SubjectAlternativeName(map(DNSName, lst)) This is also a slight behavior change if the caller modifies the list after passing it to the constructor, because input lists are now copied. Which seems like a good thing. Also: * Name now checks that attributes elements are of type NameAttribute * NoticeReference now allows notice_numbers to be any iterable
Diffstat (limited to 'src/cryptography/x509')
-rw-r--r--src/cryptography/x509/extensions.py72
-rw-r--r--src/cryptography/x509/name.py4
2 files changed, 45 insertions, 31 deletions
diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py
index b7ea72cd..c0705a3a 100644
--- a/src/cryptography/x509/extensions.py
+++ b/src/cryptography/x509/extensions.py
@@ -174,13 +174,15 @@ class AuthorityKeyIdentifier(object):
"must both be present or both None"
)
- if authority_cert_issuer is not None and not all(
- isinstance(x, GeneralName) for x in authority_cert_issuer
- ):
- raise TypeError(
- "authority_cert_issuer must be a list of GeneralName "
- "objects"
- )
+ if authority_cert_issuer is not None:
+ authority_cert_issuer = list(authority_cert_issuer)
+ if not all(
+ isinstance(x, GeneralName) for x in authority_cert_issuer
+ ):
+ raise TypeError(
+ "authority_cert_issuer must be a list of GeneralName "
+ "objects"
+ )
if authority_cert_serial_number is not None and not isinstance(
authority_cert_serial_number, six.integer_types
@@ -273,6 +275,7 @@ class AuthorityInformationAccess(object):
oid = ExtensionOID.AUTHORITY_INFORMATION_ACCESS
def __init__(self, descriptions):
+ descriptions = list(descriptions)
if not all(isinstance(x, AccessDescription) for x in descriptions):
raise TypeError(
"Every item in the descriptions list must be an "
@@ -386,6 +389,7 @@ class CRLDistributionPoints(object):
oid = ExtensionOID.CRL_DISTRIBUTION_POINTS
def __init__(self, distribution_points):
+ distribution_points = list(distribution_points)
if not all(
isinstance(x, DistributionPoint) for x in distribution_points
):
@@ -426,22 +430,22 @@ class DistributionPoint(object):
"least one must be None."
)
- if full_name and not all(
- isinstance(x, GeneralName) for x in full_name
- ):
- raise TypeError(
- "full_name must be a list of GeneralName objects"
- )
+ if full_name:
+ full_name = list(full_name)
+ if not all(isinstance(x, GeneralName) for x in full_name):
+ raise TypeError(
+ "full_name must be a list of GeneralName objects"
+ )
if relative_name and not isinstance(relative_name, Name):
raise TypeError("relative_name must be a Name")
- if crl_issuer and not all(
- isinstance(x, GeneralName) for x in crl_issuer
- ):
- raise TypeError(
- "crl_issuer must be None or a list of general names"
- )
+ if crl_issuer:
+ crl_issuer = list(crl_issuer)
+ if not all(isinstance(x, GeneralName) for x in crl_issuer):
+ raise TypeError(
+ "crl_issuer must be None or a list of general names"
+ )
if reasons and (not isinstance(reasons, frozenset) or not all(
isinstance(x, ReasonFlags) for x in reasons
@@ -569,6 +573,7 @@ class CertificatePolicies(object):
oid = ExtensionOID.CERTIFICATE_POLICIES
def __init__(self, policies):
+ policies = list(policies)
if not all(isinstance(x, PolicyInformation) for x in policies):
raise TypeError(
"Every item in the policies list must be a "
@@ -605,15 +610,17 @@ class PolicyInformation(object):
raise TypeError("policy_identifier must be an ObjectIdentifier")
self._policy_identifier = policy_identifier
- if policy_qualifiers and not all(
- isinstance(
- x, (six.text_type, UserNotice)
- ) for x in policy_qualifiers
- ):
- raise TypeError(
- "policy_qualifiers must be a list of strings and/or UserNotice"
- " objects or None"
- )
+
+ if policy_qualifiers:
+ policy_qualifiers = list(policy_qualifiers)
+ if not all(
+ isinstance(x, (six.text_type, UserNotice))
+ for x in policy_qualifiers
+ ):
+ raise TypeError(
+ "policy_qualifiers must be a list of strings and/or "
+ "UserNotice objects or None"
+ )
self._policy_qualifiers = policy_qualifiers
@@ -676,9 +683,8 @@ class UserNotice(object):
class NoticeReference(object):
def __init__(self, organization, notice_numbers):
self._organization = organization
- if not isinstance(notice_numbers, list) or not all(
- isinstance(x, int) for x in notice_numbers
- ):
+ notice_numbers = list(notice_numbers)
+ if not all(isinstance(x, int) for x in notice_numbers):
raise TypeError(
"notice_numbers must be a list of integers"
)
@@ -712,6 +718,7 @@ class ExtendedKeyUsage(object):
oid = ExtensionOID.EXTENDED_KEY_USAGE
def __init__(self, usages):
+ usages = list(usages)
if not all(isinstance(x, ObjectIdentifier) for x in usages):
raise TypeError(
"Every item in the usages list must be an ObjectIdentifier"
@@ -866,6 +873,7 @@ class NameConstraints(object):
def __init__(self, permitted_subtrees, excluded_subtrees):
if permitted_subtrees is not None:
+ permitted_subtrees = list(permitted_subtrees)
if not all(
isinstance(x, GeneralName) for x in permitted_subtrees
):
@@ -877,6 +885,7 @@ class NameConstraints(object):
self._validate_ip_name(permitted_subtrees)
if excluded_subtrees is not None:
+ excluded_subtrees = list(excluded_subtrees)
if not all(
isinstance(x, GeneralName) for x in excluded_subtrees
):
@@ -965,6 +974,7 @@ class Extension(object):
class GeneralNames(object):
def __init__(self, general_names):
+ general_names = list(general_names)
if not all(isinstance(x, GeneralName) for x in general_names):
raise TypeError(
"Every item in the general_names list must be an "
diff --git a/src/cryptography/x509/name.py b/src/cryptography/x509/name.py
index d62341d7..7e55f6e3 100644
--- a/src/cryptography/x509/name.py
+++ b/src/cryptography/x509/name.py
@@ -54,6 +54,10 @@ class NameAttribute(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
def get_attributes_for_oid(self, oid):