From 9668b000326585339267a42176facd9ff81481ee Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 3 Nov 2019 01:47:13 -0400 Subject: Deal with the 2.5 deprecations (#5048) * Deal with the 2.5 deprecations * pep8 + test fixes * docs typo * Why did I do this? * typo --- CHANGELOG.rst | 4 ++++ src/cryptography/hazmat/backends/openssl/x25519.py | 16 +--------------- src/cryptography/hazmat/primitives/asymmetric/ec.py | 4 ++-- src/cryptography/hazmat/primitives/asymmetric/x25519.py | 2 +- src/cryptography/utils.py | 2 +- tests/hazmat/primitives/test_ec.py | 2 +- tests/hazmat/primitives/test_x25519.py | 8 +------- 7 files changed, 11 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 607f67b8..b727c8aa 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,10 @@ Changelog * Support for OpenSSL 1.0.1 has been removed. Users on older version of OpenSSL will need to upgrade. +* Removed support for calling + :meth:`~cryptography.hazmat.primitives.asymmetric.x25519.X25519PublicKey.public_bytes` + with no arguments, as per our deprecation policy. You must now pass + ``encoding`` and ``format``. .. _v2-8: diff --git a/src/cryptography/hazmat/backends/openssl/x25519.py b/src/cryptography/hazmat/backends/openssl/x25519.py index 9aab25b8..8708834e 100644 --- a/src/cryptography/hazmat/backends/openssl/x25519.py +++ b/src/cryptography/hazmat/backends/openssl/x25519.py @@ -4,8 +4,6 @@ from __future__ import absolute_import, division, print_function -import warnings - from cryptography import utils from cryptography.hazmat.backends.openssl.utils import _evp_pkey_derive from cryptography.hazmat.primitives import serialization @@ -23,19 +21,7 @@ class _X25519PublicKey(object): self._backend = backend self._evp_pkey = evp_pkey - def public_bytes(self, encoding=None, format=None): - if encoding is None or format is None: - if encoding is not None or format is not None: - raise ValueError("Both encoding and format are required") - else: - warnings.warn( - "public_bytes now requires encoding and format arguments. " - "Support for calling without arguments will be removed in " - "cryptography 2.7", - utils.DeprecatedIn25, - ) - encoding = serialization.Encoding.Raw - format = serialization.PublicFormat.Raw + def public_bytes(self, encoding, format): if ( encoding is serialization.Encoding.Raw or format is serialization.PublicFormat.Raw diff --git a/src/cryptography/hazmat/primitives/asymmetric/ec.py b/src/cryptography/hazmat/primitives/asymmetric/ec.py index 529391f9..eef922dc 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/ec.py +++ b/src/cryptography/hazmat/primitives/asymmetric/ec.py @@ -364,7 +364,7 @@ class EllipticCurvePublicNumbers(object): " and will be removed in a future version. Please use " "EllipticCurvePublicKey.public_bytes to obtain both " "compressed and uncompressed point encoding.", - utils.DeprecatedIn25, + utils.PersistentlyDeprecated2019, stacklevel=2, ) # key_size is in bits. Convert to bytes and round up @@ -383,7 +383,7 @@ class EllipticCurvePublicNumbers(object): "Support for unsafe construction of public numbers from " "encoded data will be removed in a future version. " "Please use EllipticCurvePublicKey.from_encoded_point", - utils.DeprecatedIn25, + utils.PersistentlyDeprecated2019, stacklevel=2, ) diff --git a/src/cryptography/hazmat/primitives/asymmetric/x25519.py b/src/cryptography/hazmat/primitives/asymmetric/x25519.py index 4e8badf4..61a95ffa 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/x25519.py +++ b/src/cryptography/hazmat/primitives/asymmetric/x25519.py @@ -25,7 +25,7 @@ class X25519PublicKey(object): return backend.x25519_load_public_bytes(data) @abc.abstractmethod - def public_bytes(self, encoding=None, format=None): + def public_bytes(self, encoding, format): """ The serialized bytes of the public key. """ diff --git a/src/cryptography/utils.py b/src/cryptography/utils.py index 0b36f637..e895aa05 100644 --- a/src/cryptography/utils.py +++ b/src/cryptography/utils.py @@ -22,7 +22,7 @@ class CryptographyDeprecationWarning(UserWarning): # cycle ends. PersistentlyDeprecated2017 = CryptographyDeprecationWarning PersistentlyDeprecated2018 = CryptographyDeprecationWarning -DeprecatedIn25 = CryptographyDeprecationWarning +PersistentlyDeprecated2019 = CryptographyDeprecationWarning DeprecatedIn27 = CryptographyDeprecationWarning diff --git a/tests/hazmat/primitives/test_ec.py b/tests/hazmat/primitives/test_ec.py index 922a25f0..987c0ff0 100644 --- a/tests/hazmat/primitives/test_ec.py +++ b/tests/hazmat/primitives/test_ec.py @@ -181,7 +181,7 @@ def test_encode_point(): 16 ) pn = ec.EllipticCurvePublicNumbers(x, y, ec.SECP256R1()) - with pytest.warns(utils.DeprecatedIn25): + with pytest.warns(utils.PersistentlyDeprecated2019): data = pn.encode_point() assert data == binascii.unhexlify( "04233ea3b0027127084cd2cd336a13aeef69c598d8af61369a36454a17c6c22ae" diff --git a/tests/hazmat/primitives/test_x25519.py b/tests/hazmat/primitives/test_x25519.py index 8bdc6b49..30dc2818 100644 --- a/tests/hazmat/primitives/test_x25519.py +++ b/tests/hazmat/primitives/test_x25519.py @@ -9,7 +9,6 @@ import os import pytest -from cryptography import utils from cryptography.exceptions import _Reasons from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric.x25519 import ( @@ -95,16 +94,11 @@ class TestX25519Exchange(object): with pytest.raises(ValueError): private_key.exchange(public_key) - def test_deprecated_public_bytes(self, backend): - key = X25519PrivateKey.generate().public_key() - with pytest.warns(utils.DeprecatedIn25): - key.public_bytes() - def test_public_bytes_bad_args(self, backend): key = X25519PrivateKey.generate().public_key() with pytest.raises(ValueError): key.public_bytes(None, serialization.PublicFormat.Raw) - with pytest.raises(ValueError): + with pytest.raises(TypeError): key.public_bytes(serialization.Encoding.Raw) # These vectors are also from RFC 7748 -- cgit v1.2.3