From a68fd33ca8518a734b655457eca9ab28ccbcb7bb Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Thu, 27 Nov 2014 07:08:40 -1000 Subject: address review feedback --- docs/exceptions.rst | 5 ----- docs/x509.rst | 7 ++++++- src/cryptography/exceptions.py | 4 ---- src/cryptography/hazmat/backends/openssl/x509.py | 5 ++--- src/cryptography/x509.py | 4 ++++ tests/test_x509.py | 7 +++---- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/exceptions.rst b/docs/exceptions.rst index b86d3eea..28da8ecc 100644 --- a/docs/exceptions.rst +++ b/docs/exceptions.rst @@ -43,8 +43,3 @@ Exceptions This is raised when the verify method of a one time password function's computed token does not match the expected token. - - -.. class:: InvalidX509Version - - This is raised when an X.509 certificate has an invalid version number. diff --git a/docs/x509.rst b/docs/x509.rst index 2c9c0f46..ba52d91a 100644 --- a/docs/x509.rst +++ b/docs/x509.rst @@ -6,7 +6,8 @@ X.509 .. currentmodule:: cryptography.x509 X.509 is an ITU-T standard for a `public key infrastructure`_. X.509v3 is -defined in :rfc:`5280` (which obsoletes :rfc:`2459` and :rfc:`3280`). +defined in :rfc:`5280` (which obsoletes :rfc:`2459` and :rfc:`3280`). X.509 +certificates are commonly used in protocols like `TLS`_. Loading ~~~~~~~ @@ -92,6 +93,10 @@ Support Classes For version 3 X.509 certificates. +.. class:: InvalidX509Version + + This is raised when an X.509 certificate has an invalid version number. .. _`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/exceptions.py b/src/cryptography/exceptions.py index 23edcd02..b0e1a993 100644 --- a/src/cryptography/exceptions.py +++ b/src/cryptography/exceptions.py @@ -53,7 +53,3 @@ class InvalidKey(Exception): class InvalidToken(Exception): pass - - -class InvalidX509Version(Exception): - pass diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index 9f6f71d0..6befc3cf 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -16,7 +16,6 @@ from __future__ import absolute_import, division, print_function import datetime from cryptography import utils, x509 -from cryptography.exceptions import InvalidX509Version from cryptography.hazmat.primitives import hashes, interfaces @@ -61,8 +60,8 @@ class _X509Certificate(object): elif version == 2: return x509.X509Version.v3 else: - raise InvalidX509Version( - "{0} is not a valid X509 version", version + raise x509.InvalidX509Version( + "{0} is not a valid X509 version".format(version) ) @property diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py index f3c73d6b..191666e6 100644 --- a/src/cryptography/x509.py +++ b/src/cryptography/x509.py @@ -18,3 +18,7 @@ def load_pem_x509_certificate(data, backend): def load_der_x509_certificate(data, backend): return backend.load_der_x509_certificate(data) + + +class InvalidX509Version(Exception): + pass diff --git a/tests/test_x509.py b/tests/test_x509.py index f50a82ae..df27f8d0 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -10,7 +10,6 @@ import os import pytest from cryptography import x509 -from cryptography.exceptions import InvalidX509Version from cryptography.hazmat.backends.interfaces import ( DSABackend, EllipticCurveBackend, RSABackend, X509Backend ) @@ -43,7 +42,7 @@ class TestRSAX509Certificate(object): pemfile.read(), backend ) ) - assert cert + assert isinstance(cert, interfaces.X509Certificate) def test_load_der_cert(self, backend): cert = load_vectors_from_file( @@ -53,7 +52,7 @@ class TestRSAX509Certificate(object): derfile.read(), backend ) ) - assert cert + assert isinstance(cert, interfaces.X509Certificate) def test_load_good_ca_cert(self, backend): cert = _load_der_cert("GoodCACert.crt", backend) @@ -117,7 +116,7 @@ class TestRSAX509Certificate(object): pemfile.read(), backend ) ) - with pytest.raises(InvalidX509Version): + with pytest.raises(x509.InvalidX509Version): cert.version def test_version_1_cert(self, backend): -- cgit v1.2.3