diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-12-26 17:45:20 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-12-26 17:45:20 -0600 |
commit | 5c999d3429c27440789f998a4212805ce4e7be99 (patch) | |
tree | 2e7eb6961a98a1168827905570f2a16cd3f93d8d | |
parent | f4ca79443de298bc62323190fe0a3efb7d25f4af (diff) | |
download | cryptography-5c999d3429c27440789f998a4212805ce4e7be99.tar.gz cryptography-5c999d3429c27440789f998a4212805ce4e7be99.tar.bz2 cryptography-5c999d3429c27440789f998a4212805ce4e7be99.zip |
make CertificateIssuer and IssuerAlternativeName indexable
-rw-r--r-- | src/cryptography/x509/extensions.py | 6 | ||||
-rw-r--r-- | tests/test_x509_ext.py | 22 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py index 10b8da41..4dee72f0 100644 --- a/src/cryptography/x509/extensions.py +++ b/src/cryptography/x509/extensions.py @@ -961,6 +961,9 @@ class IssuerAlternativeName(object): def __ne__(self, other): return not self == other + def __getitem__(self, idx): + return self._general_names[idx] + @utils.register_interface(ExtensionType) class CertificateIssuer(object): @@ -990,6 +993,9 @@ class CertificateIssuer(object): def __ne__(self, other): return not self == other + def __getitem__(self, idx): + return self._general_names[idx] + @utils.register_interface(ExtensionType) class CRLReason(object): diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index f8023005..67081b23 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -87,6 +87,17 @@ class TestCertificateIssuer(object): x509.DNSName(u"crypto.local"), ] + def test_indexing(self): + ci = x509.CertificateIssuer([ + 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 ci[-1] == ci[4] + assert ci[2:6:2] == [ci[2], ci[4]] + def test_eq(self): ci1 = x509.CertificateIssuer([x509.DNSName(u"cryptography.io")]) ci2 = x509.CertificateIssuer([x509.DNSName(u"cryptography.io")]) @@ -1561,6 +1572,17 @@ class TestIssuerAlternativeName(object): x509.DNSName(u"crypto.local"), ] + def test_indexing(self): + ian = x509.IssuerAlternativeName([ + 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 ian[-1] == ian[4] + assert ian[2:6:2] == [ian[2], ian[4]] + def test_invalid_general_names(self): with pytest.raises(TypeError): x509.IssuerAlternativeName( |