aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-12-26 14:46:58 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-12-26 14:46:58 -0600
commit8adb59643b7c1219cd286c53243a401b1da0f285 (patch)
tree8588250d5c7999fecca72b00faa57b34014842c6
parent3bcd2d778f91e10a78ec5af3b53abbbc388fd7c2 (diff)
downloadcryptography-8adb59643b7c1219cd286c53243a401b1da0f285.tar.gz
cryptography-8adb59643b7c1219cd286c53243a401b1da0f285.tar.bz2
cryptography-8adb59643b7c1219cd286c53243a401b1da0f285.zip
support indexing on GeneralNames and SubjectAlternativeName
-rw-r--r--src/cryptography/x509/extensions.py6
-rw-r--r--tests/test_x509_ext.py26
2 files changed, 32 insertions, 0 deletions
diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py
index 0eed21b9..f5fb1345 100644
--- a/src/cryptography/x509/extensions.py
+++ b/src/cryptography/x509/extensions.py
@@ -894,6 +894,9 @@ class GeneralNames(object):
def __ne__(self, other):
return not self == other
+ def __getitem__(self, idx):
+ return self._general_names[idx]
+
@utils.register_interface(ExtensionType)
class SubjectAlternativeName(object):
@@ -920,6 +923,9 @@ class SubjectAlternativeName(object):
return self._general_names == other._general_names
+ def __getitem__(self, idx):
+ return self._general_names[idx]
+
def __ne__(self, other):
return not self == other
diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py
index a12a48fc..e7252623 100644
--- a/tests/test_x509_ext.py
+++ b/tests/test_x509_ext.py
@@ -1483,6 +1483,19 @@ class TestGeneralNames(object):
x509.DNSName(u"crypto.local"),
]
+ def test_indexing(self):
+ gn = x509.GeneralNames([
+ x509.DNSName(u"cryptography.io"),
+ x509.DNSName(u"crypto.local"),
+ x509.DNSName(u"another.local"),
+ x509.RFC822Name(u"email@another.local"),
+ x509.UniformResourceIdentifier(u"http://another.local"),
+ ])
+ assert gn[-1] == gn[4]
+ assert len(gn[1:3]) == 2
+ assert gn[2:4][0] == gn[2]
+ assert gn[2:5:2][1] == gn[4]
+
def test_invalid_general_names(self):
with pytest.raises(TypeError):
x509.GeneralNames(
@@ -1637,6 +1650,19 @@ class TestSubjectAlternativeName(object):
x509.DNSName(u"crypto.local"),
]
+ def test_indexing(self):
+ san = x509.SubjectAlternativeName([
+ x509.DNSName(u"cryptography.io"),
+ x509.DNSName(u"crypto.local"),
+ x509.DNSName(u"another.local"),
+ x509.RFC822Name(u"email@another.local"),
+ x509.UniformResourceIdentifier(u"http://another.local"),
+ ])
+ assert san[-1] == san[4]
+ assert len(san[1:3]) == 2
+ assert san[2:4][0] == san[2]
+ assert san[2:5:2][1] == san[4]
+
def test_invalid_general_names(self):
with pytest.raises(TypeError):
x509.SubjectAlternativeName(