aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-12-24 07:35:10 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-12-24 07:35:10 -0600
commitb6519135245a524f8d1efdb7db31e70e6d782c23 (patch)
treed71c5808126d7b48392ee67660aaf61584ece100
parent4c804930f4af99e6fff13789d1827752cb46da44 (diff)
parentaa37fbb9a6722d4497a677a02c7ec1a12ed55452 (diff)
downloadcryptography-b6519135245a524f8d1efdb7db31e70e6d782c23.tar.gz
cryptography-b6519135245a524f8d1efdb7db31e70e6d782c23.tar.bz2
cryptography-b6519135245a524f8d1efdb7db31e70e6d782c23.zip
Merge pull request #2561 from alex/crl-len-perf
Improve the performance of len(crl)
-rw-r--r--src/cryptography/hazmat/backends/openssl/x509.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py
index 12f5d46f..4699a7a5 100644
--- a/src/cryptography/hazmat/backends/openssl/x509.py
+++ b/src/cryptography/hazmat/backends/openssl/x509.py
@@ -864,15 +864,13 @@ class _CertificateRevocationList(object):
def _revoked_certificates(self):
revoked = self._backend._lib.X509_CRL_get_REVOKED(self._x509_crl)
revoked_list = []
- if revoked != self._backend._ffi.NULL:
- num = self._backend._lib.sk_X509_REVOKED_num(revoked)
- for i in range(num):
- r = self._backend._lib.sk_X509_REVOKED_value(revoked, i)
- self._backend.openssl_assert(r != self._backend._ffi.NULL)
- revoked_certificate = _RevokedCertificate(
- self._backend, self, r
- )
- revoked_list.append(revoked_certificate)
+ for i in range(len(self)):
+ r = self._backend._lib.sk_X509_REVOKED_value(revoked, i)
+ self._backend.openssl_assert(r != self._backend._ffi.NULL)
+ revoked_certificate = _RevokedCertificate(
+ self._backend, self, r
+ )
+ revoked_list.append(revoked_certificate)
return revoked_list
@@ -883,7 +881,11 @@ class _CertificateRevocationList(object):
return self._revoked_certificates()[idx]
def __len__(self):
- return len(self._revoked_certificates())
+ revoked = self._backend._lib.X509_CRL_get_REVOKED(self._x509_crl)
+ if revoked == self._backend._ffi.NULL:
+ return 0
+ else:
+ return self._backend._lib.sk_X509_REVOKED_num(revoked)
@property
def extensions(self):