Skip to content

Commit 469d127

Browse files
committed
trim more usage of six.b()
1 parent c6bb5e1 commit 469d127

File tree

3 files changed

+59
-63
lines changed

3 files changed

+59
-63
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: 53 additions & 57 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,9 +365,7 @@ 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"
370-
)
368+
curve_oid_der = der.encode_oid(*(1, 2, 840, 10045, 3, 1, 1)) + b"garbage"
371369
enc_type_der = der.encode_sequence(type_oid_der, curve_oid_der)
372370
point_der = der.encode_bitstring(b"\x00\xff", None)
373371
to_decode = der.encode_sequence(enc_type_der, point_der)
@@ -770,10 +768,10 @@ def test_encoding(self):
770768
sk = SigningKey.from_secret_exponent(123456789)
771769
vk = sk.verifying_key
772770

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*"
771+
exp = (
772+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
773+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
774+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
777775
)
778776
self.assertEqual(vk.to_string(), exp)
779777
self.assertEqual(vk.to_string("raw"), exp)
@@ -785,10 +783,10 @@ def test_decoding(self):
785783
sk = SigningKey.from_secret_exponent(123456789)
786784
vk = sk.verifying_key
787785

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*"
786+
enc = (
787+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
788+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
789+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
792790
)
793791

794792
from_raw = VerifyingKey.from_string(enc)
@@ -804,22 +802,22 @@ def test_decoding(self):
804802
self.assertEqual(from_uncompressed.pubkey.point, vk.pubkey.point)
805803

806804
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*"
805+
enc = (
806+
b"\x04"
807+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
808+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
809+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
812810
)
813811
vk = VerifyingKey.from_string(enc, valid_encodings=("uncompressed",))
814812
sk = SigningKey.from_secret_exponent(123456789)
815813

816814
self.assertEqual(vk, sk.verifying_key)
817815

818816
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*"
817+
enc = (
818+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
819+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
820+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
823821
)
824822
with self.assertRaises(MalformedPointError) as exp:
825823
VerifyingKey.from_string(enc, valid_encodings=("hybrid",))
@@ -833,76 +831,76 @@ def test_decoding_with_unknown_format(self):
833831
self.assertIn("Only uncompressed, compressed", str(e.exception))
834832

835833
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*"
834+
enc = (
835+
b"\x04"
836+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
837+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
838+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
841839
)
842840
with self.assertRaises(MalformedPointError) as exp:
843841
VerifyingKey.from_string(enc, valid_encodings=("hybrid",))
844842

845843
self.assertIn("Invalid X9.62 encoding", str(exp.exception))
846844

847845
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*"
846+
enc = (
847+
b"\x06"
848+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
849+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
850+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
853851
)
854852
with self.assertRaises(MalformedPointError) as exp:
855853
VerifyingKey.from_string(enc, valid_encodings=("uncompressed",))
856854

857855
self.assertIn("Invalid X9.62 encoding", str(exp.exception))
858856

859857
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*"
858+
enc = (
859+
b"\x02"
860+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
861+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
862+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
865863
)[:25]
866864
with self.assertRaises(MalformedPointError) as exp:
867865
VerifyingKey.from_string(enc, valid_encodings=("hybrid", "raw"))
868866

869867
self.assertIn("(hybrid, raw)", str(exp.exception))
870868

871869
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*"
870+
enc = (
871+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
872+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
873+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
876874
)
877875

878876
with self.assertRaises(MalformedPointError):
879877
VerifyingKey.from_string(b"\x02" + enc)
880878

881879
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*"
880+
enc = (
881+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
882+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
883+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
886884
)
887885

888886
with self.assertRaises(MalformedPointError):
889887
VerifyingKey.from_string(b"\x01" + enc[:24])
890888

891889
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*"
890+
enc = (
891+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
892+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
893+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
896894
)
897895

898896
with self.assertRaises(MalformedPointError):
899897
VerifyingKey.from_string(b"\x07" + enc)
900898

901899
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*"
900+
enc = (
901+
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
902+
b"\xfd\xc8\xa0c\xff\xfb\x02\xb9\xc4\x84)\x1a\x0f\x8b\x87\xa4"
903+
b"z\x8a#\xb5\x97\xecO\xb6\xa0HQ\x89*"
906904
)
907905

908906
with self.assertRaises(MalformedPointError):
@@ -1894,7 +1892,7 @@ def OFF_test_prove_uniformity(self): # pragma: no cover
18941892
# this technique should use the full range
18951893
self.assertTrue(counts[order - 1])
18961894
for i in range(1, order):
1897-
print_("%3d: %s" % (i, "*" * (counts[i] // 100)))
1895+
print("%3d: %s" % (i, "*" * (counts[i] // 100)))
18981896

18991897

19001898
class RFC6979(unittest.TestCase):
@@ -1981,9 +1979,7 @@ def test_1(self):
19811979
),
19821980
secexp=int("09A4D6792295A7F730FC3F2B49CBC0F62E862272F", 16),
19831981
hsh=unhexlify(
1984-
b(
1985-
"AF2BDBE1AA9B6EC1E2ADE1D694F41FC71A831D0268E9891562113D8A62ADD1BF"
1986-
)
1982+
b"AF2BDBE1AA9B6EC1E2ADE1D694F41FC71A831D0268E9891562113D8A62ADD1BF"
19871983
),
19881984
hash_func=hashlib.sha256,
19891985
expected=int("23AF4074C90A02B3FE61D286D5C87F425E6BDD81B", 16),

0 commit comments

Comments
 (0)