Skip to content

Commit 83f10ae

Browse files
committed
fix sphinx warnings in doc stings
1 parent a3a91ec commit 83f10ae

File tree

5 files changed

+100
-79
lines changed

5 files changed

+100
-79
lines changed

src/ecdsa/ecdh.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def generate_private_key(self):
116116
:raises NoCurveError: Curve must be set before key generation.
117117
118118
:return: public (verifying) key from this private key.
119-
:rtype: VerifyingKey object
119+
:rtype: VerifyingKey
120120
"""
121121
if not self.curve:
122122
raise NoCurveError("Curve must be set prior to key generation.")
@@ -135,7 +135,7 @@ def load_private_key(self, private_key):
135135
:raises InvalidCurveError: private_key curve not the same as self.curve
136136
137137
:return: public (verifying) key from this private key.
138-
:rtype: VerifyingKey object
138+
:rtype: VerifyingKey
139139
"""
140140
if not self.curve:
141141
self.curve = private_key.curve
@@ -158,7 +158,7 @@ def load_private_key_bytes(self, private_key):
158158
:raises NoCurveError: Curve must be set before loading.
159159
160160
:return: public (verifying) key from this private key.
161-
:rtype: VerifyingKey object
161+
:rtype: VerifyingKey
162162
"""
163163
if not self.curve:
164164
raise NoCurveError("Curve must be set prior to key load.")
@@ -183,7 +183,7 @@ def load_private_key_der(self, private_key_der):
183183
:raises InvalidCurveError: private_key curve not the same as self.curve
184184
185185
:return: public (verifying) key from this private key.
186-
:rtype: VerifyingKey object
186+
:rtype: VerifyingKey
187187
"""
188188
return self.load_private_key(SigningKey.from_der(private_key_der))
189189

@@ -204,7 +204,7 @@ def load_private_key_pem(self, private_key_pem):
204204
:raises InvalidCurveError: private_key curve not the same as self.curve
205205
206206
:return: public (verifying) key from this private key.
207-
:rtype: VerifyingKey object
207+
:rtype: VerifyingKey
208208
"""
209209
return self.load_private_key(SigningKey.from_pem(private_key_pem))
210210

@@ -215,7 +215,7 @@ def get_public_key(self):
215215
Needs to be sent to the remote party.
216216
217217
:return: public (verifying) key from local private key.
218-
:rtype: VerifyingKey object
218+
:rtype: VerifyingKey
219219
"""
220220
return self.private_key.get_verifying_key()
221221

@@ -310,7 +310,7 @@ def generate_sharedsecret_bytes(self):
310310
:raises NoKeyError: public_key or private_key is not set
311311
312312
:return: shared secret
313-
:rtype: byte string
313+
:rtype: bytes
314314
"""
315315
return number_to_string(
316316
self.generate_sharedsecret(), self.private_key.curve.curve.p()
@@ -323,9 +323,9 @@ def generate_sharedsecret(self):
323323
The objects needs to have both private key and received public key
324324
before generation is allowed.
325325
326-
It's the same for local and remote party.
327-
shared secret(local private key, remote public key ) ==
328-
shared secret (local public key, remote private key)
326+
It's the same for local and remote party,
327+
shared secret(local private key, remote public key) ==
328+
shared secret(local public key, remote private key)
329329
330330
:raises InvalidCurveError: public_key curve not the same as self.curve
331331
:raises NoKeyError: public_key or private_key is not set

src/ecdsa/ecdsa.py

+50-32
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,64 @@
11
#! /usr/bin/env python
22

33
"""
4-
Implementation of Elliptic-Curve Digital Signatures.
4+
Low level implementation of Elliptic-Curve Digital Signatures.
5+
6+
.. note ::
7+
You're most likely looking for the :py:class:`~ecdsa.keys` module.
8+
This is a low-level implementation of the ECDSA that operates on
9+
integers, not byte strings.
510
611
Classes and methods for elliptic-curve signatures:
712
private keys, public keys, signatures,
8-
NIST prime-modulus curves with modulus lengths of
9-
192, 224, 256, 384, and 521 bits.
13+
and definitions of prime-modulus curves.
1014
1115
Example:
1216
13-
# (In real-life applications, you would probably want to
14-
# protect against defects in SystemRandom.)
15-
from random import SystemRandom
16-
randrange = SystemRandom().randrange
17+
.. code-block:: python
1718
18-
# Generate a public/private key pair using the NIST Curve P-192:
19+
# (In real-life applications, you would probably want to
20+
# protect against defects in SystemRandom.)
21+
from random import SystemRandom
22+
randrange = SystemRandom().randrange
1923
20-
g = generator_192
21-
n = g.order()
22-
secret = randrange( 1, n )
23-
pubkey = Public_key( g, g * secret )
24-
privkey = Private_key( pubkey, secret )
24+
# Generate a public/private key pair using the NIST Curve P-192:
2525
26-
# Signing a hash value:
26+
g = generator_192
27+
n = g.order()
28+
secret = randrange( 1, n )
29+
pubkey = Public_key( g, g * secret )
30+
privkey = Private_key( pubkey, secret )
2731
28-
hash = randrange( 1, n )
29-
signature = privkey.sign( hash, randrange( 1, n ) )
32+
# Signing a hash value:
3033
31-
# Verifying a signature for a hash value:
34+
hash = randrange( 1, n )
35+
signature = privkey.sign( hash, randrange( 1, n ) )
3236
33-
if pubkey.verifies( hash, signature ):
34-
print_("Demo verification succeeded.")
35-
else:
36-
print_("*** Demo verification failed.")
37+
# Verifying a signature for a hash value:
3738
38-
# Verification fails if the hash value is modified:
39+
if pubkey.verifies( hash, signature ):
40+
print_("Demo verification succeeded.")
41+
else:
42+
print_("*** Demo verification failed.")
3943
40-
if pubkey.verifies( hash-1, signature ):
41-
print_("**** Demo verification failed to reject tampered hash.")
42-
else:
43-
print_("Demo verification correctly rejected tampered hash.")
44+
# Verification fails if the hash value is modified:
4445
45-
Version of 2009.05.16.
46+
if pubkey.verifies( hash-1, signature ):
47+
print_("**** Demo verification failed to reject tampered hash.")
48+
else:
49+
print_("Demo verification correctly rejected tampered hash.")
4650
4751
Revision history:
4852
2005.12.31 - Initial version.
53+
4954
2008.11.25 - Substantial revisions introducing new classes.
55+
5056
2009.05.16 - Warn against using random.randrange in real applications.
57+
5158
2009.05.17 - Use random.SystemRandom by default.
5259
53-
Written in 2005 by Peter Pearson and placed in the public domain.
60+
Originally written in 2005 by Peter Pearson and placed in the public domain,
61+
modified as part of the python-ecdsa package.
5462
"""
5563

5664
from six import int2byte, b
@@ -69,16 +77,26 @@ class InvalidPointError(RuntimeError):
6977

7078

7179
class Signature(object):
72-
"""ECDSA signature."""
80+
"""
81+
ECDSA signature.
82+
83+
:ivar int r: the ``r`` element of the ECDSA signature
84+
:ivar int s: the ``s`` element of the ECDSA signature
85+
"""
7386

7487
def __init__(self, r, s):
7588
self.r = r
7689
self.s = s
7790

7891
def recover_public_keys(self, hash, generator):
79-
"""Returns two public keys for which the signature is valid
80-
hash is signed hash
81-
generator is the used generator of the signature
92+
"""
93+
Returns two public keys for which the signature is valid
94+
95+
:param int hash: signed hash
96+
:param AbstractPoint generator: is the generator used in creation
97+
of the signature
98+
:rtype: tuple(Public_key, Public_key)
99+
:return: a pair of public keys that can validate the signature
82100
"""
83101
curve = generator.curve()
84102
n = generator.order()

src/ecdsa/ellipticcurve.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def from_bytes(
224224
:param data: single point encoding of the public key
225225
:type data: :term:`bytes-like object`
226226
:param curve: the curve on which the public key is expected to lay
227-
:type curve: ecdsa.ellipticcurve.CurveFp
227+
:type curve: ~ecdsa.ellipticcurve.CurveFp
228228
:param validate_encoding: whether to verify that the encoding of the
229229
point is self-consistent, defaults to True, has effect only
230230
on ``hybrid`` encoding
@@ -235,8 +235,8 @@ def from_bytes(
235235
name). All formats by default (specified with ``None``).
236236
:type valid_encodings: :term:`set-like object`
237237
238-
:raises MalformedPointError: if the public point does not lay on the
239-
curve or the encoding is invalid
238+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
239+
not lay on the curve or the encoding is invalid
240240
241241
:return: x and y coordinates of the encoded point
242242
:rtype: tuple(int, int)
@@ -391,7 +391,7 @@ def from_bytes(
391391
:param data: single point encoding of the public key
392392
:type data: :term:`bytes-like object`
393393
:param curve: the curve on which the public key is expected to lay
394-
:type curve: ecdsa.ellipticcurve.CurveFp
394+
:type curve: ~ecdsa.ellipticcurve.CurveFp
395395
:param validate_encoding: whether to verify that the encoding of the
396396
point is self-consistent, defaults to True, has effect only
397397
on ``hybrid`` encoding
@@ -407,8 +407,8 @@ def from_bytes(
407407
such, it will be commonly used with scalar multiplication. This
408408
will cause to precompute multiplication table generation for it
409409
410-
:raises MalformedPointError: if the public point does not lay on the
411-
curve or the encoding is invalid
410+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
411+
not lay on the curve or the encoding is invalid
412412
413413
:return: Point on curve
414414
:rtype: PointJacobi
@@ -970,7 +970,7 @@ def from_bytes(
970970
:param data: single point encoding of the public key
971971
:type data: :term:`bytes-like object`
972972
:param curve: the curve on which the public key is expected to lay
973-
:type curve: ecdsa.ellipticcurve.CurveFp
973+
:type curve: ~ecdsa.ellipticcurve.CurveFp
974974
:param validate_encoding: whether to verify that the encoding of the
975975
point is self-consistent, defaults to True, has effect only
976976
on ``hybrid`` encoding
@@ -983,8 +983,8 @@ def from_bytes(
983983
:param int order: the point order, must be non zero when using
984984
generator=True
985985
986-
:raises MalformedPointError: if the public point does not lay on the
987-
curve or the encoding is invalid
986+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
987+
not lay on the curve or the encoding is invalid
988988
989989
:return: Point on curve
990990
:rtype: Point

0 commit comments

Comments
 (0)