Skip to content

TypeError instead of InvalidPointError on VerifyingKey.from_public_point(INFINITY) #341

Open
@akarve

Description

@akarve

I was experimenting to understand how the library handles failures. I don't expect the following line to work but I do expect it to raise a different error (MalformedPoint, not Type).

VerifyingKey.from_public_point(INFINITY)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 VerifyingKey.from_public_point(INFINITY)

File ~/miniconda3/envs/de/lib/python3.9/site-packages/ecdsa/keys.py:170, in VerifyingKey.from_public_point(cls, point, curve, hashfunc, validate_point)
    168 self.default_hashfunc = hashfunc
    169 try:
--> 170     self.pubkey = ecdsa.Public_key(
    171         curve.generator, point, validate_point
    172     )
    173 except ecdsa.InvalidPointError:
    174     raise MalformedPointError("Point does not lay on the curve")

File ~/miniconda3/envs/de/lib/python3.9/site-packages/ecdsa/ecdsa.py:151, in Public_key.__init__(self, generator, point, verify)
    149 n = generator.order()
    150 p = self.curve.p()
--> 151 if not (0 <= point.x() < p) or not (0 <= point.y() < p):
    152     raise InvalidPointError(
    153         "The public point has x or y out of range."
    154     )
    155 if verify and not self.curve.contains_point(point.x(), point.y()):

TypeError: '<=' not supported between instances of 'int' and 'NoneType'

Related: for cases where one wishes to avoid the point at infinity is this the right way to detect it if point == ellipticcurve.INFINITY? I kind of expected infinity to vary by the curve family but there's nothing under eg SECKP256k1 that I can find.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugunintended behaviour in ecdsa codehelp wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions