diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-12-23 23:22:35 -0500 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2015-12-23 23:22:35 -0500 |
commit | cc4c323f1192d81f46aa2da402f7b916fa120e02 (patch) | |
tree | 2418502c83245294005661fdcb12595b49ec1fcb | |
parent | 8c52c203accd5fdb35fcdae33bbf3fa172c7879f (diff) | |
download | cryptography-cc4c323f1192d81f46aa2da402f7b916fa120e02.tar.gz cryptography-cc4c323f1192d81f46aa2da402f7b916fa120e02.tar.bz2 cryptography-cc4c323f1192d81f46aa2da402f7b916fa120e02.zip |
Improve the performance of len(crl)
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/x509.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index 12f5d46f..b342cd8a 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -865,8 +865,7 @@ class _CertificateRevocationList(object): 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): + 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( @@ -883,7 +882,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): |