Skip to content

Commit 35c33f2

Browse files
authored
Merge pull request #339 from a-detiste/master
trim more usage of six.b()
2 parents c6bb5e1 + bfce13b commit 35c33f2

File tree

3 files changed

+60
-62
lines changed

3 files changed

+60
-62
lines changed

src/ecdsa/ecdsa.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@
4040
# Verifying a signature for a hash value:
4141
4242
if pubkey.verifies( hash, signature ):
43-
print_("Demo verification succeeded.")
43+
print("Demo verification succeeded.")
4444
else:
45-
print_("*** Demo verification failed.")
45+
print("*** Demo verification failed.")
4646
4747
# Verification fails if the hash value is modified:
4848
4949
if pubkey.verifies( hash-1, signature ):
50-
print_("**** Demo verification failed to reject tampered hash.")
50+
print("**** Demo verification failed to reject tampered hash.")
5151
else:
52-
print_("Demo verification correctly rejected tampered hash.")
52+
print("Demo verification correctly rejected tampered hash.")
5353
5454
Revision history:
5555
2005.12.31 - Initial version.

src/ecdsa/ellipticcurve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,14 +1223,14 @@ def leftmost_bit(x):
12231223
negative_self = Point(self.__curve, self.__x, -self.__y, self.__order)
12241224
i = leftmost_bit(e3) // 2
12251225
result = self
1226-
# print_("Multiplying %s by %d (e3 = %d):" % (self, other, e3))
1226+
# print("Multiplying %s by %d (e3 = %d):" % (self, other, e3))
12271227
while i > 1:
12281228
result = result.double()
12291229
if (e3 & i) != 0 and (e & i) == 0:
12301230
result = result + self
12311231
if (e3 & i) == 0 and (e & i) != 0:
12321232
result = result + negative_self
1233-
# print_(". . . i = %d, result = %s" % ( i, result ))
1233+
# print(". . . i = %d, result = %s" % ( i, result ))
12341234
i = i // 2
12351235

12361236
return result

src/ecdsa/test_pyecdsa.py

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import with_statement, division
1+
from __future__ import with_statement, division, print_function
22

33
try:
44
import unittest2 as unittest
@@ -16,7 +16,7 @@
1616
from hypothesis import given, settings
1717
import hypothesis.strategies as st
1818

19-
from six import b, print_, binary_type
19+
from six import binary_type
2020
from .keys import SigningKey, VerifyingKey
2121
from .keys import BadSignatureError, MalformedPointError, BadDigestError
2222
from . import util
@@ -365,8 +365,8 @@ def test_sk_to_der_with_invalid_point_encoding(self):
365365

366366
def test_vk_from_der_garbage_after_curve_oid(self):
367367
type_oid_der = encoded_oid_ecPublicKey
368-
curve_oid_der = der.encode_oid(*(1, 2, 840, 10045, 3, 1, 1)) + b(
369-
"garbage"
368+
curve_oid_der = (
369+
der.encode_oid(*(1, 2, 840, 10045, 3, 1, 1)) + b"garbage"
370370
)
371371
enc_type_der = der.encode_sequence(type_oid_der, curve_oid_der)
372372
point_der = der.encode_bitstring(b"\x00\xff", None)
@@ -770,10 +770,10 @@ def test_encoding(self):
770770
sk = SigningKey.from_secret_exponent(123456789)
771771
vk = sk.verifying_key
772772

773-
exp = b(
774-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
775-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
776-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
773+
exp = (
774+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
775+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
776+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
777777
)
778778
self.assertEqual(vk.to_string(), exp)
779779
self.assertEqual(vk.to_string("raw"), exp)
@@ -785,10 +785,10 @@ def test_decoding(self):
785785
sk = SigningKey.from_secret_exponent(123456789)
786786
vk = sk.verifying_key
787787

788-
enc = b(
789-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
790-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
791-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
788+
enc = (
789+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
790+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
791+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
792792
)
793793

794794
from_raw = VerifyingKey.from_string(enc)
@@ -804,22 +804,22 @@ def test_decoding(self):
804804
self.assertEqual(from_uncompressed.pubkey.point, vk.pubkey.point)
805805

806806
def test_uncompressed_decoding_as_only_alowed(self):
807-
enc = b(
808-
"\x04"
809-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
810-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
811-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
807+
enc = (
808+
b"\x04"
809+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
810+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
811+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
812812
)
813813
vk = VerifyingKey.from_string(enc, valid_encodings=("uncompressed",))
814814
sk = SigningKey.from_secret_exponent(123456789)
815815

816816
self.assertEqual(vk, sk.verifying_key)
817817

818818
def test_raw_decoding_with_blocked_format(self):
819-
enc = b(
820-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
821-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
822-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
819+
enc = (
820+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
821+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
822+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
823823
)
824824
with self.assertRaises(MalformedPointError) as exp:
825825
VerifyingKey.from_string(enc, valid_encodings=("hybrid",))
@@ -833,76 +833,76 @@ def test_decoding_with_unknown_format(self):
833833
self.assertIn("Only uncompressed, compressed", str(e.exception))
834834

835835
def test_uncompressed_decoding_with_blocked_format(self):
836-
enc = b(
837-
"\x04"
838-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
839-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
840-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
836+
enc = (
837+
b"\x04"
838+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
839+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
840+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
841841
)
842842
with self.assertRaises(MalformedPointError) as exp:
843843
VerifyingKey.from_string(enc, valid_encodings=("hybrid",))
844844

845845
self.assertIn("Invalid X9.62 encoding", str(exp.exception))
846846

847847
def test_hybrid_decoding_with_blocked_format(self):
848-
enc = b(
849-
"\x06"
850-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
851-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
852-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
848+
enc = (
849+
b"\x06"
850+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
851+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
852+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
853853
)
854854
with self.assertRaises(MalformedPointError) as exp:
855855
VerifyingKey.from_string(enc, valid_encodings=("uncompressed",))
856856

857857
self.assertIn("Invalid X9.62 encoding", str(exp.exception))
858858

859859
def test_compressed_decoding_with_blocked_format(self):
860-
enc = b(
861-
"\x02"
862-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
863-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
864-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
860+
enc = (
861+
b"\x02"
862+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
863+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
864+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
865865
)[:25]
866866
with self.assertRaises(MalformedPointError) as exp:
867867
VerifyingKey.from_string(enc, valid_encodings=("hybrid", "raw"))
868868

869869
self.assertIn("(hybrid, raw)", str(exp.exception))
870870

871871
def test_decoding_with_malformed_uncompressed(self):
872-
enc = b(
873-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
874-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
875-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
872+
enc = (
873+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
874+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
875+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
876876
)
877877

878878
with self.assertRaises(MalformedPointError):
879879
VerifyingKey.from_string(b"\x02" + enc)
880880

881881
def test_decoding_with_malformed_compressed(self):
882-
enc = b(
883-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
884-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
885-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
882+
enc = (
883+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
884+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
885+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
886886
)
887887

888888
with self.assertRaises(MalformedPointError):
889889
VerifyingKey.from_string(b"\x01" + enc[:24])
890890

891891
def test_decoding_with_inconsistent_hybrid(self):
892-
enc = b(
893-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
894-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
895-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
892+
enc = (
893+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
894+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
895+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
896896
)
897897

898898
with self.assertRaises(MalformedPointError):
899899
VerifyingKey.from_string(b"\x07" + enc)
900900

901901
def test_decoding_with_point_not_on_curve(self):
902-
enc = b(
903-
"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
904-
"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
905-
"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
902+
enc = (
903+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
904+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
905+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
906906
)
907907

908908
with self.assertRaises(MalformedPointError):
@@ -1894,7 +1894,7 @@ def OFF_test_prove_uniformity(self): # pragma: no cover
18941894
# this technique should use the full range
18951895
self.assertTrue(counts[order - 1])
18961896
for i in range(1, order):
1897-
print_("%3d: %s" % (i, "*" * (counts[i] // 100)))
1897+
print("%3d: %s" % (i, "*" * (counts[i] // 100)))
18981898

18991899

19001900
class RFC6979(unittest.TestCase):
@@ -1981,9 +1981,7 @@ def test_1(self):
19811981
),
19821982
secexp=int("09A4D6792295A7F730FC3F2B49CBC0F62E862272F", 16),
19831983
hsh=unhexlify(
1984-
b(
1985-
"AF2BDBE1AA9B6EC1E2ADE1D694F41FC71A831D0268E9891562113D8A62ADD1BF"
1986-
)
1984+
b"AF2BDBE1AA9B6EC1E2ADE1D694F41FC71A831D0268E9891562113D8A62ADD1BF"
19871985
),
19881986
hash_func=hashlib.sha256,
19891987
expected=int("23AF4074C90A02B3FE61D286D5C87F425E6BDD81B", 16),

0 commit comments

Comments
 (0)