Skip to content

Commit 2949133

Browse files
committed
fix the int/long type in python2.7
1 parent 76833c8 commit 2949133

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/ecdsa/ecdsa.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,19 @@ class InvalidPointError(RuntimeError):
8181
pass
8282

8383

84-
class RValue(int):
84+
# Plain integers in Python 2 are implemented using long in C,
85+
# which gives them at least 32 bits of precision.
86+
# Long integers have unlimited precision.
87+
# In python 3 int and long were 'unified'
88+
89+
if sys.version_info < (3, 0):
90+
# flake8 is complaining on python3
91+
INT_TYPE = long # noqa: F821
92+
else:
93+
INT_TYPE = int
94+
95+
96+
class RValue(INT_TYPE):
8597
"""An r signature value that also carries the originating EC point.
8698
8799
Behaves as a regular ``int`` (equal to ``point.x() % order``) so
@@ -91,7 +103,7 @@ class RValue(int):
91103
"""
92104

93105
def __new__(cls, r, point):
94-
obj = super(RValue, cls).__new__(cls, r)
106+
obj = super(RValue, cls).__new__(cls, INT_TYPE(r))
95107
obj.point = point
96108
return obj
97109

0 commit comments

Comments
 (0)