From 8b21a4a34a82ca0e73ca67bd3f148b25d6c7bdc6 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sat, 14 Feb 2015 07:56:36 -0600 Subject: simplify things based on review feedback --- docs/x509.rst | 11 ++++++----- src/cryptography/hazmat/backends/openssl/x509.py | 1 + src/cryptography/x509.py | 2 +- tests/test_x509.py | 20 ++++---------------- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/docs/x509.rst b/docs/x509.rst index 473efc36..099d3f87 100644 --- a/docs/x509.rst +++ b/docs/x509.rst @@ -195,12 +195,13 @@ X.509 Certificate Object .. 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) + , value=u'US')> + , value=u'Test Certificates 2011')> + , 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 ebfbf331..76dcf32f 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -115,6 +115,7 @@ class _Certificate(object): 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 21693ed4..8a888d2a 100644 --- a/src/cryptography/x509.py +++ b/src/cryptography/x509.py @@ -121,7 +121,7 @@ class Name(object): 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 0e95b258..55a94084 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -68,10 +68,7 @@ class TestRSACertificate(object): ) 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 @@ class TestRSACertificate(object): 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 @@ class TestRSACertificate(object): ) 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 @@ class TestRSACertificate(object): ) 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'), -- cgit v1.2.3