Skip to content

Commit 333ee3f

Browse files
authored
Merge pull request #186 from hukkinj1/black
Format with black
2 parents c00a19a + f757a23 commit 333ee3f

28 files changed

+4342
-2955
lines changed

diff-instrumental.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
argv = sys.argv[1:]
1111

1212
opts, args = getopt.getopt(
13-
argv, "s:r:",
14-
["fail-under=", "max-difference=", "save=", "read="])
13+
argv, "s:r:", ["fail-under=", "max-difference=", "save=", "read="]
14+
)
1515
if args:
1616
raise ValueError("Unexpected parameters: {0}".format(args))
1717
for opt, arg in opts:
@@ -20,9 +20,9 @@
2020
elif opt == "-r" or opt == "--read":
2121
read_location = arg
2222
elif opt == "--fail-under":
23-
fail_under = float(arg)/100.0
23+
fail_under = float(arg) / 100.0
2424
elif opt == "--max-difference":
25-
max_difference = float(arg)/100.0
25+
max_difference = float(arg) / 100.0
2626
else:
2727
raise ValueError("Unknown option: {0}".format(opt))
2828

@@ -34,7 +34,7 @@
3434
continue
3535

3636
fields = line.split()
37-
hit, count = fields[1].split('/')
37+
hit, count = fields[1].split("/")
3838
total_hits += int(hit)
3939
total_count += int(count)
4040

@@ -43,16 +43,16 @@
4343
if read_location:
4444
with open(read_location, "r") as f:
4545
old_coverage = float(f.read())
46-
print("Old coverage: {0:6.2f}%".format(old_coverage*100))
46+
print("Old coverage: {0:6.2f}%".format(old_coverage * 100))
4747

4848
if save_location:
4949
with open(save_location, "w") as f:
5050
f.write("{0:1.40f}".format(coverage))
5151

52-
print("Coverage: {0:6.2f}%".format(coverage*100))
52+
print("Coverage: {0:6.2f}%".format(coverage * 100))
5353

5454
if read_location:
55-
print("Difference: {0:6.2f}%".format((old_coverage - coverage)*100))
55+
print("Difference: {0:6.2f}%".format((old_coverage - coverage) * 100))
5656

5757
if fail_under and coverage < fail_under:
5858
print("ERROR: Insufficient coverage.", file=sys.stderr)

setup.py

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,33 @@
1414
with io.open(readme_path, encoding="utf-8") as read_file:
1515
long_description = read_file.read()
1616

17-
setup(name="ecdsa",
18-
version=versioneer.get_version(),
19-
description="ECDSA cryptographic signature library (pure python)",
20-
long_description=long_description,
21-
long_description_content_type='text/markdown',
22-
author="Brian Warner",
23-
author_email="warner@lothar.com",
24-
url="http://github.com/warner/python-ecdsa",
25-
packages=["ecdsa"],
26-
package_dir={"": "src"},
27-
license="MIT",
28-
cmdclass=commands,
29-
python_requires=">=2.6, !=3.0.*, !=3.1.*, !=3.2.*",
30-
classifiers=[
31-
"Programming Language :: Python",
32-
"Programming Language :: Python :: 2",
33-
"Programming Language :: Python :: 2.6",
34-
"Programming Language :: Python :: 2.7",
35-
"Programming Language :: Python :: 3",
36-
"Programming Language :: Python :: 3.3",
37-
"Programming Language :: Python :: 3.4",
38-
"Programming Language :: Python :: 3.5",
39-
"Programming Language :: Python :: 3.6",
40-
"Programming Language :: Python :: 3.7",
41-
"Programming Language :: Python :: 3.8",
42-
],
43-
install_requires=['six>=1.9.0'],
44-
extras_require={
45-
'gmpy2': 'gmpy2',
46-
'gmpy': 'gmpy',
47-
},
48-
)
17+
setup(
18+
name="ecdsa",
19+
version=versioneer.get_version(),
20+
description="ECDSA cryptographic signature library (pure python)",
21+
long_description=long_description,
22+
long_description_content_type="text/markdown",
23+
author="Brian Warner",
24+
author_email="warner@lothar.com",
25+
url="http://github.com/warner/python-ecdsa",
26+
packages=["ecdsa"],
27+
package_dir={"": "src"},
28+
license="MIT",
29+
cmdclass=commands,
30+
python_requires=">=2.6, !=3.0.*, !=3.1.*, !=3.2.*",
31+
classifiers=[
32+
"Programming Language :: Python",
33+
"Programming Language :: Python :: 2",
34+
"Programming Language :: Python :: 2.6",
35+
"Programming Language :: Python :: 2.7",
36+
"Programming Language :: Python :: 3",
37+
"Programming Language :: Python :: 3.3",
38+
"Programming Language :: Python :: 3.4",
39+
"Programming Language :: Python :: 3.5",
40+
"Programming Language :: Python :: 3.6",
41+
"Programming Language :: Python :: 3.7",
42+
"Programming Language :: Python :: 3.8",
43+
],
44+
install_requires=["six>=1.9.0"],
45+
extras_require={"gmpy2": "gmpy2", "gmpy": "gmpy"},
46+
)

speed.py

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,42 @@
22
import timeit
33
from ecdsa.curves import curves
44

5+
56
def do(setup_statements, statement):
67
# extracted from timeit.py
7-
t = timeit.Timer(stmt=statement,
8-
setup="\n".join(setup_statements))
8+
t = timeit.Timer(stmt=statement, setup="\n".join(setup_statements))
99
# determine number so that 0.2 <= total time < 2.0
1010
for i in range(1, 10):
11-
number = 10**i
11+
number = 10 ** i
1212
x = t.timeit(number)
1313
if x >= 0.2:
1414
break
1515
return x / number
1616

17+
1718
prnt_form = (
1819
"{name:>16}{sep:1} {siglen:>6} {keygen:>9{form}}{unit:1} "
1920
"{keygen_inv:>9{form_inv}} {sign:>9{form}}{unit:1} "
2021
"{sign_inv:>9{form_inv}} {verify:>9{form}}{unit:1} "
21-
"{verify_inv:>9{form_inv}}")
22+
"{verify_inv:>9{form_inv}}"
23+
)
2224

23-
print(prnt_form.format(siglen="siglen", keygen="keygen", keygen_inv="keygen/s",
24-
sign="sign", sign_inv="sign/s", verify="verify",
25-
verify_inv="verify/s", name="", sep="", unit="",
26-
form="", form_inv=""))
25+
print(
26+
prnt_form.format(
27+
siglen="siglen",
28+
keygen="keygen",
29+
keygen_inv="keygen/s",
30+
sign="sign",
31+
sign_inv="sign/s",
32+
verify="verify",
33+
verify_inv="verify/s",
34+
name="",
35+
sep="",
36+
unit="",
37+
form="",
38+
form_inv="",
39+
)
40+
)
2741

2842
for curve in [i.name for i in curves]:
2943
S1 = "import six; from ecdsa import SigningKey, %s" % curve
@@ -38,24 +52,44 @@ def do(setup_statements, statement):
3852
# were changed to lazily calculate vk, we'd need to change this
3953
# benchmark to loop over S5 instead of S2
4054
keygen = do([S1], S2)
41-
sign = do([S1,S2,S3], S4)
42-
verf = do([S1,S2,S3,S4,S5,S6], S7)
55+
sign = do([S1, S2, S3], S4)
56+
verf = do([S1, S2, S3, S4, S5, S6], S7)
4357
import ecdsa
58+
4459
c = getattr(ecdsa, curve)
4560
sig = ecdsa.SigningKey.generate(c).sign(six.b("msg"))
46-
print(prnt_form.format(
47-
name=curve, sep=":", siglen=len(sig), unit="s", keygen=keygen,
48-
keygen_inv=1.0/keygen, sign=sign, sign_inv=1.0/sign, verify=verf,
49-
verify_inv=1.0/verf, form=".5f", form_inv=".2f"))
61+
print(
62+
prnt_form.format(
63+
name=curve,
64+
sep=":",
65+
siglen=len(sig),
66+
unit="s",
67+
keygen=keygen,
68+
keygen_inv=1.0 / keygen,
69+
sign=sign,
70+
sign_inv=1.0 / sign,
71+
verify=verf,
72+
verify_inv=1.0 / verf,
73+
form=".5f",
74+
form_inv=".2f",
75+
)
76+
)
5077

51-
print('')
78+
print("")
5279

53-
ecdh_form = (
54-
"{name:>16}{sep:1} {ecdh:>9{form}}{unit:1} "
55-
"{ecdh_inv:>9{form_inv}}")
80+
ecdh_form = "{name:>16}{sep:1} {ecdh:>9{form}}{unit:1} {ecdh_inv:>9{form_inv}}"
5681

57-
print(ecdh_form.format(ecdh="ecdh", ecdh_inv="ecdh/s", name="", sep="",
58-
unit="", form="", form_inv=""))
82+
print(
83+
ecdh_form.format(
84+
ecdh="ecdh",
85+
ecdh_inv="ecdh/s",
86+
name="",
87+
sep="",
88+
unit="",
89+
form="",
90+
form_inv="",
91+
)
92+
)
5993

6094
for curve in [i.name for i in curves]:
6195
S1 = "from ecdsa import SigningKey, ECDH, {0}".format(curve)
@@ -64,6 +98,14 @@ def do(setup_statements, statement):
6498
S4 = "ecdh = ECDH(private_key=our, public_key=remote)"
6599
S5 = "ecdh.generate_sharedsecret_bytes()"
66100
ecdh = do([S1, S2, S3, S4], S5)
67-
print(ecdh_form.format(
68-
name=curve, sep=":", unit="s", form=".5f", form_inv=".2f",
69-
ecdh=ecdh, ecdh_inv=1.0/ecdh))
101+
print(
102+
ecdh_form.format(
103+
name=curve,
104+
sep=":",
105+
unit="s",
106+
form=".5f",
107+
form_inv=".2f",
108+
ecdh=ecdh,
109+
ecdh_inv=1.0 / ecdh,
110+
)
111+
)

src/ecdsa/__init__.py

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,76 @@
1-
from .keys import SigningKey, VerifyingKey, BadSignatureError, BadDigestError,\
2-
MalformedPointError
3-
from .curves import NIST192p, NIST224p, NIST256p, NIST384p, NIST521p,\
4-
SECP256k1, BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1,\
5-
BRAINPOOLP256r1, BRAINPOOLP320r1, BRAINPOOLP384r1, BRAINPOOLP512r1
6-
from .ecdh import ECDH, NoKeyError, NoCurveError, InvalidCurveError, \
7-
InvalidSharedSecretError
1+
from .keys import (
2+
SigningKey,
3+
VerifyingKey,
4+
BadSignatureError,
5+
BadDigestError,
6+
MalformedPointError,
7+
)
8+
from .curves import (
9+
NIST192p,
10+
NIST224p,
11+
NIST256p,
12+
NIST384p,
13+
NIST521p,
14+
SECP256k1,
15+
BRAINPOOLP160r1,
16+
BRAINPOOLP192r1,
17+
BRAINPOOLP224r1,
18+
BRAINPOOLP256r1,
19+
BRAINPOOLP320r1,
20+
BRAINPOOLP384r1,
21+
BRAINPOOLP512r1,
22+
)
23+
from .ecdh import (
24+
ECDH,
25+
NoKeyError,
26+
NoCurveError,
27+
InvalidCurveError,
28+
InvalidSharedSecretError,
29+
)
830
from .der import UnexpectedDER
931

1032
# This code comes from http://github.com/warner/python-ecdsa
1133
from ._version import get_versions
12-
__version__ = get_versions()['version']
34+
35+
__version__ = get_versions()["version"]
1336
del get_versions
1437

15-
__all__ = ["curves", "der", "ecdsa", "ellipticcurve", "keys", "numbertheory",
16-
"test_pyecdsa", "util", "six"]
38+
__all__ = [
39+
"curves",
40+
"der",
41+
"ecdsa",
42+
"ellipticcurve",
43+
"keys",
44+
"numbertheory",
45+
"test_pyecdsa",
46+
"util",
47+
"six",
48+
]
1749

18-
_hush_pyflakes = [SigningKey, VerifyingKey, BadSignatureError, BadDigestError,
19-
MalformedPointError, UnexpectedDER, InvalidCurveError,
20-
NoKeyError, InvalidSharedSecretError, ECDH, NoCurveError,
21-
NIST192p, NIST224p, NIST256p, NIST384p, NIST521p, SECP256k1,
22-
BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1,
23-
BRAINPOOLP256r1, BRAINPOOLP320r1, BRAINPOOLP384r1,
24-
BRAINPOOLP512r1]
50+
_hush_pyflakes = [
51+
SigningKey,
52+
VerifyingKey,
53+
BadSignatureError,
54+
BadDigestError,
55+
MalformedPointError,
56+
UnexpectedDER,
57+
InvalidCurveError,
58+
NoKeyError,
59+
InvalidSharedSecretError,
60+
ECDH,
61+
NoCurveError,
62+
NIST192p,
63+
NIST224p,
64+
NIST256p,
65+
NIST384p,
66+
NIST521p,
67+
SECP256k1,
68+
BRAINPOOLP160r1,
69+
BRAINPOOLP192r1,
70+
BRAINPOOLP224r1,
71+
BRAINPOOLP256r1,
72+
BRAINPOOLP320r1,
73+
BRAINPOOLP384r1,
74+
BRAINPOOLP512r1,
75+
]
2576
del _hush_pyflakes

src/ecdsa/_compat.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def str_idx_as_int(string, index):
1414

1515

1616
if sys.version_info < (3, 0):
17+
1718
def normalise_bytes(buffer_object):
1819
"""Cast the input into array of bytes."""
1920
# flake8 runs on py3 where `buffer` indeed doesn't exist...
@@ -22,6 +23,7 @@ def normalise_bytes(buffer_object):
2223
def hmac_compat(ret):
2324
return ret
2425

26+
2527
else:
2628
if sys.version_info < (3, 4):
2729
# on python 3.3 hmac.hmac.update() accepts only bytes, on newer
@@ -30,10 +32,12 @@ def hmac_compat(data):
3032
if not isinstance(data, bytes):
3133
return bytes(data)
3234
return data
35+
3336
else:
37+
3438
def hmac_compat(data):
3539
return data
3640

3741
def normalise_bytes(buffer_object):
3842
"""Cast the input into array of bytes."""
39-
return memoryview(buffer_object).cast('B')
43+
return memoryview(buffer_object).cast("B")

src/ecdsa/_rwlock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def writer_release(self):
6666
class _LightSwitch:
6767
"""An auxiliary "light switch"-like object. The first thread turns on the
6868
"switch", the last one turns it off (see [1, sec. 4.2.2] for details)."""
69+
6970
def __init__(self):
7071
self.__counter = 0
7172
self.__mutex = threading.Lock()

0 commit comments

Comments
 (0)