diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-12-30 21:03:26 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-12-30 21:03:26 -0600 |
commit | e69c5fe0649adcfb1c540c39e2b296ad44cde244 (patch) | |
tree | 04baa988849f11c1b58ace4371864a1b9b2472ff | |
parent | 7640889dbbc379fe1f164cbd3094b2189aa655ba (diff) | |
download | cryptography-e69c5fe0649adcfb1c540c39e2b296ad44cde244.tar.gz cryptography-e69c5fe0649adcfb1c540c39e2b296ad44cde244.tar.bz2 cryptography-e69c5fe0649adcfb1c540c39e2b296ad44cde244.zip |
don't allow UnrecognizedExtension with get_extension_for_class
-rw-r--r-- | src/cryptography/x509/extensions.py | 7 | ||||
-rw-r--r-- | tests/test_x509_ext.py | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py index 0c5b5523..f7b5d7f5 100644 --- a/src/cryptography/x509/extensions.py +++ b/src/cryptography/x509/extensions.py @@ -91,6 +91,13 @@ class Extensions(object): raise ExtensionNotFound("No {0} extension was found".format(oid), oid) def get_extension_for_class(self, extclass): + if extclass is UnrecognizedExtension: + raise TypeError( + "UnrecognizedExtension can't be used with " + "get_extension_for_class because more than one instance of the" + " class may be present." + ) + for ext in self: if isinstance(ext.value, extclass): return ext diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 7c5ca5f2..df796e0a 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -1057,6 +1057,11 @@ class TestExtensions(object): exts.get_extension_for_class(x509.IssuerAlternativeName) assert exc.value.oid == ExtensionOID.ISSUER_ALTERNATIVE_NAME + def test_unrecognized_extension_for_class(self): + exts = x509.Extensions([]) + with pytest.raises(TypeError): + exts.get_extension_for_class(x509.UnrecognizedExtension) + def test_indexing(self, backend): cert = _load_cert( os.path.join("x509", "cryptography.io.pem"), |