Skip to content

Commit 2b6e463

Browse files
authored
fixes #7179 -- remove deprecated from_encoded_point (#7572)
1 parent 9547b31 commit 2b6e463

File tree

4 files changed

+11
-117
lines changed

4 files changed

+11
-117
lines changed

CHANGELOG.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ Changelog
88

99
.. note:: This version is not yet released and is under active development.
1010

11-
* Support for OpenSSL 1.1.0 has been removed. Users on older version of
12-
OpenSSL will need to upgrade.
11+
* **BACKWARDS INCOMPATIBLE:** Support for OpenSSL 1.1.0 has been removed.
12+
Users on older version of OpenSSL will need to upgrade.
1313
* **BACKWARDS INCOMPATIBLE:** Dropped support for LibreSSL 3.1.x, 3.2.x,
1414
3.3.0, and 3.3.1. The new minimum LibreSSL version is 3.3.2+.
15+
* **BACKWARDS INCOMPATIBLE:** Removed the ``encode_point`` and
16+
``from_encoded_point`` methods on
17+
:class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers`,
18+
which had been deprecated for several years.
19+
:meth:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.public_bytes`
20+
and
21+
:meth:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.from_encoded_point`
22+
should be used instead.
1523

1624
.. _v38-0-0:
1725

src/cryptography/hazmat/primitives/asymmetric/ec.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import abc
77
import typing
8-
import warnings
98

109
from cryptography import utils
1110
from cryptography.hazmat._oid import ObjectIdentifier
@@ -363,50 +362,6 @@ def public_key(self, backend: typing.Any = None) -> EllipticCurvePublicKey:
363362

364363
return ossl.load_elliptic_curve_public_numbers(self)
365364

366-
def encode_point(self) -> bytes:
367-
warnings.warn(
368-
"encode_point has been deprecated on EllipticCurvePublicNumbers"
369-
" and will be removed in a future version. Please use "
370-
"EllipticCurvePublicKey.public_bytes to obtain both "
371-
"compressed and uncompressed point encoding.",
372-
utils.PersistentlyDeprecated2019,
373-
stacklevel=2,
374-
)
375-
# key_size is in bits. Convert to bytes and round up
376-
byte_length = (self.curve.key_size + 7) // 8
377-
return (
378-
b"\x04"
379-
+ utils.int_to_bytes(self.x, byte_length)
380-
+ utils.int_to_bytes(self.y, byte_length)
381-
)
382-
383-
@classmethod
384-
def from_encoded_point(
385-
cls, curve: EllipticCurve, data: bytes
386-
) -> "EllipticCurvePublicNumbers":
387-
if not isinstance(curve, EllipticCurve):
388-
raise TypeError("curve must be an EllipticCurve instance")
389-
390-
warnings.warn(
391-
"Support for unsafe construction of public numbers from "
392-
"encoded data will be removed in a future version. "
393-
"Please use EllipticCurvePublicKey.from_encoded_point",
394-
utils.PersistentlyDeprecated2019,
395-
stacklevel=2,
396-
)
397-
398-
if data.startswith(b"\x04"):
399-
# key_size is in bits. Convert to bytes and round up
400-
byte_length = (curve.key_size + 7) // 8
401-
if len(data) == 2 * byte_length + 1:
402-
x = int.from_bytes(data[1 : byte_length + 1], "big")
403-
y = int.from_bytes(data[byte_length + 1 :], "big")
404-
return cls(x, y, curve)
405-
else:
406-
raise ValueError("Invalid elliptic curve point data length")
407-
else:
408-
raise ValueError("Unsupported elliptic curve point type")
409-
410365
@property
411366
def curve(self) -> EllipticCurve:
412367
return self._curve

src/cryptography/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class CryptographyDeprecationWarning(UserWarning):
2121
# Several APIs were deprecated with no specific end-of-life date because of the
2222
# ubiquity of their use. They should not be removed until we agree on when that
2323
# cycle ends.
24-
PersistentlyDeprecated2019 = CryptographyDeprecationWarning
2524
DeprecatedIn35 = CryptographyDeprecationWarning
2625
DeprecatedIn36 = CryptographyDeprecationWarning
2726
DeprecatedIn37 = CryptographyDeprecationWarning

tests/hazmat/primitives/test_ec.py

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212

1313
import pytest
1414

15-
from cryptography import exceptions, utils, x509
15+
from cryptography import exceptions, x509
1616
from cryptography.hazmat.primitives import hashes, serialization
1717
from cryptography.hazmat.primitives.asymmetric import ec
1818
from cryptography.hazmat.primitives.asymmetric.utils import (
1919
Prehashed,
2020
encode_dss_signature,
2121
)
22-
from cryptography.utils import CryptographyDeprecationWarning
2322

2423
from .fixtures_ec import EC_KEY_SECP384R1
2524
from .utils import skip_fips_traditional_openssl
@@ -171,73 +170,6 @@ def test_invalid_private_numbers_public_numbers():
171170
ec.EllipticCurvePrivateNumbers(1, None) # type: ignore[arg-type]
172171

173172

174-
def test_encode_point():
175-
# secp256r1 point
176-
x = int(
177-
"233ea3b0027127084cd2cd336a13aeef69c598d8af61369a36454a17c6c22aec", 16
178-
)
179-
y = int(
180-
"3ea2c10a84153862be4ec82940f0543f9ba866af9751a6ee79d38460b35f442e", 16
181-
)
182-
pn = ec.EllipticCurvePublicNumbers(x, y, ec.SECP256R1())
183-
with pytest.warns(utils.PersistentlyDeprecated2019):
184-
data = pn.encode_point()
185-
assert data == binascii.unhexlify(
186-
"04233ea3b0027127084cd2cd336a13aeef69c598d8af61369a36454a17c6c22ae"
187-
"c3ea2c10a84153862be4ec82940f0543f9ba866af9751a6ee79d38460b35f442e"
188-
)
189-
190-
191-
def test_from_encoded_point():
192-
# secp256r1 point
193-
data = binascii.unhexlify(
194-
"04233ea3b0027127084cd2cd336a13aeef69c598d8af61369a36454a17c6c22ae"
195-
"c3ea2c10a84153862be4ec82940f0543f9ba866af9751a6ee79d38460b35f442e"
196-
)
197-
with pytest.warns(CryptographyDeprecationWarning):
198-
pn = ec.EllipticCurvePublicNumbers.from_encoded_point(
199-
ec.SECP256R1(), data
200-
)
201-
assert pn.x == int(
202-
"233ea3b0027127084cd2cd336a13aeef69c598d8af61369a36454a17c6c22aec", 16
203-
)
204-
assert pn.y == int(
205-
"3ea2c10a84153862be4ec82940f0543f9ba866af9751a6ee79d38460b35f442e", 16
206-
)
207-
208-
209-
def test_from_encoded_point_invalid_length():
210-
bad_data = binascii.unhexlify(
211-
"04233ea3b0027127084cd2cd336a13aeef69c598d8af61369a36454a17c6c22ae"
212-
"c3ea2c10a84153862be4ec82940f0543f9ba866af9751a6ee79d38460"
213-
)
214-
with pytest.raises(ValueError):
215-
with pytest.warns(CryptographyDeprecationWarning):
216-
ec.EllipticCurvePublicNumbers.from_encoded_point(
217-
ec.SECP384R1(), bad_data
218-
)
219-
220-
221-
def test_from_encoded_point_unsupported_point_no_backend():
222-
# set to point type 2.
223-
unsupported_type = binascii.unhexlify(
224-
"02233ea3b0027127084cd2cd336a13aeef69c598d8af61369a36454a17c6c22a"
225-
)
226-
with pytest.raises(ValueError):
227-
with pytest.warns(CryptographyDeprecationWarning):
228-
ec.EllipticCurvePublicNumbers.from_encoded_point(
229-
ec.SECP256R1(), unsupported_type
230-
)
231-
232-
233-
def test_from_encoded_point_not_a_curve():
234-
with pytest.raises(TypeError):
235-
with pytest.warns(CryptographyDeprecationWarning):
236-
ec.EllipticCurvePublicNumbers.from_encoded_point(
237-
"notacurve", b"\x04data" # type: ignore[arg-type]
238-
)
239-
240-
241173
def test_ec_public_numbers_repr():
242174
pn = ec.EllipticCurvePublicNumbers(2, 3, ec.SECP256R1())
243175
assert repr(pn) == "<EllipticCurvePublicNumbers(curve=secp256r1, x=2, y=3>"

0 commit comments

Comments
 (0)