Skip to content

Commit bed03a2

Browse files
committed
test_ecdsa: cleanup imports
don't use six.print_ - not needed on py2.6 sort imports in conventional way
1 parent fa7655c commit bed03a2

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/ecdsa/test_ecdsa.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from .ecdsa import (Private_key, Public_key, Signature,
2-
curve_192, generator_192,
3-
digest_integer, ellipticcurve, point_is_valid)
4-
from six import print_
1+
from __future__ import print_function
52
import random
3+
from .ecdsa import Private_key, Public_key, Signature, \
4+
curve_192, generator_192, digest_integer, ellipticcurve, point_is_valid
5+
66

77
def test_ecdsa():
88
class TestFailure(Exception):
@@ -12,7 +12,7 @@ def test_point_validity(generator, x, y, expected):
1212
"""generator defines the curve; is (x,y) a point on
1313
this curve? "expected" is True if the right answer is Yes."""
1414
if point_is_valid(generator, x, y) == expected:
15-
print_("Point validity tested as expected.")
15+
print("Point validity tested as expected.")
1616
else:
1717
raise TestFailure("*** Point validity test gave wrong result.")
1818

@@ -24,8 +24,8 @@ def test_signature_validity(Msg, Qx, Qy, R, S, expected):
2424
ellipticcurve.Point(curve_192, Qx, Qy))
2525
got = pubk.verifies(digest_integer(Msg), Signature(R, S))
2626
if got == expected:
27-
print_("Signature tested as expected: got %s, expected %s." % \
28-
(got, expected))
27+
print("Signature tested as expected: got %s, expected %s." % \
28+
(got, expected))
2929
else:
3030
raise TestFailure("*** Signature test failed: got %s, expected %s." % \
3131
(got, expected))
@@ -35,29 +35,29 @@ def test_pk_recovery(Msg, R, S, Qx, Qy):
3535
sign = Signature(R,S)
3636
pks = sign.recover_public_keys(digest_integer(Msg), generator_192)
3737

38-
print_("Test pk recover")
38+
print("Test pk recover")
3939

4040
if pks:
4141

4242
# Test if the signature is valid for all found public keys
4343
for pk in pks:
4444
q = pk.point
45-
print_("Recovered q: %s" % q)
45+
print("Recovered q: %s" % q)
4646
test_signature_validity(Msg, q.x(), q.y(), R, S, True)
4747

4848
# Test if the original public key is in the set of found keys
4949
original_q = ellipticcurve.Point(curve_192, Qx, Qy)
5050
points = [pk.point for pk in pks]
5151
if original_q in points:
52-
print_("Original q was found")
52+
print("Original q was found")
5353
else:
5454
raise TestFailure("Original q is not in the list of recovered public keys")
5555

5656
else:
5757
raise TestFailure("*** NO valid public key returned")
5858

5959

60-
print_("NIST Curve P-192:")
60+
print("NIST Curve P-192:")
6161

6262
p192 = generator_192
6363

@@ -68,15 +68,15 @@ def test_pk_recovery(Msg, R, S, Qx, Qy):
6868
if Q.x() != 0x62B12D60690CDCF330BABAB6E69763B471F994DD702D16A5:
6969
raise TestFailure("*** p192 * d came out wrong.")
7070
else:
71-
print_("p192 * d came out right.")
71+
print("p192 * d came out right.")
7272

7373
k = 6140507067065001063065065565667405560006161556565665656654
7474
R = k * p192
7575
if R.x() != 0x885052380FF147B734C330C43D39B2C4A89F29B0F749FEAD \
7676
or R.y() != 0x9CF9FA1CBEFEFB917747A3BB29C072B9289C2547884FD835:
7777
raise TestFailure("*** k * p192 came out wrong.")
7878
else:
79-
print_("k * p192 came out right.")
79+
print("k * p192 came out right.")
8080

8181
u1 = 2563697409189434185194736134579731015366492496392189760599
8282
u2 = 6266643813348617967186477710235785849136406323338782220568
@@ -85,7 +85,7 @@ def test_pk_recovery(Msg, R, S, Qx, Qy):
8585
or temp.y() != 0x9CF9FA1CBEFEFB917747A3BB29C072B9289C2547884FD835:
8686
raise TestFailure("*** u1 * p192 + u2 * Q came out wrong.")
8787
else:
88-
print_("u1 * p192 + u2 * Q came out right.")
88+
print("u1 * p192 + u2 * Q came out right.")
8989

9090
e = 968236873715988614170569073515315707566766479517
9191
pubk = Public_key(generator_192, generator_192 * d)
@@ -96,21 +96,21 @@ def test_pk_recovery(Msg, R, S, Qx, Qy):
9696
or s != 5735822328888155254683894997897571951568553642892029982342:
9797
raise TestFailure("*** r or s came out wrong.")
9898
else:
99-
print_("r and s came out right.")
99+
print("r and s came out right.")
100100

101101
valid = pubk.verifies(e, sig)
102102
if valid:
103-
print_("Signature verified OK.")
103+
print("Signature verified OK.")
104104
else:
105105
raise TestFailure("*** Signature failed verification.")
106106

107107
valid = pubk.verifies(e - 1, sig)
108108
if not valid:
109-
print_("Forgery was correctly rejected.")
109+
print("Forgery was correctly rejected.")
110110
else:
111111
raise TestFailure("*** Forgery was erroneously accepted.")
112112

113-
print_("Testing point validity, as per ECDSAVS.pdf B.2.2:")
113+
print("Testing point validity, as per ECDSAVS.pdf B.2.2:")
114114

115115
test_point_validity( \
116116
p192, \
@@ -184,8 +184,8 @@ def test_pk_recovery(Msg, R, S, Qx, Qy):
184184
0x509014c0c4d6b536e3ca750ec09066af39b4c8616a53a923, \
185185
False)
186186

187-
print_("Trying signature-verification tests from ECDSAVS.pdf B.2.4:")
188-
print_("P-192:")
187+
print("Trying signature-verification tests from ECDSAVS.pdf B.2.4:")
188+
print("P-192:")
189189
Msg = 0x84ce72aa8699df436059f052ac51b6398d2511e49631bcb7e71f89c499b9ee425dfbc13a5f6d408471b054f2655617cbbaf7937b7c80cd8865cf02c8487d30d2b0fbd8b2c4e102e16d828374bbc47b93852f212d5043c3ea720f086178ff798cc4f63f787b9c2e419efa033e7644ea7936f54462dc21a6c4580725f7f0e7d158
190190
Qx = 0xd9dbfb332aa8e5ff091e8ce535857c37c73f6250ffb2e7ac
191191
Qy = 0x282102e364feded3ad15ddf968f88d8321aa268dd483ebc4
@@ -293,7 +293,7 @@ def test_pk_recovery(Msg, R, S, Qx, Qy):
293293
S = 0x984c2db99827576c0a41a5da41e07d8cc768bc82f18c9da9
294294
test_signature_validity(Msg, Qx, Qy, R, S, False)
295295

296-
print_("Testing the example code:")
296+
print("Testing the example code:")
297297

298298
# Building a public/private key pair from the NIST Curve P-192:
299299

@@ -320,11 +320,11 @@ def test_pk_recovery(Msg, R, S, Qx, Qy):
320320
# Verifying a signature for a hash value:
321321

322322
if pubkey.verifies(hash, signature):
323-
print_("Demo verification succeeded.")
323+
print("Demo verification succeeded.")
324324
else:
325325
raise TestFailure("*** Demo verification failed.")
326326

327327
if pubkey.verifies(hash - 1, signature):
328328
raise TestFailure("**** Demo verification failed to reject tampered hash.")
329329
else:
330-
print_("Demo verification correctly rejected tampered hash.")
330+
print("Demo verification correctly rejected tampered hash.")

0 commit comments

Comments
 (0)