diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2018-12-18 09:48:51 +0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2018-12-17 20:48:51 -0500 |
commit | 7deaf5a8397b3c1fae5e6e3ffb788146f24c4af4 (patch) | |
tree | 74c2dad2f2fac8b9633f0c7170fb26de7f826012 | |
parent | 3c137d909dc004fbcab4a1593c3a6430882fd853 (diff) | |
download | cryptography-7deaf5a8397b3c1fae5e6e3ffb788146f24c4af4.tar.gz cryptography-7deaf5a8397b3c1fae5e6e3ffb788146f24c4af4.tar.bz2 cryptography-7deaf5a8397b3c1fae5e6e3ffb788146f24c4af4.zip |
handle empty byte string in from_encoded_point (#4649)
* handle empty byte string in from_encoded_point
* move the error
-rw-r--r-- | src/cryptography/hazmat/primitives/asymmetric/ec.py | 4 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_ec.py | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/cryptography/hazmat/primitives/asymmetric/ec.py b/src/cryptography/hazmat/primitives/asymmetric/ec.py index 125235f8..c93cc090 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/ec.py +++ b/src/cryptography/hazmat/primitives/asymmetric/ec.py @@ -155,9 +155,13 @@ class EllipticCurvePublicKey(object): @classmethod def from_encoded_point(cls, curve, data): utils._check_bytes("data", data) + if not isinstance(curve, EllipticCurve): raise TypeError("curve must be an EllipticCurve instance") + if len(data) == 0: + raise ValueError("data must not be an empty byte string") + if six.indexbytes(data, 0) not in [0x02, 0x03, 0x04]: raise ValueError("Unsupported elliptic curve point type") diff --git a/tests/hazmat/primitives/test_ec.py b/tests/hazmat/primitives/test_ec.py index 7cf9a09a..f883d065 100644 --- a/tests/hazmat/primitives/test_ec.py +++ b/tests/hazmat/primitives/test_ec.py @@ -1071,6 +1071,12 @@ class TestEllipticCurvePEMPublicKeySerialization(object): ec.SECP384R1(), bad_data ) + def test_from_encoded_point_empty_byte_string(self): + with pytest.raises(ValueError): + ec.EllipticCurvePublicKey.from_encoded_point( + ec.SECP384R1(), b"" + ) + def test_from_encoded_point_not_a_curve(self): with pytest.raises(TypeError): ec.EllipticCurvePublicKey.from_encoded_point( |