Skip to content

Commit ef898fc

Browse files
committed
fix sphinx warnings in doc stings
1 parent 8531f73 commit ef898fc

File tree

6 files changed

+110
-88
lines changed

6 files changed

+110
-88
lines changed

src/ecdsa/_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def a2b_hex(val):
128128
raise ValueError("base16 error: %s" % e)
129129

130130
# pylint: disable=invalid-name
131-
# pylint is stupid here and deson't notice it's a function, not
131+
# pylint is stupid here and doesn't notice it's a function, not
132132
# constant
133133
bytes_to_int = int.from_bytes
134134
# pylint: enable=invalid-name

src/ecdsa/ecdh.py

Lines changed: 10 additions & 10 deletions
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

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,67 @@
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
NOTE: This a low level implementation of ECDSA, for normal applications
712
you should be looking at the keys.py module.
813
914
Classes and methods for elliptic-curve signatures:
1015
private keys, public keys, signatures,
11-
NIST prime-modulus curves with modulus lengths of
12-
192, 224, 256, 384, and 521 bits.
16+
and definitions of prime-modulus curves.
1317
1418
Example:
1519
16-
# (In real-life applications, you would probably want to
17-
# protect against defects in SystemRandom.)
18-
from random import SystemRandom
19-
randrange = SystemRandom().randrange
20+
.. code-block:: python
2021
21-
# Generate a public/private key pair using the NIST Curve P-192:
22+
# (In real-life applications, you would probably want to
23+
# protect against defects in SystemRandom.)
24+
from random import SystemRandom
25+
randrange = SystemRandom().randrange
2226
23-
g = generator_192
24-
n = g.order()
25-
secret = randrange( 1, n )
26-
pubkey = Public_key( g, g * secret )
27-
privkey = Private_key( pubkey, secret )
27+
# Generate a public/private key pair using the NIST Curve P-192:
2828
29-
# Signing a hash value:
29+
g = generator_192
30+
n = g.order()
31+
secret = randrange( 1, n )
32+
pubkey = Public_key( g, g * secret )
33+
privkey = Private_key( pubkey, secret )
3034
31-
hash = randrange( 1, n )
32-
signature = privkey.sign( hash, randrange( 1, n ) )
35+
# Signing a hash value:
3336
34-
# Verifying a signature for a hash value:
37+
hash = randrange( 1, n )
38+
signature = privkey.sign( hash, randrange( 1, n ) )
3539
36-
if pubkey.verifies( hash, signature ):
37-
print_("Demo verification succeeded.")
38-
else:
39-
print_("*** Demo verification failed.")
40+
# Verifying a signature for a hash value:
4041
41-
# Verification fails if the hash value is modified:
42+
if pubkey.verifies( hash, signature ):
43+
print_("Demo verification succeeded.")
44+
else:
45+
print_("*** Demo verification failed.")
4246
43-
if pubkey.verifies( hash-1, signature ):
44-
print_("**** Demo verification failed to reject tampered hash.")
45-
else:
46-
print_("Demo verification correctly rejected tampered hash.")
47+
# Verification fails if the hash value is modified:
4748
48-
Version of 2009.05.16.
49+
if pubkey.verifies( hash-1, signature ):
50+
print_("**** Demo verification failed to reject tampered hash.")
51+
else:
52+
print_("Demo verification correctly rejected tampered hash.")
4953
5054
Revision history:
5155
2005.12.31 - Initial version.
56+
5257
2008.11.25 - Substantial revisions introducing new classes.
58+
5359
2009.05.16 - Warn against using random.randrange in real applications.
60+
5461
2009.05.17 - Use random.SystemRandom by default.
5562
56-
Written in 2005 by Peter Pearson and placed in the public domain.
63+
Originally written in 2005 by Peter Pearson and placed in the public domain,
64+
modified as part of the python-ecdsa package.
5765
"""
5866

5967
from six import int2byte, b
@@ -72,16 +80,26 @@ class InvalidPointError(RuntimeError):
7280

7381

7482
class Signature(object):
75-
"""ECDSA signature."""
83+
"""
84+
ECDSA signature.
85+
86+
:ivar int r: the ``r`` element of the ECDSA signature
87+
:ivar int s: the ``s`` element of the ECDSA signature
88+
"""
7689

7790
def __init__(self, r, s):
7891
self.r = r
7992
self.s = s
8093

8194
def recover_public_keys(self, hash, generator):
82-
"""Returns two public keys for which the signature is valid
83-
hash is signed hash
84-
generator is the used generator of the signature
95+
"""
96+
Returns two public keys for which the signature is valid
97+
98+
:param int hash: signed hash
99+
:param AbstractPoint generator: is the generator used in creation
100+
of the signature
101+
:rtype: tuple(Public_key, Public_key)
102+
:return: a pair of public keys that can validate the signature
85103
"""
86104
curve = generator.curve()
87105
n = generator.order()

src/ecdsa/ellipticcurve.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def from_bytes(
342342
:param data: single point encoding of the public key
343343
:type data: :term:`bytes-like object`
344344
:param curve: the curve on which the public key is expected to lay
345-
:type curve: ecdsa.ellipticcurve.CurveFp
345+
:type curve: ~ecdsa.ellipticcurve.CurveFp
346346
:param validate_encoding: whether to verify that the encoding of the
347347
point is self-consistent, defaults to True, has effect only
348348
on ``hybrid`` encoding
@@ -353,8 +353,8 @@ def from_bytes(
353353
name). All formats by default (specified with ``None``).
354354
:type valid_encodings: :term:`set-like object`
355355
356-
:raises MalformedPointError: if the public point does not lay on the
357-
curve or the encoding is invalid
356+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
357+
not lay on the curve or the encoding is invalid
358358
359359
:return: x and y coordinates of the encoded point
360360
:rtype: tuple(int, int)
@@ -547,7 +547,7 @@ def from_bytes(
547547
:param data: single point encoding of the public key
548548
:type data: :term:`bytes-like object`
549549
:param curve: the curve on which the public key is expected to lay
550-
:type curve: ecdsa.ellipticcurve.CurveFp
550+
:type curve: ~ecdsa.ellipticcurve.CurveFp
551551
:param validate_encoding: whether to verify that the encoding of the
552552
point is self-consistent, defaults to True, has effect only
553553
on ``hybrid`` encoding
@@ -563,8 +563,8 @@ def from_bytes(
563563
such, it will be commonly used with scalar multiplication. This
564564
will cause to precompute multiplication table generation for it
565565
566-
:raises MalformedPointError: if the public point does not lay on the
567-
curve or the encoding is invalid
566+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
567+
not lay on the curve or the encoding is invalid
568568
569569
:return: Point on curve
570570
:rtype: PointJacobi
@@ -1110,7 +1110,7 @@ def from_bytes(
11101110
:param data: single point encoding of the public key
11111111
:type data: :term:`bytes-like object`
11121112
:param curve: the curve on which the public key is expected to lay
1113-
:type curve: ecdsa.ellipticcurve.CurveFp
1113+
:type curve: ~ecdsa.ellipticcurve.CurveFp
11141114
:param validate_encoding: whether to verify that the encoding of the
11151115
point is self-consistent, defaults to True, has effect only
11161116
on ``hybrid`` encoding
@@ -1123,8 +1123,8 @@ def from_bytes(
11231123
:param int order: the point order, must be non zero when using
11241124
generator=True
11251125
1126-
:raises MalformedPointError: if the public point does not lay on the
1127-
curve or the encoding is invalid
1126+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
1127+
not lay on the curve or the encoding is invalid
11281128
11291129
:return: Point on curve
11301130
:rtype: Point
@@ -1320,8 +1320,8 @@ def from_bytes(
13201320
this will cause the library to pre-compute some values to
13211321
make repeated usages of the point much faster
13221322
1323-
:raises MalformedPointError: if the public point does not lay on the
1324-
curve or the encoding is invalid
1323+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
1324+
not lay on the curve or the encoding is invalid
13251325
13261326
:return: Initialised point on an Edwards curve
13271327
:rtype: PointEdwards

0 commit comments

Comments
 (0)