8000 Merge pull request #170 from tomato42/style-fixes · tlsfuzzer/python-ecdsa@bdabc0f · GitHub
[go: up one dir, main page]

Skip to content

Commit bdabc0f

Browse files
authored
Merge pull request #170 from tomato42/style-fixes
Style fixes
2 parents 26d4edc + b653c2c commit bdabc0f

File tree

13 files changed

+61
-52
lines changed

13 files changed

+61
-52
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ matrix:
4343
env: TOX_ENV=py37
4444
dist: xenial
4545
sudo: true
46+
- python: 3.8
47+
env: TOX_ENV=codechecks
48+
dist: xenial
49+
sudo: true
4650
- python: 3.8
4751
env: TOX_ENV=py38
4852
dist: xenial

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
],
4343
install_requires=['six>=1.9.0'],
4444
extras_require={
45-
'gmpy2': 'gmpy2',
46-
'gmpy': 'gmpy',
47-
},
45+
'gmpy2': 'gmpy2',
46+
'gmpy': 'gmpy',
47+
},
4848
)

speed.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def do(setup_statements, statement):
1414
break
1515
return x / number
1616

17-
prnt_form = ("{name:>16}{sep:1} {siglen:>6} {keygen:>9{form}}{unit:1} "
17+
prnt_form = (
18+
"{name:>16}{sep:1} {siglen:>6} {keygen:>9{form}}{unit:1} "
1819
"{keygen_inv:>9{form_inv}} {sign:>9{form}}{unit:1} "
1920
"{sign_inv:>9{form_inv}} {verify:>9{form}}{unit:1} "
2021
"{verify_inv:>9{form_inv}}")
@@ -49,7 +50,8 @@ def do(setup_statements, statement):
4950

5051
print('')
5152

52-
ecdh_form = ("{name:>16}{sep:1} {ecdh:>9{form}}{unit:1} "
53+
ecdh_form = (
54+
"{name:>16}{sep:1} {ecdh:>9{form}}{unit:1} "
5355
"{ecdh_inv:>9{form_inv}}")
5456

5557
print(ecdh_form.format(ecdh="ecdh", ecdh_inv="ecdh/s", name="", sep="",

src/ecdsa/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from .keys import SigningKey, VerifyingKey, BadSignatureError, BadDigestError,\
2-
MalformedPointError
2+
MalformedPointError
33
from .curves import NIST192p, NIST224p, NIST256p, NIST384p, NIST521p,\
4-
SECP256k1, BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1,\
5-
BRAINPOOLP256r1, BRAINPOOLP320r1, BRAINPOOLP384r1, BRAINPOOLP512r1
4+
SECP256k1, BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1,\
5+
BRAINPOOLP256r1, BRAINPOOLP320r1, BRAINPOOLP384r1, BRAINPOOLP512r1
66
from .ecdh import ECDH, NoKeyError, NoCurveError, InvalidCurveError, \
77
InvalidSharedSecretError
88
from .der import UnexpectedDER

src/ecdsa/_compat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def str_idx_as_int(string, index):
1616
if sys.version_info < (3, 0):
1717
def normalise_bytes(buffer_object):
1818
"""Cast the input into array of bytes."""
19-
return buffer(buffer_object)
19+
# flake8 runs on py3 where `buffer` indeed doesn't exist...
20+
return buffer(buffer_object) # noqa: F821
2021

2122
def hmac_compat(ret):
2223
return ret

src/ecdsa/curves.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__all__ = ["UnknownCurveError", "orderlen", "Curve", "NIST192p",
1010
"NIST224p", "NIST256p", "NIST384p", "NIST521p", "curves",
1111
"find_curve", "SECP256k1", "BRAINPOOLP160r1", "BRAINPOOLP192r1",
12-
"BRAINPOOLP224r1", "BRAINPOOLP256r1" "BRAINPOOLP320r1",
12+
"BRAINPOOLP224r1", "BRAINPOOLP256r1", "BRAINPOOLP320r1",
1313
"BRAINPOOLP384r1", "BRAINPOOLP512r1"]
1414

1515

@@ -115,7 +115,7 @@ def __repr__(self):
115115

116116

117117
curves = [NIST192p, NIST224p, NIST256p, NIST384p, NIST521p, SECP256k1,
118-
BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1, BRAINPOOLP256r1,
118+
BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1, BRAINPOOLP256r1,
119119
BRAINPOOLP320r1, BRAINPOOLP384r1, BRAINPOOLP512r1]
120120

121121

src/ecdsa/ecdh.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class InvalidSharedSecretError(Exception):
3838
class ECDH(object):
3939
"""
4040
Elliptic-curve Diffie-Hellman (ECDH). A key agreement protocol.
41-
42-
Allows two parties, each having an elliptic-curve public-private key
41+
42+
Allows two parties, each having an elliptic-curve public-private key
4343
pair, to establish a shared secret over an insecure channel
4444
"""""
4545

@@ -283,8 +283,8 @@ def generate_sharedsecret_bytes(self):
283283
:rtype: byte string
284284
"""
285285
return number_to_string(
286-
self.generate_sharedsecret(),
287-
self.private_key.curve.order)
286+
self.generate_sharedsecret(),
287+
self.private_key.curve.order)
288288

289289
def generate_sharedsecret(self):
290290
"""

src/ecdsa/ecdsa.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ def __init__(self, generator, point, verify=True):
139139
raise InvalidPointError("Generator point order is bad.")
140140

141141
def __eq__(self, other):
142-
if isinstance(other, Public_key):
142+
if isinstance(other, Public_key):
143143
"""Return True if the points are identical, False otherwise."""
144144
return self.curve == other.curve \
145-
and self.point == other.point
145+
and self.point == other.point
146146
return NotImplemented
147147

148148
def verifies(self, hash, signature):
@@ -182,12 +182,12 @@ def __init__(self, public_key, secret_multiplier):
182182

183183
self.public_key = public_key
184184
self.secret_multiplier = secret_multiplier
185-
185+
186186
def __eq__(self, other):
187-
if isinstance(other, Private_key):
187+
if isinstance(other, Private_key):
188188
"""Return True if the points are identical, False otherwise."""
189189
return self.public_key == other.public_key \
190-
and self.secret_multiplier == other.secret_multiplier
190+
and self.secret_multiplier == other.secret_multiplier
191191
return NotImplemented
192192

193193
def sign(self, hash, random_k):
@@ -220,8 +220,8 @@ def sign(self, hash, random_k):
220220
r = p1.x() % n
221221
if r == 0:
222222
raise RSZeroError("amazingly unlucky random number r")
223-
s = (numbertheory.inverse_mod(k, n) *
224-
(hash + (self.secret_multiplier * r) % n)) % n
223+
s = (numbertheory.inverse_mod(k, n)
224+
* (hash + (self.secret_multiplier * r) % n)) % n
225225
if s == 0:
226226
raise RSZeroError("amazingly unlucky random number s")
227227
return Signature(r, s)
@@ -277,8 +277,8 @@ def point_is_valid(generator, x, y):
277277
if not curve.contains_point(x, y):
278278
return False
279279
if curve.cofactor() != 1 and \
280-
not n * ellipticcurve.PointJacobi(curve, x, y, 1)\
281-
== ellipticcurve.INFINITY:
280+
not n * ellipticcurve.PointJacobi(curve, x, y, 1)\
281+
== ellipticcurve.INFINITY:
282282
return False
283283
return True
284284

@@ -361,7 +361,7 @@ def point_is_valid(generator, x, y):
361361
generator_secp256k1 = ellipticcurve.PointJacobi(
362362
curve_secp256k1, _Gx, _Gy, 1, _r, generator=True)
363363

364-
# Brainpool P-160-r1
364+
# Brainpool P-160-r1
365365
_a = 0x340E7BE2A280EB74E2BE61BADA745D97E8F7C300
366366
_b = 0x1E589A8595423412134FAA2DBDEC95C8D8675E58
367367
_p = 0xE95E4A5F737059DC60DFC7AD95B3D8139515620F

src/ecdsa/ellipticcurve.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737

3838
try:
3939
from gmpy2 import mpz
40-
GMPY=True
40+
GMPY = True
4141
except ImportError:
4242
try:
4343
from gmpy import mpz
44-
GMPY=True
44+
GMPY = True
4545
except ImportError:
46-
GMPY=False
46+
GMPY = False
4747

4848

4949
from six import python_2_unicode_compatible
@@ -84,13 +84,13 @@ def __init__(self, p, a, b, h=None):
8484
self.__a = a
8585
self.__b = b
8686
self.__h = h
87-
87+
8888
def __eq__(self, other):
89-
if isinstance(other, CurveFp):
89+
if isinstance(other, CurveFp):
9090
"""Return True if the curves are identical, False otherwise."""
9191
return self.__p == other.__p \
92-
and self.__a == other.__a \
93-
and self.__b == other.__b
92+
and self.__a == other.__a \
93+
and self.__b == other.__b
9494
return NotImplemented
9595

9696
def __hash__(self):
@@ -155,7 +155,7 @@ def __init__(self, curve, x, y, z, order=None, generator=False):
155155
self.__y = y
156156
self.__z = z
157157
self.__order = order
158-
self.__precompute=[]
158+
self.__precompute = []
159159
if generator:
160160
assert order
161161
i = 1
@@ -192,7 +192,7 @@ def __eq__(self, other):
192192
# compare the fractions by bringing them to the same denominator
193193
# depend on short-circuit to save 4 multiplications in case of inequality
194194
return (x1 * zz2 - x2 * zz1) % p == 0 and \
195-
(y1 * zz2 * z2 - y2 * zz1 * z1) % p == 0
195+
(y1 * zz2 * z2 - y2 * zz1 * z1) % p == 0
196196

197197
def order(self):
198198
"""Return the order of the point.
@@ -604,10 +604,10 @@ def __init__(self, curve, x, y, order=None):
604604

605605
def __eq__(self, other):
606606
"""Return True if the points are identical, False otherwise."""
607-
if isinstance(other, Point):
607+
if isinstance(other, Point):
608608
return self.__curve == other.__curve \
609-
and self.__x == other.__x \
610-
and self.__y == other.__y
609+
and self.__x == other.__x \
610+
and self.__y == other.__y
611611
return NotImplemented
612612

613613
def __neg__(self):

src/ecdsa/keys.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def __repr__(self):
142142

143143
def __eq__(self, other):
144144
"""Return True if the points are identical, False otherwise."""
145-
if isinstance(other, VerifyingKey):
145+
if isinstance(other, VerifyingKey):
146146
return self.curve == other.curve \
147147
and self.pubkey == other.pubkey
148148
return NotImplemented
@@ -245,9 +245,9 @@ def _from_hybrid(cls, string, curve, validate_point):
245245
point = cls._from_raw_encoding(string[1:], curve)
246246

247247
# but validate if it's self-consistent if we're asked to do that
248-
if validate_point and \
249-
(point.y() & 1 and string[:1] != b('\x07') or
250-
(not point.y() & 1) and string[:1] != b('\x06')):
248+
if validate_point \
249+
and (point.y() & 1 and string[:1] != b('\x07')
250+
or (not point.y() & 1) and string[:1] != b('\x06')):
251251
raise MalformedPointError("Inconsistent hybrid point encoding")
252252

253253
return point
@@ -677,10 +677,10 @@ def __init__(self, _error__please_use_generate=None):
677677
self.baselen = None
678678
self.verifying_key = None
679679
self.privkey = None
680-
680+
681681
def __eq__(self, other):
682682
"""Return True if the points are identical, False otherwise."""
683-
if isinstance(other, SigningKey):
683+
if isinstance(other, SigningKey):
684684
return self.curve == other.curve \
685685
and self.verifying_key == other.verifying_key \
686686
and self.privkey == other.privkey
@@ -967,8 +967,7 @@ def to_der(self, point_encoding="uncompressed"):
967967
der.encode_integer(1),
968968
der.encode_octet_string(self.to_string()),
969969
der.encode_constructed(0, self.curve.encoded_oid),
970-
der.encode_constructed(1, der.encode_bitstring(encoded_vk, 0)),
971-
)
970+
der.encode_constructed(1, der.encode_bitstring(encoded_vk, 0)))
972971

973972
def get_verifying_key(self):
974973
"""

0 commit comments

Comments
 (0)
0