Skip to content

Commit 75a6f2e

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

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/ecdsa/der.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ def remove_boolean(string):
282282
)
283283
if body == b"\x00":
284284
return False, rest
285-
# the workaround due to instrumental, that
286-
# saves the binary data as UTF-8 string
287-
# (0xff is an invalid start byte)
288-
if isinstance(body, text_type):
285+
# the workaround due to instrumental, that
286+
# saves the binary data as UTF-8 string
287+
# (0xff is an invalid start byte)
288+
if isinstance(body, text_type): # pragma: no branch
289289
body = body.encode("utf-8")
290290
num = int(binascii.hexlify(body), 16)
291291
if num == 0xFF:

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): # pragma:no branch
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

src/ecdsa/test_der.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ def test_simple_true(self):
573573
self.assertEqual(len(der), 3)
574574
self.assertEqual(der, b"\x01\x01\xff")
575575

576-
def test_simle_false(self):
576+
def test_simple_false(self):
577577
der = encode_boolean(False)
578578
self.assertEqual(len(der), 3)
579579
self.assertEqual(der, b"\x01\x01\x00")

src/ecdsa/test_malformed_sigs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def test_random_der_ecdsa_sig_value_y_boolean(params): # pragma: no cover
432432
"""
433433
verifying_key, sig = params
434434

435-
# The compressed point verification is more strict than 'raw',
435+
# The 'compressed' point verification is more strict than 'raw',
436436
# sometimes the random numbers are producing valid point, so
437437
# the signature verification will fail (BadSignatureError),
438438
# but sometimes the test will fail with trying to create a point

0 commit comments

Comments
 (0)