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 8eb1d34e..3c017ea1 100644 --- a/src/cryptography/x509/extensions.py +++ b/src/cryptography/x509/extensions.py @@ -104,6 +104,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 f124a286..037512a4 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -896,6 +896,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( |