Skip to content

Commit f757a23

Browse files
committed
Fix docstring indentation issues
1 parent 33092d8 commit f757a23

File tree

4 files changed

+118
-125
lines changed

4 files changed

+118
-125
lines changed

src/ecdsa/ecdh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(self, curve=None, private_key=None, public_key=None):
6363
:type private_key: SigningKey
6464
:param public_key: `their` public key for ECDH
6565
:type public_key: VerifyingKey
66-
"""
66+
"""
6767
self.curve = curve
6868
self.private_key = None
6969
self.public_key = None

src/ecdsa/ecdsa.py

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,17 @@ class InvalidPointError(RuntimeError):
6868

6969

7070
class Signature(object):
71-
"""ECDSA signature.
72-
"""
71+
"""ECDSA signature."""
7372

7473
def __init__(self, r, s):
7574
self.r = r
7675
self.s = s
7776

7877
def recover_public_keys(self, hash, generator):
7978
"""Returns two public keys for which the signature is valid
80-
hash is signed hash
81-
generator is the used generator of the signature
82-
"""
79+
hash is signed hash
80+
generator is the used generator of the signature
81+
"""
8382
curve = generator.curve()
8483
n = generator.order()
8584
r = self.r
@@ -108,20 +107,18 @@ def recover_public_keys(self, hash, generator):
108107

109108

110109
class Public_key(object):
111-
"""Public key for ECDSA.
112-
"""
110+
"""Public key for ECDSA."""
113111

114112
def __init__(self, generator, point, verify=True):
115-
"""
116-
Low level ECDSA public key object.
113+
"""Low level ECDSA public key object.
117114
118-
:param generator: the Point that generates the group (the base point)
119-
:param point: the Point that defines the public key
120-
:param bool verify: if True check if point is valid point on curve
115+
:param generator: the Point that generates the group (the base point)
116+
:param point: the Point that defines the public key
117+
:param bool verify: if True check if point is valid point on curve
121118
122-
:raises InvalidPointError: if the point parameters are invalid or
123-
point does not lie on the curve
124-
"""
119+
:raises InvalidPointError: if the point parameters are invalid or
120+
point does not lie on the curve
121+
"""
125122

126123
self.curve = generator.curve()
127124
self.generator = generator
@@ -154,8 +151,8 @@ def __eq__(self, other):
154151

155152
def verifies(self, hash, signature):
156153
"""Verify that signature is a valid signature of hash.
157-
Return True if the signature is valid.
158-
"""
154+
Return True if the signature is valid.
155+
"""
159156

160157
# From X9.62 J.3.1.
161158

@@ -179,13 +176,12 @@ def verifies(self, hash, signature):
179176

180177

181178
class Private_key(object):
182-
"""Private key for ECDSA.
183-
"""
179+
"""Private key for ECDSA."""
184180

185181
def __init__(self, public_key, secret_multiplier):
186182
"""public_key is of class Public_key;
187-
secret_multiplier is a large integer.
188-
"""
183+
secret_multiplier is a large integer.
184+
"""
189185

190186
self.public_key = public_key
191187
self.secret_multiplier = secret_multiplier
@@ -201,18 +197,18 @@ def __eq__(self, other):
201197

202198
def sign(self, hash, random_k):
203199
"""Return a signature for the provided hash, using the provided
204-
random nonce. It is absolutely vital that random_k be an unpredictable
205-
number in the range [1, self.public_key.point.order()-1]. If
206-
an attacker can guess random_k, he can compute our private key from a
207-
single signature. Also, if an attacker knows a few high-order
208-
bits (or a few low-order bits) of random_k, he can compute our private
209-
key from many signatures. The generation of nonces with adequate
210-
cryptographic strength is very difficult and far beyond the scope
211-
of this comment.
212-
213-
May raise RuntimeError, in which case retrying with a new
214-
random value k is in order.
215-
"""
200+
random nonce. It is absolutely vital that random_k be an unpredictable
201+
number in the range [1, self.public_key.point.order()-1]. If
202+
an attacker can guess random_k, he can compute our private key from a
203+
single signature. Also, if an attacker knows a few high-order
204+
bits (or a few low-order bits) of random_k, he can compute our private
205+
key from many signatures. The generation of nonces with adequate
206+
cryptographic strength is very difficult and far beyond the scope
207+
of this comment.
208+
209+
May raise RuntimeError, in which case retrying with a new
210+
random value k is in order.
211+
"""
216212

217213
G = self.public_key.generator
218214
n = G.order()

src/ecdsa/ellipticcurve.py

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ class CurveFp(object):
6161

6262
def __init__(self, p, a, b, h=None):
6363
"""
64-
The curve of points satisfying y^2 = x^3 + a*x + b (mod p).
64+
The curve of points satisfying y^2 = x^3 + a*x + b (mod p).
6565
66-
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.
70-
"""
66+
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.
70+
"""
7171
self.__p = mpz(p)
7272
self.__a = mpz(a)
7373
self.__b = mpz(b)
@@ -79,13 +79,13 @@ def __init__(self, p, a, b, h=None):
7979

8080
def __init__(self, p, a, b, h=None):
8181
"""
82-
The curve of points satisfying y^2 = x^3 + a*x + b (mod p).
82+
The curve of points satisfying y^2 = x^3 + a*x + b (mod p).
8383
84-
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.
88-
"""
84+
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.
88+
"""
8989
self.__p = p
9090
self.__a = a
9191
self.__b = b
@@ -131,32 +131,32 @@ def __str__(self):
131131

132132
class PointJacobi(object):
133133
"""
134-
Point on an elliptic curve. Uses Jacobi coordinates.
134+
Point on an elliptic curve. Uses Jacobi coordinates.
135135
136-
In Jacobian coordinates, there are three parameters, X, Y and Z.
137-
They correspond to affine parameters 'x' and 'y' like so:
136+
In Jacobian coordinates, there are three parameters, X, Y and Z.
137+
They correspond to affine parameters 'x' and 'y' like so:
138138
139-
x = X / Z²
140-
y = Y / Z³
141-
"""
139+
x = X / Z²
140+
y = Y / Z³
141+
"""
142142

143143
def __init__(self, curve, x, y, z, order=None, generator=False):
144144
"""
145-
Initialise a point that uses Jacobi representation internally.
146-
147-
:param CurveFp curve: curve on which the point resides
148-
:param int x: the X parameter of Jacobi representation (equal to x when
149-
converting from affine coordinates
150-
:param int y: the Y parameter of Jacobi representation (equal to y when
151-
converting from affine coordinates
152-
:param int z: the Z parameter of Jacobi representation (equal to 1 when
153-
converting from affine coordinates
154-
:param int order: the point order, must be non zero when using
155-
generator=True
156-
:param bool generator: the point provided is a curve generator, as
157-
such, it will be commonly used with scalar multiplication. This will
158-
cause to precompute multiplication table for it
159-
"""
145+
Initialise a point that uses Jacobi representation internally.
146+
147+
:param CurveFp curve: curve on which the point resides
148+
:param int x: the X parameter of Jacobi representation (equal to x when
149+
converting from affine coordinates
150+
:param int y: the Y parameter of Jacobi representation (equal to y when
151+
converting from affine coordinates
152+
:param int z: the Z parameter of Jacobi representation (equal to 1 when
153+
converting from affine coordinates
154+
:param int order: the point order, must be non zero when using
155+
generator=True
156+
:param bool generator: the point provided is a curve generator, as
157+
such, it will be commonly used with scalar multiplication. This will
158+
cause to precompute multiplication table for it
159+
"""
160160
self.__curve = curve
161161
# since it's generally better (faster) to use scaled points vs unscaled
162162
# ones, use writer-biased RWLock for locking:
@@ -220,8 +220,8 @@ def __eq__(self, other):
220220
def order(self):
221221
"""Return the order of the point.
222222
223-
None if it is undefined.
224-
"""
223+
None if it is undefined.
224+
"""
225225
return self.__order
226226

227227
def curve(self):
@@ -230,13 +230,13 @@ def curve(self):
230230

231231
def x(self):
232232
"""
233-
Return affine x coordinate.
233+
Return affine x coordinate.
234234
235-
This method should be used only when the 'y' coordinate is not needed.
236-
It's computationally more efficient to use `to_affine()` and then
237-
call x() and y() on the returned instance. Or call `scale()`
238-
and then x() and y() on the returned instance.
239-
"""
235+
This method should be used only when the 'y' coordinate is not needed.
236+
It's computationally more efficient to use `to_affine()` and then
237+
call x() and y() on the returned instance. Or call `scale()`
238+
and then x() and y() on the returned instance.
239+
"""
240240
try:
241241
self._scale_lock.reader_acquire()
242242
if self.__z == 1:
@@ -251,13 +251,13 @@ def x(self):
251251

252252
def y(self):
253253
"""
254-
Return affine y coordinate.
254+
Return affine y coordinate.
255255
256-
This method should be used only when the 'x' coordinate is not needed.
257-
It's computationally more efficient to use `to_affine()` and then
258-
call x() and y() on the returned instance. Or call `scale()`
259-
and then x() and y() on the returned instance.
260-
"""
256+
This method should be used only when the 'x' coordinate is not needed.
257+
It's computationally more efficient to use `to_affine()` and then
258+
call x() and y() on the returned instance. Or call `scale()`
259+
and then x() and y() on the returned instance.
260+
"""
261261
try:
262262
self._scale_lock.reader_acquire()
263263
if self.__z == 1:
@@ -272,10 +272,10 @@ def y(self):
272272

273273
def scale(self):
274274
"""
275-
Return point scaled so that z == 1.
275+
Return point scaled so that z == 1.
276276
277-
Modifies point in place, returns self.
278-
"""
277+
Modifies point in place, returns self.
278+
"""
279279
try:
280280
self._scale_lock.reader_acquire()
281281
if self.__z == 1:
@@ -312,10 +312,10 @@ def to_affine(self):
312312
def from_affine(point, generator=False):
313313
"""Create from an affine point.
314314
315-
:param bool generator: set to True to make the point to precalculate
316-
multiplication table - useful for public point when verifying many
317-
signatures (around 100 or so) or for generator points of a curve.
318-
"""
315+
:param bool generator: set to True to make the point to precalculate
316+
multiplication table - useful for public point when verifying many
317+
signatures (around 100 or so) or for generator points of a curve.
318+
"""
319319
return PointJacobi(
320320
point.curve(), point.x(), point.y(), 1, point.order(), generator
321321
)

0 commit comments

Comments
 (0)