From 01f90a1b010754c37a332b1b432bca73f7c529a2 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 7 Feb 2019 09:14:48 -0500 Subject: [PATCH] Removed deprecated Type aliases (#814) * Removed deprecated Type aliases * typo * typo * missed this somehow * Line wrap --- CHANGELOG.rst | 5 ++- src/OpenSSL/SSL.py | 14 ------- src/OpenSSL/crypto.py | 71 ------------------------------------ tests/test_crypto.py | 85 +++++++++++++++---------------------------- tests/test_ssl.py | 10 ++--- 5 files changed, 35 insertions(+), 150 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7d77f74a8..ee8dda437 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,8 +11,9 @@ The third digit is only for regressions. Backward-incompatible changes: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -*none* - +- Removed deprecated ``ContextType``, ``ConnectionType``, ``PKeyType``, ``X509NameType``, ``X509ReqType``, ``X509Type``, ``X509StoreType``, ``CRLType``, ``PKCS7Type``, ``PKCS12Type``, and ``NetscapeSPKIType`` aliases. + Use the classes without the ``Type`` suffix instead. + `#814 `_ Deprecations: ^^^^^^^^^^^^^ diff --git a/src/OpenSSL/SSL.py b/src/OpenSSL/SSL.py index 0687fc318..5d07b262d 100644 --- a/src/OpenSSL/SSL.py +++ b/src/OpenSSL/SSL.py @@ -6,8 +6,6 @@ from weakref import WeakValueDictionary from errno import errorcode -from cryptography.utils import deprecated - from six import ( binary_type as _binary_type, integer_types as integer_types, int2byte, indexbytes) @@ -1528,12 +1526,6 @@ def set_ocsp_client_callback(self, callback, data=None): self._set_ocsp_callback(helper, data) -ContextType = deprecated( - Context, __name__, - "ContextType has been deprecated, use Context instead", DeprecationWarning -) - - class Connection(object): """ """ @@ -2496,12 +2488,6 @@ def request_ocsp(self): _openssl_assert(rc == 1) -ConnectionType = deprecated( - Connection, __name__, - "ConnectionType has been deprecated, use Connection instead", - DeprecationWarning -) - # This is similar to the initialization calls at the end of OpenSSL/crypto.py # but is exercised mostly by the Context initializer. _lib.SSL_library_init() diff --git a/src/OpenSSL/crypto.py b/src/OpenSSL/crypto.py index b8d636f12..5a734ccd9 100644 --- a/src/OpenSSL/crypto.py +++ b/src/OpenSSL/crypto.py @@ -11,7 +11,6 @@ from cryptography import x509 from cryptography.hazmat.primitives.asymmetric import dsa, rsa -from cryptography.utils import deprecated from OpenSSL._util import ( ffi as _ffi, @@ -367,13 +366,6 @@ def bits(self): return _lib.EVP_PKEY_bits(self._pkey) -PKeyType = deprecated( - PKey, __name__, - "PKeyType has been deprecated, use PKey instead", - DeprecationWarning -) - - class _EllipticCurve(object): """ A representation of a supported elliptic curve. @@ -706,13 +698,6 @@ def get_components(self): return result -X509NameType = deprecated( - X509Name, __name__, - "X509NameType has been deprecated, use X509Name instead", - DeprecationWarning -) - - class X509Extension(object): """ An X.509 v3 certificate extension. @@ -864,13 +849,6 @@ def get_data(self): return _ffi.buffer(char_result, result_length)[:] -X509ExtensionType = deprecated( - X509Extension, __name__, - "X509ExtensionType has been deprecated, use X509Extension instead", - DeprecationWarning -) - - class X509Req(object): """ An X.509 certificate signing requests. @@ -1070,13 +1048,6 @@ def verify(self, pkey): return result -X509ReqType = deprecated( - X509Req, __name__, - "X509ReqType has been deprecated, use X509Req instead", - DeprecationWarning -) - - class X509(object): """ An X.509 certificate. @@ -1543,13 +1514,6 @@ def get_extension(self, index): return ext -X509Type = deprecated( - X509, __name__, - "X509Type has been deprecated, use X509 instead", - DeprecationWarning -) - - class X509StoreFlags(object): """ Flags for X509 verification, used to change the behavior of @@ -1684,13 +1648,6 @@ def set_time(self, vfy_time): _openssl_assert(_lib.X509_STORE_set1_param(self._store, param) != 0) -X509StoreType = deprecated( - X509Store, __name__, - "X509StoreType has been deprecated, use X509Store instead", - DeprecationWarning -) - - class X509StoreContextError(Exception): """ An exception raised when an error occurred while verifying a certificate @@ -2338,13 +2295,6 @@ def export(self, cert, key, type=FILETYPE_PEM, days=100, return dump_crl(type, self) -CRLType = deprecated( - CRL, __name__, - "CRLType has been deprecated, use CRL instead", - DeprecationWarning -) - - class PKCS7(object): def type_is_signed(self): """ @@ -2389,13 +2339,6 @@ def get_type_name(self): return _ffi.string(string_type) -PKCS7Type = deprecated( - PKCS7, __name__, - "PKCS7Type has been deprecated, use PKCS7 instead", - DeprecationWarning -) - - class PKCS12(object): """ A PKCS #12 archive. @@ -2570,13 +2513,6 @@ def export(self, passphrase=None, iter=2048, maciter=1): return _bio_to_string(bio) -PKCS12Type = deprecated( - PKCS12, __name__, - "PKCS12Type has been deprecated, use PKCS12 instead", - DeprecationWarning -) - - class NetscapeSPKI(object): """ A Netscape SPKI object. @@ -2667,13 +2603,6 @@ def set_pubkey(self, pkey): _openssl_assert(set_result == 1) -NetscapeSPKIType = deprecated( - NetscapeSPKI, __name__, - "NetscapeSPKIType has been deprecated, use NetscapeSPKI instead", - DeprecationWarning -) - - class _PassphraseHelper(object): def __init__(self, type, passphrase, more_args=False, truncate=False): if type != FILETYPE_PEM and passphrase is not None: diff --git a/tests/test_crypto.py b/tests/test_crypto.py index fcce6640b..9d943a943 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -22,26 +22,25 @@ import flaky -from OpenSSL.crypto import TYPE_RSA, TYPE_DSA, Error, PKey, PKeyType -from OpenSSL.crypto import X509, X509Type, X509Name, X509NameType +from OpenSSL.crypto import TYPE_RSA, TYPE_DSA, Error, PKey +from OpenSSL.crypto import X509, X509Name from OpenSSL.crypto import ( X509Store, X509StoreFlags, - X509StoreType, X509StoreContext, X509StoreContextError ) -from OpenSSL.crypto import X509Req, X509ReqType -from OpenSSL.crypto import X509Extension, X509ExtensionType +from OpenSSL.crypto import X509Req +from OpenSSL.crypto import X509Extension from OpenSSL.crypto import load_certificate, load_privatekey from OpenSSL.crypto import load_publickey, dump_publickey from OpenSSL.crypto import FILETYPE_PEM, FILETYPE_ASN1, FILETYPE_TEXT from OpenSSL.crypto import dump_certificate, load_certificate_request from OpenSSL.crypto import dump_certificate_request, dump_privatekey -from OpenSSL.crypto import PKCS7, PKCS7Type, load_pkcs7_data -from OpenSSL.crypto import PKCS12, PKCS12Type, load_pkcs12 +from OpenSSL.crypto import PKCS7, load_pkcs7_data +from OpenSSL.crypto import PKCS12, load_pkcs12 from OpenSSL.crypto import CRL, Revoked, dump_crl, load_crl -from OpenSSL.crypto import NetscapeSPKI, NetscapeSPKIType +from OpenSSL.crypto import NetscapeSPKI from OpenSSL.crypto import ( sign, verify, get_elliptic_curve, get_elliptic_curves) @@ -609,10 +608,8 @@ def test_str(self): def test_type(self): """ - `X509Extension` and `X509ExtensionType` refer to the same type object - and can be used to create instances of that type. + `X509Extension` can be used to create instances of that type. """ - assert X509Extension is X509ExtensionType assert is_consistent_type( X509Extension, 'X509Extension', b'basicConstraints', True, b'CA:true') @@ -620,13 +617,13 @@ def test_type(self): def test_construction(self): """ `X509Extension` accepts an extension type name, a critical flag, - and an extension value and returns an `X509ExtensionType` instance. + and an extension value and returns an `X509Extension` instance. """ basic = X509Extension(b'basicConstraints', True, b'CA:true') - assert isinstance(basic, X509ExtensionType) + assert isinstance(basic, X509Extension) comment = X509Extension(b'nsComment', False, b'pyOpenSSL unit test') - assert isinstance(comment, X509ExtensionType) + assert isinstance(comment, X509Extension) @pytest.mark.parametrize('type_name, critical, value', [ (b'thisIsMadeUp', False, b'hi'), @@ -847,10 +844,8 @@ def test_convert_private_pkey_to_cryptography_key(self): def test_type(self): """ - `PKey` and `PKeyType` refer to the same type object and can be used to - create instances of that type. + `PKey` can be used to create instances of that type. """ - assert PKey is PKeyType assert is_consistent_type(PKey, 'PKey') def test_construction(self): @@ -998,14 +993,10 @@ class TestX509Name(object): def test_type(self): """ - The type of X509Name objects is `X509NameType`. + The type of X509Name objects is `X509Name`. """ - assert X509Name is X509NameType - assert X509NameType.__name__ == 'X509Name' - assert isinstance(X509NameType, type) - name = x509_name() - assert isinstance(name, X509NameType) + assert isinstance(name, X509Name) def test_only_string_attributes(self): """ @@ -1315,18 +1306,16 @@ def signable(self): def test_type(self): """ - `X509Req` and `X509ReqType` refer to the same type object and can be - used to create instances of that type. + `X509Req` can be used to create instances of that type. """ - assert X509Req is X509ReqType assert is_consistent_type(X509Req, 'X509Req') def test_construction(self): """ - `X509Req` takes no arguments and returns an `X509ReqType` instance. + `X509Req` takes no arguments and returns an `X509Req` instance. """ request = X509Req() - assert isinstance(request, X509ReqType) + assert isinstance(request, X509Req) def test_version(self): """ @@ -1358,7 +1347,7 @@ def test_get_subject(self): """ request = X509Req() subject = request.get_subject() - assert isinstance(subject, X509NameType) + assert isinstance(subject, X509Name) subject.commonName = "foo" assert request.get_subject().commonName == "foo" del request @@ -1507,21 +1496,17 @@ def signable(self): def test_type(self): """ - `X509` and `X509Type` refer to the same type object and can be used to - create instances of that type. + `X509` can be used to create instances of that type. """ - assert X509 is X509Type assert is_consistent_type(X509, 'X509') def test_construction(self): """ - `X509` takes no arguments and returns an instance of `X509Type`. + `X509` takes no arguments and returns an instance of `X509`. """ certificate = X509() - assert isinstance(certificate, X509Type) - assert type(X509Type).__name__ == 'type' + assert isinstance(certificate, X509) assert type(certificate).__name__ == 'X509' - assert type(certificate) == X509Type assert type(certificate) == X509 def test_set_version_wrong_args(self): @@ -2004,7 +1989,6 @@ def test_type(self): """ `X509Store` is a type object. """ - assert X509Store is X509StoreType assert is_consistent_type(X509Store, 'X509Store') def test_add_cert(self): @@ -2044,9 +2028,8 @@ class TestPKCS12(object): def test_type(self): """ - `PKCS12Type` is a type object. + `PKCS12` is a type object. """ - assert PKCS12 is PKCS12Type assert is_consistent_type(PKCS12, 'PKCS12') def test_empty_construction(self): @@ -2554,7 +2537,7 @@ def test_load_privatekey_passphrase(self): key = load_privatekey( FILETYPE_PEM, encryptedPrivateKeyPEM, encryptedPrivateKeyPEMPassphrase) - assert isinstance(key, PKeyType) + assert isinstance(key, PKey) def test_load_privatekey_passphrase_exception(self): """ @@ -2595,7 +2578,7 @@ def cb(writing): called.append(writing) return encryptedPrivateKeyPEMPassphrase key = load_privatekey(FILETYPE_PEM, encryptedPrivateKeyPEM, cb) - assert isinstance(key, PKeyType) + assert isinstance(key, PKey) assert called == [False] def test_load_privatekey_passphrase_wrong_return_type(self): @@ -2681,7 +2664,7 @@ def test_dump_privatekey_passphrase(self): pem = dump_privatekey(FILETYPE_PEM, key, GOOD_CIPHER, passphrase) assert isinstance(pem, binary_type) loadedKey = load_privatekey(FILETYPE_PEM, pem, passphrase) - assert isinstance(loadedKey, PKeyType) + assert isinstance(loadedKey, PKey) assert loadedKey.type() == key.type() assert loadedKey.bits() == key.bits() @@ -2822,7 +2805,7 @@ def cb(writing): assert isinstance(pem, binary_type) assert called == [True] loadedKey = load_privatekey(FILETYPE_PEM, pem, passphrase) - assert isinstance(loadedKey, PKeyType) + assert isinstance(loadedKey, PKey) assert loadedKey.type() == key.type() assert loadedKey.bits() == key.bits() @@ -2910,14 +2893,6 @@ class TestPKCS7(object): Tests for `PKCS7`. """ - def test_type(self): - """ - `PKCS7` is a type object. - """ - assert isinstance(PKCS7, type) - assert PKCS7Type.__name__ == 'PKCS7' - assert PKCS7 is PKCS7Type - def test_type_is_signed(self): """ `PKCS7.type_is_signed` returns `True` if the PKCS7 object is of @@ -2981,18 +2956,16 @@ def signable(self): def test_type(self): """ - `NetscapeSPKI` and `NetscapeSPKIType` refer to the same type object - and can be used to create instances of that type. + `NetscapeSPKI` can be used to create instances of that type. """ - assert NetscapeSPKI is NetscapeSPKIType assert is_consistent_type(NetscapeSPKI, 'NetscapeSPKI') def test_construction(self): """ - `NetscapeSPKI` returns an instance of `NetscapeSPKIType`. + `NetscapeSPKI` returns an instance of `NetscapeSPKI`. """ nspki = NetscapeSPKI() - assert isinstance(nspki, NetscapeSPKIType) + assert isinstance(nspki, NetscapeSPKI) def test_invalid_attribute(self): """ diff --git a/tests/test_ssl.py b/tests/test_ssl.py index bddeaa9ff..38511a4df 100644 --- a/tests/test_ssl.py +++ b/tests/test_ssl.py @@ -57,7 +57,7 @@ from OpenSSL.SSL import ( Error, SysCallError, WantReadError, WantWriteError, ZeroReturnError) from OpenSSL.SSL import ( - Context, ContextType, Session, Connection, ConnectionType, SSLeay_version) + Context, Session, Connection, SSLeay_version) from OpenSSL.SSL import _make_requires from OpenSSL._util import ffi as _ffi, lib as _lib @@ -508,10 +508,8 @@ def test_method_long(self): def test_type(self): """ - `Context` and `ContextType` refer to the same type object and can - be used to create instances of that type. + `Context` can be used to create instances of that type. """ - assert Context is ContextType assert is_consistent_type(Context, 'Context', TLSv1_METHOD) def test_use_privatekey(self): @@ -2129,10 +2127,8 @@ class TestConnection(object): def test_type(self): """ - `Connection` and `ConnectionType` refer to the same type object and - can be used to create instances of that type. + `Connection` can be used to create instances of that type. """ - assert Connection is ConnectionType ctx = Context(TLSv1_METHOD) assert is_consistent_type(Connection, 'Connection', ctx, None)