diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-12-24 09:19:09 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-12-24 09:19:09 -0600 |
commit | b9d9021b9961c8616b6ed4ec987d76dead284059 (patch) | |
tree | 9c9c918c92260e45dfceba3a339c38a43958b0ee /src | |
parent | b6519135245a524f8d1efdb7db31e70e6d782c23 (diff) | |
parent | 34a4754d21b8fa3590d50becb79e67a155df7113 (diff) | |
download | cryptography-b9d9021b9961c8616b6ed4ec987d76dead284059.tar.gz cryptography-b9d9021b9961c8616b6ed4ec987d76dead284059.tar.bz2 cryptography-b9d9021b9961c8616b6ed4ec987d76dead284059.zip |
Merge pull request #2563 from alex/crl-iter-perf
Simplify implementation of CRL indexing and iteration.
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/x509.py | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index 4699a7a5..7b9f71cd 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -861,24 +861,19 @@ class _CertificateRevocationList(object): self._backend.openssl_assert(res == 1) return self._backend._read_mem_bio(bio) - def _revoked_certificates(self): + def _revoked_cert(self, idx): revoked = self._backend._lib.X509_CRL_get_REVOKED(self._x509_crl) - revoked_list = [] - 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 + r = self._backend._lib.sk_X509_REVOKED_value(revoked, idx) + self._backend.openssl_assert(r != self._backend._ffi.NULL) + return _RevokedCertificate(self._backend, self, r) def __iter__(self): - return iter(self._revoked_certificates()) + for i in range(len(self)): + yield self._revoked_cert(i) def __getitem__(self, idx): - return self._revoked_certificates()[idx] + # TODO: indexing is O(n) + return list(self)[idx] def __len__(self): revoked = self._backend._lib.X509_CRL_get_REVOKED(self._x509_crl) |