summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-15 17:20:33 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-15 17:20:33 -0600
commitd5cccf7a376f4cf81cab6649646af0f09f5389ac (patch)
treeafdf7ad94784d12d02e9b95aa9569fdbda21ec33
parent25014658d6d7df3a97f72a5a65c6833a3364c51e (diff)
downloadcryptography-d5cccf7a376f4cf81cab6649646af0f09f5389ac.tar.gz
add parsed_version attribute to InvalidVersion
-rw-r--r--docs/x509.rst4
-rw-r--r--src/cryptography/hazmat/backends/openssl/x509.py2
-rw-r--r--src/cryptography/x509.py4
-rw-r--r--tests/test_x509.py4
4 files changed, 11 insertions, 3 deletions
diff --git a/docs/x509.rst b/docs/x509.rst
index 5278d07b2..e44f16c16 100644
--- a/docs/x509.rst
+++ b/docs/x509.rst
@@ -153,6 +153,10 @@ X.509 Certificate Object
This is raised when an X.509 certificate has an invalid version number.
+ .. attribute:: parsed_version
+
+ Returns the version that was parsed from the certificate.
+
.. _`public key infrastructure`: https://en.wikipedia.org/wiki/Public_key_infrastructure
.. _`TLS`: https://en.wikipedia.org/wiki/Transport_Layer_Security
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py
index 9a1fcc8d1..0828f3cc0 100644
--- a/src/cryptography/hazmat/backends/openssl/x509.py
+++ b/src/cryptography/hazmat/backends/openssl/x509.py
@@ -45,7 +45,7 @@ class _Certificate(object):
return x509.Version.v3
else:
raise x509.InvalidVersion(
- "{0} is not a valid X509 version".format(version)
+ "{0} is not a valid X509 version".format(version), version
)
@property
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index c79d11716..be1298b67 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -24,7 +24,9 @@ def load_der_x509_certificate(data, backend):
class InvalidVersion(Exception):
- pass
+ def __init__(self, msg, parsed_version):
+ super(InvalidVersion, self).__init__(msg)
+ self.parsed_version = parsed_version
@six.add_metaclass(abc.ABCMeta)
diff --git a/tests/test_x509.py b/tests/test_x509.py
index f8d19a54a..5383871ac 100644
--- a/tests/test_x509.py
+++ b/tests/test_x509.py
@@ -140,9 +140,11 @@ class TestRSACertificate(object):
x509.load_pem_x509_certificate,
backend
)
- with pytest.raises(x509.InvalidVersion):
+ with pytest.raises(x509.InvalidVersion) as exc:
cert.version
+ assert exc.value.parsed_version == 7
+
def test_version_1_cert(self, backend):
cert = _load_cert(
os.path.join("x509", "v1_cert.pem"),