diff options
-rw-r--r-- | src/cryptography/x509/extensions.py | 3 | ||||
-rw-r--r-- | tests/test_x509_ext.py | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py index 15feb717..7ec653d0 100644 --- a/src/cryptography/x509/extensions.py +++ b/src/cryptography/x509/extensions.py @@ -102,6 +102,9 @@ class Extensions(object): def __len__(self): return len(self._extensions) + def __getitem__(self, idx): + return self._extensions[idx] + def __repr__(self): return ( "<Extensions({0})>".format(self._extensions) diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index d9743c8e..1144d47a 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -858,6 +858,18 @@ class TestExtensions(object): exts.get_extension_for_class(x509.IssuerAlternativeName) assert exc.value.oid == ExtensionOID.ISSUER_ALTERNATIVE_NAME + def test_indexing(self, backend): + cert = _load_cert( + os.path.join("x509", "cryptography.io.pem"), + x509.load_pem_x509_certificate, + backend + ) + exts = cert.extensions + assert exts[-1] == exts[7] + assert len(exts[3:5]) == 2 + assert exts[2:4][0] == exts[2] + assert exts[2:4][1] == exts[3] + def test_one_extension_get_for_class(self, backend): cert = _load_cert( os.path.join( |