Skip to content

Commit e698072

Browse files
committed
fix and check for lines 80 chars and longer
1 parent 5a922f9 commit e698072

File tree

6 files changed

+35
-33
lines changed

6 files changed

+35
-33
lines changed

src/ecdsa/ecdh.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ class NoCurveError(Exception):
2929

3030

3131
class InvalidCurveError(Exception):
32-
"""ECDH. Raised in case the public and private keys use different curves."""
32+
"""
33+
ECDH. Raised in case the public and private keys use different curves.
34+
"""
3335

3436
pass
3537

@@ -174,7 +176,8 @@ def load_private_key_der(self, private_key_der):
174176
Note, the only DER format supported is the RFC5915
175177
Look at keys.py:SigningKey.from_der()
176178
177-
:param private_key_der: string with the DER encoding of private ECDSA key
179+
:param private_key_der: string with the DER encoding of private ECDSA
180+
key
178181
:type private_key_der: string
179182
180183
:raises InvalidCurveError: private_key curve not the same as self.curve

src/ecdsa/ellipticcurve.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def __init__(self, p, a, b, h=None):
6464
The curve of points satisfying y^2 = x^3 + a*x + b (mod p).
6565
6666
h is an integer that is the cofactor of the elliptic curve domain
67-
parameters; it is the number of points satisfying the elliptic curve
68-
equation divided by the order of the base point. It is used for selection
69-
of efficient algorithm for public point verification.
67+
parameters; it is the number of points satisfying the elliptic
68+
curve equation divided by the order of the base point. It is used
69+
for selection of efficient algorithm for public point verification.
7070
"""
7171
self.__p = mpz(p)
7272
self.__a = mpz(a)
@@ -82,9 +82,9 @@ def __init__(self, p, a, b, h=None):
8282
The curve of points satisfying y^2 = x^3 + a*x + b (mod p).
8383
8484
h is an integer that is the cofactor of the elliptic curve domain
85-
parameters; it is the number of points satisfying the elliptic curve
86-
equation divided by the order of the base point. It is used for selection
87-
of efficient algorithm for public point verification.
85+
parameters; it is the number of points satisfying the elliptic
86+
curve equation divided by the order of the base point. It is used
87+
for selection of efficient algorithm for public point verification.
8888
"""
8989
self.__p = p
9090
self.__a = a
@@ -228,7 +228,8 @@ def __eq__(self, other):
228228
zz2 = z2 * z2 % p
229229

230230
# compare the fractions by bringing them to the same denominator
231-
# depend on short-circuit to save 4 multiplications in case of inequality
231+
# depend on short-circuit to save 4 multiplications in case of
232+
# inequality
232233
return (x1 * zz2 - x2 * zz1) % p == 0 and (
233234
y1 * zz2 * z2 - y2 * zz1 * z1
234235
) % p == 0
@@ -309,8 +310,8 @@ def scale(self):
309310
zz_inv = z_inv * z_inv % p
310311
self.__x = self.__x * zz_inv % p
311312
self.__y = self.__y * zz_inv * z_inv % p
312-
# we are setting the z last so that the check above will return true
313-
# only after all values were already updated
313+
# we are setting the z last so that the check above will return
314+
# true only after all values were already updated
314315
self.__z = 1
315316
finally:
316317
self._scale_lock.writer_release()
@@ -599,7 +600,7 @@ def __mul__(self, other):
599600

600601
@staticmethod
601602
def _leftmost_bit(x):
602-
"""Return integer with the same magnitude as x but hamming weight of 1"""
603+
"""Return integer with the same magnitude as x but only one bit set"""
603604
assert x > 0
604605
result = 1
605606
while result <= x:
@@ -688,9 +689,9 @@ def __init__(self, curve, x, y, order=None):
688689
# self.curve is allowed to be None only for INFINITY:
689690
if self.__curve:
690691
assert self.__curve.contains_point(x, y)
691-
# for curves with cofactor 1, all points that are on the curve are scalar
692-
# multiples of the base point, so performing multiplication is not
693-
# necessary to verify that. See Section 3.2.2.1 of SEC 1 v2
692+
# for curves with cofactor 1, all points that are on the curve are
693+
# scalar multiples of the base point, so performing multiplication is
694+
# not necessary to verify that. See Section 3.2.2.1 of SEC 1 v2
694695
if curve and curve.cofactor() != 1 and order:
695696
assert self * order == INFINITY
696697

src/ecdsa/keys.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,8 @@ def from_secret_exponent(cls, secexp, curve=NIST192p, hashfunc=sha1):
801801
n = curve.order
802802
if not 1 <= secexp < n:
803803
raise MalformedPointError(
804-
"Invalid value for secexp, expected integer between 1 and {0}".format(
805-
n
806-
)
804+
"Invalid value for secexp, expected integer "
805+
"between 1 and {0}".format(n)
807806
)
808807
pubkey_point = curve.generator * secexp
809808
if hasattr(pubkey_point, "scale"):
@@ -845,9 +844,8 @@ def from_string(cls, string, curve=NIST192p, hashfunc=sha1):
845844
string = normalise_bytes(string)
846845
if len(string) != curve.baselen:
847846
raise MalformedPointError(
848-
"Invalid length of private key, received {0}, expected {1}".format(
849-
len(string), curve.baselen
850-
)
847+
"Invalid length of private key, received {0}, "
848+
"expected {1}".format(len(string), curve.baselen)
851849
)
852850
secexp = string_to_number(string)
853851
return cls.from_secret_exponent(secexp, curve, hashfunc)
@@ -1035,7 +1033,8 @@ def from_der(cls, string, hashfunc=sha1):
10351033
# pubkey_str = der.remove_bitstring(pubkey_bitstring, 0)
10361034
# if empty != "":
10371035
# raise der.UnexpectedDER("trailing junk after DER privkey "
1038-
# "pubkeystr: %s" % binascii.hexlify(empty))
1036+
# "pubkeystr: %s"
1037+
# % binascii.hexlify(empty))
10391038

10401039
# our from_string method likes fixed-length privkey strings
10411040
if len(privkey_str) < curve.baselen:

src/ecdsa/rfc6979.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def generate_k(order, secexp, hash_func, data, retry_gen=0, extra_entropy=b""):
4444
"""
4545
order - order of the DSA generator used in the signature
4646
secexp - secure exponent (private key) in numeric form
47-
hash_func - reference to the same hash function used for generating hash
47+
hash_func - reference to the same hash function used for generating
48+
hash
4849
data - hash in binary form of the signing data
4950
retry_gen - int - how many good 'k' values to skip before returning
5051
extra_entropy - extra added data in binary form as per section-3.6 of

src/ecdsa/util.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ def sigencode_der(r, s, order):
281281

282282

283283
# canonical versions of sigencode methods
284-
# these enforce low S values, by negating the value (modulo the order) if above order/2
285-
# see CECKey::Sign() https://github.com/bitcoin/bitcoin/blob/master/src/key.cpp#L214
284+
# these enforce low S values, by negating the value (modulo the order) if
285+
# above order/2 see CECKey::Sign()
286+
# https://github.com/bitcoin/bitcoin/blob/master/src/key.cpp#L214
286287
def sigencode_strings_canonize(r, s, order):
287288
if s > order / 2:
288289
s = order - s
@@ -379,16 +380,14 @@ def sigdecode_strings(rs_strings, order):
379380
if not len(r_str) == l:
380381
raise MalformedSignature(
381382
"Invalid length of first string ('r' parameter), "
382-
"expected {0} bytes long, provided string is {1} bytes long".format(
383-
l, len(r_str)
384-
)
383+
"expected {0} bytes long, provided string is {1} "
384+
"bytes long".format(l, len(r_str))
385385
)
386386
if not len(s_str) == l:
387387
raise MalformedSignature(
388388
"Invalid length of second string ('s' parameter), "
389-
"expected {0} bytes long, provided string is {1} bytes long".format(
390-
l, len(s_str)
391-
)
389+
"expected {0} bytes long, provided string is {1} "
390+
"bytes long".format(l, len(s_str))
392391
)
393392
r = string_to_number_fixedlen(r_str, order)
394393
s = string_to_number_fixedlen(s_str, order)

tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,5 @@ commands =
8484
exclude = src/ecdsa/test*.py
8585
# We're just getting started. For now, ignore the following problems:
8686
# E203: whitespace before ':' (this needs to be ignored for black compatibility)
87-
# E501: line too long
8887
# E741: ambiguous variable name
89-
extend-ignore = E203,E501,E741
88+
extend-ignore = E203,E741

0 commit comments

Comments
 (0)