simplify things based on review feedback
diff --git a/docs/x509.rst b/docs/x509.rst
index 473efc3..099d3f8 100644
--- a/docs/x509.rst
+++ b/docs/x509.rst
@@ -195,12 +195,13 @@
.. doctest::
- >>> assert len(cert.subject) == 3
- >>> attributes = []
- >>> for attribute in cert.subject:
- ... attributes.append(attribute)
- >>> len(attributes)
+ >>> len(cert.subject)
3
+ >>> for attribute in cert.subject:
+ ... print(attribute)
+ <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
+ <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
+ <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
.. method:: get_attributes_for_oid(oid)
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py
index ebfbf33..76dcf32 100644
--- a/src/cryptography/hazmat/backends/openssl/x509.py
+++ b/src/cryptography/hazmat/backends/openssl/x509.py
@@ -115,6 +115,7 @@
assert data != self._backend._ffi.NULL
buf = self._backend._ffi.new("unsigned char **")
res = self._backend._lib.ASN1_STRING_to_UTF8(buf, data)
+ assert res >= 0
assert buf[0] != self._backend._ffi.NULL
buf = self._backend._ffi.gc(
buf, lambda buf: self._backend._lib.OPENSSL_free(buf[0])
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index 21693ed..8a888d2 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -121,7 +121,7 @@
return not self == other
def __iter__(self):
- return iter(self._attributes[:])
+ return iter(self._attributes)
def __len__(self):
return len(self._attributes)
diff --git a/tests/test_x509.py b/tests/test_x509.py
index 0e95b25..55a9408 100644
--- a/tests/test_x509.py
+++ b/tests/test_x509.py
@@ -68,10 +68,7 @@
)
issuer = cert.issuer
assert isinstance(issuer, x509.Name)
- attributes = []
- for attrs in issuer:
- attributes.append(attrs)
- assert attributes == [
+ assert list(issuer) == [
x509.NameAttribute(x509.OID_COUNTRY_NAME, 'US'),
x509.NameAttribute(
x509.OID_ORGANIZATION_NAME, 'Test Certificates 2011'
@@ -94,10 +91,7 @@
issuer = cert.issuer
assert isinstance(issuer, x509.Name)
- attributes = []
- for attrs in issuer:
- attributes.append(attrs)
- assert attributes == [
+ assert list(issuer) == [
x509.NameAttribute(x509.OID_COUNTRY_NAME, 'US'),
x509.NameAttribute(x509.OID_COUNTRY_NAME, 'CA'),
x509.NameAttribute(x509.OID_STATE_OR_PROVINCE_NAME, 'Texas'),
@@ -141,10 +135,7 @@
)
subject = cert.subject
assert isinstance(subject, x509.Name)
- attributes = []
- for attrs in subject:
- attributes.append(attrs)
- assert attributes == [
+ assert list(subject) == [
x509.NameAttribute(x509.OID_COUNTRY_NAME, 'US'),
x509.NameAttribute(
x509.OID_ORGANIZATION_NAME, 'Test Certificates 2011'
@@ -194,10 +185,7 @@
)
subject = cert.subject
assert isinstance(subject, x509.Name)
- attributes = []
- for attrs in subject:
- attributes.append(attrs)
- assert attributes == [
+ assert list(subject) == [
x509.NameAttribute(x509.OID_COUNTRY_NAME, 'AU'),
x509.NameAttribute(x509.OID_COUNTRY_NAME, 'DE'),
x509.NameAttribute(x509.OID_STATE_OR_PROVINCE_NAME, 'California'),