Skip to content

Commit fc91378

Browse files
committed
unify exceptions between raw and compressed encoding
make the decoding of malformed point raise the same exception irrespective of the formatting of the key/public point
1 parent 0bba1e3 commit fc91378

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/ecdsa/keys.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ def _from_raw_encoding(string, curve, validate_point):
5555
assert len(ys) == curve.baselen, (len(ys), curve.baselen)
5656
x = string_to_number(xs)
5757
y = string_to_number(ys)
58-
if validate_point:
59-
assert ecdsa.point_is_valid(curve.generator, x, y)
58+
if validate_point and not ecdsa.point_is_valid(curve.generator, x, y):
59+
raise MalformedPoint("Point does not lie on the curve")
60+
6061
return ellipticcurve.Point(curve.curve, x, y, order)
6162

6263
@staticmethod

src/ecdsa/test_pyecdsa.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,14 @@ def test_decoding_with_malformed_compressed(self):
416416
with self.assertRaises(MalformedPoint):
417417
VerifyingKey.from_string(b('\x01') + enc[:24])
418418

419+
def test_decoding_with_point_not_on_curve(self):
420+
enc = b('\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3'
421+
'\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4'
422+
'z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*')
423+
424+
with self.assertRaises(MalformedPoint):
425+
VerifyingKey.from_string(enc[:47] + b('\x00'))
426+
419427
def test_decoding_with_point_at_infinity(self):
420428
# decoding it is unsupported, as it's not necessary to encode it
421429
with self.assertRaises(MalformedPoint):

0 commit comments

Comments
 (0)