Skip to content

Commit 179c183

Browse files
committed
better cross-module linking in ecdsa.keys
1 parent 1609b85 commit 179c183

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

src/ecdsa/keys.py

+34-25
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def verify(
636636
:type signature: sigdecode method dependent
637637
:param data: data signed by the `signature`, will be hashed using
638638
`hashfunc`, if specified, or default hash function
639-
:type data: bytes like object
639+
:type data: :term:`bytes-like object`
640640
:param hashfunc: The default hash function that will be used for
641641
verification, needs to implement the same interface as hashlib.sha1
642642
:type hashfunc: callable
@@ -690,7 +690,7 @@ def verify_digest(
690690
:param signature: encoding of the signature
691691
:type signature: sigdecode method dependent
692692
:param digest: raw hash value that the signature authenticates.
693-
:type digest: bytes like object
693+
:type digest: :term:`bytes-like object`
694694
:param sigdecode: Callable to define the way the signature needs to
695695
be decoded to an object, needs to handle `signature` as the
696696
first parameter, the curve order (an int) as the second and return
@@ -879,7 +879,7 @@ def from_string(cls, string, curve=NIST192p, hashfunc=sha1):
879879
In Python 3, the expected type is `bytes`.
880880
881881
:param string: the raw encoding of the private key
882-
:type string: bytes like object
882+
:type string: :term:`bytes-like object`
883883
:param curve: The curve on which the point needs to reside
884884
:type curve: ~ecdsa.curves.Curve
885885
:param hashfunc: The default hash function that will be used for
@@ -1012,7 +1012,7 @@ def from_der(cls, string, hashfunc=sha1, valid_curve_encodings=None):
10121012
in them will not be detected.
10131013
10141014
:param string: binary string with DER-encoded private ECDSA key
1015-
:type string: bytes like object
1015+
:type string: :term:`bytes-like object`
10161016
:param valid_curve_encodings: list of allowed encoding formats
10171017
for curve parameters. By default (``None``) all are supported:
10181018
``named_curve`` and ``explicit``.
@@ -1315,7 +1315,7 @@ def sign_deterministic(
13151315
of data is necessary.
13161316
13171317
:param data: data to be hashed and computed signature over
1318-
:type data: bytes like object
1318+
:type data: :term:`bytes-like object`
13191319
:param hashfunc: hash function to use for computing the signature,
13201320
if unspecified, the default hash function selected during
13211321
object initialisation will be used (see
@@ -1334,7 +1334,7 @@ def sign_deterministic(
13341334
:param extra_entropy: additional data that will be fed into the random
13351335
number generator used in the RFC6979 process. Entirely optional.
13361336
Ignored with EdDSA.
1337-
:type extra_entropy: bytes like object
1337+
:type extra_entropy: :term:`bytes-like object`
13381338
13391339
:return: encoded signature over `data`
13401340
:rtype: bytes or sigencode function dependent type
@@ -1374,24 +1374,26 @@ def sign_digest_deterministic(
13741374
hashing of data is necessary.
13751375
13761376
:param digest: hash of data that will be signed
1377-
:type digest: bytes like object
1377+
:type digest: :term:`bytes-like object`
13781378
:param hashfunc: hash function to use for computing the random "k"
13791379
value from RFC6979 process,
13801380
if unspecified, the default hash function selected during
13811381
object initialisation will be used (see
1382-
`VerifyingKey.default_hashfunc`). The object needs to implement
1383-
the same interface as hashlib.sha1.
1382+
:attr:`.VerifyingKey.default_hashfunc`). The object needs to
1383+
implement
1384+
the same interface as :func:`~hashlib.sha1` from :py:mod:`hashlib`.
13841385
:type hashfunc: callable
13851386
:param sigencode: function used to encode the signature.
13861387
The function needs to accept three parameters: the two integers
13871388
that are the signature and the order of the curve over which the
13881389
signature was computed. It needs to return an encoded signature.
1389-
See `ecdsa.util.sigencode_string` and `ecdsa.util.sigencode_der`
1390+
See :func:`~ecdsa.util.sigencode_string` and
1391+
:func:`~ecdsa.util.sigencode_der`
13901392
as examples of such functions.
13911393
:type sigencode: callable
13921394
:param extra_entropy: additional data that will be fed into the random
13931395
number generator used in the RFC6979 process. Entirely optional.
1394-
:type extra_entropy: bytes like object
1396+
:type extra_entropy: :term:`bytes-like object`
13951397
:param bool allow_truncate: if True, the provided digest can have
13961398
bigger bit-size than the order of the curve, the extra bits (at
13971399
the end of the digest) will be truncated. Use it when signing
@@ -1456,46 +1458,53 @@ def sign(
14561458
method instead of this one.
14571459
14581460
:param data: data that will be hashed for signing
1459-
:type data: bytes like object
1460-
:param callable entropy: randomness source, os.urandom by default.
1461-
Ignored with EdDSA.
1462-
:param hashfunc: hash function to use for hashing the provided `data`.
1461+
:type data: :term:`bytes-like object`
1462+
:param callable entropy: randomness source, :func:`os.urandom` by
1463+
default. Ignored with EdDSA.
1464+
:param hashfunc: hash function to use for hashing the provided
1465+
``data``.
14631466
If unspecified the default hash function selected during
14641467
object initialisation will be used (see
1465-
`VerifyingKey.default_hashfunc`).
1466-
Should behave like hashlib.sha1. The output length of the
1468+
:attr:`.VerifyingKey.default_hashfunc`).
1469+
Should behave like :func:`~hashlib.sha1` from :py:mod:`hashlib`.
1470+
The output length of the
14671471
hash (in bytes) must not be longer than the length of the curve
14681472
order (rounded up to the nearest byte), so using SHA256 with
14691473
NIST256p is ok, but SHA256 with NIST192p is not. (In the 2**-96ish
14701474
unlikely event of a hash output larger than the curve order, the
14711475
hash will effectively be wrapped mod n).
1472-
Use hashfunc=hashlib.sha1 to match openssl's -ecdsa-with-SHA1 mode,
1473-
or hashfunc=hashlib.sha256 for openssl-1.0.0's -ecdsa-with-SHA256.
1476+
If you want to explicitly allow use of large hashes with small
1477+
curves set the ``allow_truncate`` to ``True``.
1478+
Use ``hashfunc=hashlib.sha1`` to match openssl's
1479+
``-ecdsa-with-SHA1`` mode,
1480+
or ``hashfunc=hashlib.sha256`` for openssl-1.0.0's
1481+
``-ecdsa-with-SHA256``.
14741482
Ignored for EdDSA
14751483
:type hashfunc: callable
14761484
:param sigencode: function used to encode the signature.
14771485
The function needs to accept three parameters: the two integers
14781486
that are the signature and the order of the curve over which the
14791487
signature was computed. It needs to return an encoded signature.
1480-
See `ecdsa.util.sigencode_string` and `ecdsa.util.sigencode_der`
1488+
See :func:`~ecdsa.util.sigencode_string` and
1489+
:func:`~ecdsa.util.sigencode_der`
14811490
as examples of such functions.
14821491
Ignored for EdDSA
14831492
:type sigencode: callable
14841493
:param int k: a pre-selected nonce for calculating the signature.
14851494
In typical use cases, it should be set to None (the default) to
14861495
allow its generation from an entropy source.
14871496
Ignored for EdDSA.
1488-
:param bool allow_truncate: if True, the provided digest can have
1497+
:param bool allow_truncate: if ``True``, the provided digest can have
14891498
bigger bit-size than the order of the curve, the extra bits (at
14901499
the end of the digest) will be truncated. Use it when signing
14911500
SHA-384 output using NIST256p or in similar situations. True by
14921501
default.
14931502
Ignored for EdDSA.
14941503
1495-
:raises RSZeroError: in the unlikely event when "r" parameter or
1496-
"s" parameter of the created signature is equal 0, as that would
1504+
:raises RSZeroError: in the unlikely event when *r* parameter or
1505+
*s* parameter of the created signature is equal 0, as that would
14971506
leak the key. Caller should try a better entropy source, retry with
1498-
different 'k', or use the
1507+
different ``k``, or use the
14991508
:func:`~SigningKey.sign_deterministic` in such case.
15001509
15011510
:return: encoded signature of the hash of `data`
@@ -1529,7 +1538,7 @@ def sign_digest(
15291538
instead of this one.
15301539
15311540
:param digest: hash value that will be signed
1532-
:type digest: bytes like object
1541+
:type digest: :term:`bytes-like object`
15331542
:param callable entropy: randomness source, os.urandom by default
15341543
:param sigencode: function used to encode the signature.
15351544
The function needs to accept three parameters: the two integers

0 commit comments

Comments
 (0)