From 7deaf5a8397b3c1fae5e6e3ffb788146f24c4af4 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 18 Dec 2018 09:48:51 +0800 Subject: handle empty byte string in from_encoded_point (#4649) * handle empty byte string in from_encoded_point * move the error --- src/cryptography/hazmat/primitives/asymmetric/ec.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') 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") -- cgit v1.2.3