
    [Ah                     ^   S r SSKrSSKJr  SSKrSSKJr  SSKJrJ	r	  SSKJ
r
Jr  SSKJr  SS	KJr  SS
KJrJrJrJr  SSKJr  SSKJrJrJr  SSKJrJrJr  SSKJrJrJrJrJr  SSK J!r!  SSK"J#r#  SSKJ$r$J%r%  / SQr& " S S\'5      r( " S S\'5      r)S r* " S S\+5      r, " S S\+5      r-g)zE
Primary classes for performing signing and verification operations.
    N)sha1)PY2   )ecdsaeddsa)derssh)rfc6979)ellipticcurve)NIST192pCurveEd25519Ed448)RSZeroError)string_to_numbernumber_to_string	randrange)sigencode_stringsigdecode_string
bit_length)oid_ecPublicKeyencoded_oid_ecPublicKeyoid_ecDH	oid_ecMQVMalformedSignature)normalise_bytes)MalformedPointError)PointJacobi	CurveEdTw)BadSignatureErrorBadDigestErrorVerifyingKey
SigningKeyr   c                       \ rS rSrSrSrg)r    &   aP  
Raised when verification of signature failed.

Will be raised irrespective of reason of the failure:

* the calculated or provided hash does not match the signature
* the signature does not match the curve/public key
* the encoding of the signature is malformed
* the size of the signature does not match the curve of the VerifyingKey
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r&       QC:\Users\julio\Documents\inmobiliaria_backend\env\Lib\site-packages\ecdsa/keys.pyr    r    &   s    	 	r.   r    c                       \ rS rSrSrSrg)r!   5   z<Raised in case the selected hash is too large for the curve.r&   Nr'   r&   r.   r/   r!   r!   5   s    Fr.   r!   c           	      T   U(       dK  [        U 5      UR                  :  a1  [        SR                  UR                  S[        U 5      -  5      5      eOU SUR                   n [        U 5      nU(       a4  [        UR                  5      n[        U 5      S-  nU[        SXT-
  5      -  nU$ )z,Truncates and converts digest to an integer.zAthis curve ({0}) is too short for the length of your digest ({1})   Nr   )	lenbaselenr!   formatnamer   r   ordermax)digestcurveallow_truncatenumber
max_lengthlengths         r/   _truncate_and_convert_digestr@   ;   s    v;& 66<fJJCK7  ' %--(f%F,
Vq 	3q&-..Mr.   c                   "   \ rS rSrSrSS jrS rS rS r\	\
\S4S	 j5       rSS jr\	\
\SS4S j5       r\	\SS4S j5       r\	\SS4S j5       r\	\\S4S j5       r\	\\S
4S j5       rSS jr SS jr SS jrS rS\S4S jr\S
4S jrSrg)r"   [   a  
Class for handling keys that can verify signatures (public keys).

:ivar `~ecdsa.curves.Curve` ~.curve: The Curve over which all the
    cryptographic operations will take place
:ivar default_hashfunc: the function that will be used for hashing the
    data. Should implement the same API as hashlib.sha1
:vartype default_hashfunc: callable
:ivar pubkey: the actual public key
:vartype pubkey: ~ecdsa.ecdsa.Public_key
Nc                 R    U(       d  [        S5      eSU l        SU l        SU l        g)>Unsupported, please use one of the classmethods to initialise.z2Please use VerifyingKey.generate() to construct meN)	TypeErrorr;   default_hashfuncpubkeyself_error__please_use_generates     r/   __init__VerifyingKey.__init__h   s-    *D  
 $r.   c                     U R                  S5      nU R                  (       a  U R                  5       R                  nOSnSR                  XR                  U5      $ )N
compressedNonez+VerifyingKey.from_string({0!r}, {1!r}, {2}))	to_stringrF   r7   r6   r;   )rI   pub_key	hash_names      r/   __repr__VerifyingKey.__repr__r   sN    ...  --/44II<CCZZ
 	
r.   c                     [        U[        5      (       a9  U R                  UR                  :H  =(       a    U R                  UR                  :H  $ [        $ z9Return True if the points are identical, False otherwise.)
isinstancer"   r;   rG   NotImplementedrI   others     r/   __eq__VerifyingKey.__eq__|   s:    e\**::,L1LLr.   c                     X:X  + $ z9Return False if the points are identical, True otherwise.r&   rY   s     r/   __ne__VerifyingKey.__ne__         r.   Tc                    U " SS9n[        UR                  [        5      (       a  [        S5      e[        U[        R
                  5      (       d  [        R
                  R                  U5      nX%l        X5l         [        R                  " UR                  X5      Ul        UR                  UR                  l        U$ ! [        R                   a    [        S5      ef = f)a6  
Initialise the object from a Point object.

This is a low-level method, generally you will not want to use it.

:param point: The point to wrap around, the actual public key
:type point: ~ecdsa.ellipticcurve.AbstractPoint
:param curve: The curve on which the point needs to reside, defaults
    to NIST192p
:type curve: ~ecdsa.curves.Curve
:param hashfunc: The default hash function that will be used for
    verification, needs to implement the same interface
    as :py:class:`hashlib.sha1`
:type hashfunc: callable
:type bool validate_point: whether to check if the point lays on curve
    should always be used if the public point is not a result
    of our own calculation

:raises MalformedPointError: if the public point does not lay on the
    curve

:return: Initialised VerifyingKey object
:rtype: VerifyingKey
TrJ   z'Method incompatible with Edwards curveszPoint does not lay on the curve)rW   r;   r   
ValueErrorr   r   from_affinerF   r   
Public_key	generatorrG   InvalidPointErrorr   r8   )clspointr;   hashfuncvalidate_pointrI   s         r/   from_public_pointVerifyingKey.from_public_point   s    8 t4ekk9--FGG%!:!:;;!--99%@E
 (	I**DK
 "KK && 	I%&GHH	Is   <&B? ? CFc           
      X   [        U R                  R                  [        5      (       a  U R                  R                  n[
        R                  " UR                  5       UR                  5       UR                  5       SUR                  5       UR                  5       -  U R                  R                  SS9U R                  l        OC[
        R                  R                  U R                  R                  S5      U R                  l        U(       d  U R                  R                  S-    gg)a  
Precompute multiplication tables for faster signature verification.

Calling this method will cause the library to precompute the
scalar multiplication tables, used in signature verification.
While it's an expensive operation (comparable to performing
as many signatures as the bit size of the curve, i.e. 256 for NIST256p)
it speeds up verification 2 times. You should call this method
if you expect to verify hundreds of signatures (or more) using the same
VerifyingKey object.

Note: You should call this method only once, this method generates a
new precomputation table every time it's called.

:param bool lazy: whether to calculate the precomputation table now
   (if set to False) or if it should be delayed to the time of first
   use (when set to True)
r   T)rg      N)rW   r;   r   rG   rj   r   PointEdwardsxyr8   r   re   )rI   lazypts      r/   
precomputeVerifyingKey.precompute   s    & djj&&	22""B - : :


  !DKK !. 9 9 E E!!4!DKK KK! r.   c                 P   [        UR                  [        5      (       a<  U " SS9nX&l        SUl         [        R
                  " UR                  U5      Ul        U$ [        R                  " UR                  UUUS9nU R                  XrX45      $ ! [         a    [        S5      ef = f)a^  
Initialise the object from byte encoding of public key.

The method does accept and automatically detect the type of point
encoding used. It supports the :term:`raw encoding`,
:term:`uncompressed`, :term:`compressed`, and :term:`hybrid` encodings.
It also works with the native encoding of Ed25519 and Ed448 public
keys (technically those are compressed, but encoded differently than
in other signature systems).

Note, while the method is named "from_string" it's a misnomer from
Python 2 days when there were no binary strings. In Python 3 the
input needs to be a bytes-like object.

:param string: single point encoding of the public key
:type string: :term:`bytes-like object`
:param curve: the curve on which the public key is expected to lay
:type curve: ~ecdsa.curves.Curve
:param hashfunc: The default hash function that will be used for
    verification, needs to implement the same interface as
    hashlib.sha1. Ignored for EdDSA.
:type hashfunc: callable
:param validate_point: whether to verify that the point lays on the
    provided curve or not, defaults to True. Ignored for EdDSA.
:type validate_point: bool
:param valid_encodings: list of acceptable point encoding formats,
    supported ones are: :term:`uncompressed`, :term:`compressed`,
    :term:`hybrid`, and :term:`raw encoding` (specified with ``raw``
    name). All formats by default (specified with ``None``).
    Ignored for EdDSA.
:type valid_encodings: :term:`set-like object`

:raises MalformedPointError: if the public point does not lay on the
    curve or the encoding is invalid

:return: Initialised VerifyingKey object
:rtype: VerifyingKey
Trc   NzMalformed point for the curve)validate_encodingvalid_encodings)rW   r;   r   rF   r   	PublicKeyrg   rG   rd   r   r   
from_bytesrm   )ri   stringr;   rk   rl   rz   rI   rj   s           r/   from_stringVerifyingKey.from_string   s    ^ ekk9--48DJ$(D!K#ooeoovF K&&KK,+	
 $$U8LL  K)*IJJKs   &B B%c                 N    U R                  [        R                  " U5      UUUS9$ )a  
Initialise from public key stored in :term:`PEM` format.

The PEM header of the key should be ``BEGIN PUBLIC KEY``.

See the :func:`~VerifyingKey.from_der()` method for details of the
format supported.

Note: only a single PEM object decoding is supported in provided
string.

:param string: text with PEM-encoded public ECDSA key
:type string: str
:param valid_encodings: list of allowed point encodings.
    By default :term:`uncompressed`, :term:`compressed`, and
    :term:`hybrid`. To read malformed files, include
    :term:`raw encoding` with ``raw`` in the list.
:type valid_encodings: :term:`set-like object`
:param valid_curve_encodings: list of allowed encoding formats
    for curve parameters. By default (``None``) all are supported:
    ``named_curve`` and ``explicit``.
:type valid_curve_encodings: :term:`set-like object`


:return: Initialised VerifyingKey object
:rtype: VerifyingKey
)rk   rz   valid_curve_encodings)from_derr   unpem)ri   r}   rk   rz   r   s        r/   from_pemVerifyingKey.from_pem  s0    F ||IIf+"7	  
 	
r.   c                    Uc  [        / SQ5      n[        U5      n[        R                  " U5      u  pVUS:w  a-  [        R                  " S[
        R                  " U5      -  5      e[        R                  " U5      u  px[        R                  " U5      u  pU	[        R                  [        R                  4;   a  U	[        R                  :X  a  [        nOU	[        R                  :X  d   e[        n[        R                  " US5      u  pU(       a  [        R                  " S5      eU R                  XS5      $ U	[        :X  d%  [        R                  " SR                  U	5      5      e[        R                   " X5      n[        R                  " US5      u  pUS:w  a-  [        R                  " S[
        R                  " U5      -  5      e[#        U5      UR$                  :X  a  [        R                  " S	5      eU R                  UUUUS
9$ )a  
Initialise the key stored in :term:`DER` format.

The expected format of the key is the SubjectPublicKeyInfo structure
from RFC5912 (for RSA keys, it's known as the PKCS#1 format)::

   SubjectPublicKeyInfo {PUBLIC-KEY: IOSet} ::= SEQUENCE {
       algorithm        AlgorithmIdentifier {PUBLIC-KEY, {IOSet}},
       subjectPublicKey BIT STRING
   }

Note: only public EC keys are supported by this method. The
SubjectPublicKeyInfo.algorithm.algorithm field must specify
id-ecPublicKey (see RFC3279).

Only the named curve encoding is supported, thus the
SubjectPublicKeyInfo.algorithm.parameters field needs to be an
object identifier. A sequence in that field indicates an explicit
parameter curve encoding, this format is not supported. A NULL object
in that field indicates an "implicitlyCA" encoding, where the curve
parameters come from CA certificate, those, again, are not supported.

:param string: binary string with the DER encoding of public ECDSA key
:type string: bytes-like object
:param valid_encodings: list of allowed point encodings.
    By default :term:`uncompressed`, :term:`compressed`, and
    :term:`hybrid`. To read malformed files, include
    :term:`raw encoding` with ``raw`` in the list.
:type valid_encodings: :term:`set-like object`
:param valid_curve_encodings: list of allowed encoding formats
    for curve parameters. By default (``None``) all are supported:
    ``named_curve`` and ``explicit``.
:type valid_curve_encodings: :term:`set-like object`

:return: Initialised VerifyingKey object
:rtype: VerifyingKey
N)uncompressedrN   hybridr.   z"trailing junk after DER pubkey: %sr   ztrailing junk after public keyz3Unexpected object identifier in DER encoding: {0!r}z*trailing junk after pubkey pointstring: %sz"Malformed encoding of public point)rk   rz   )setr   r   remove_sequenceUnexpectedDERbinasciihexlifyremove_objectr   oidr   remove_bitstringr~   r   r6   r   r   r4   verifying_key_length)ri   r}   rk   rz   r   s1emptys2point_str_bitstringoid_pkrestr;   	point_strs                r/   r   VerifyingKey.from_derE  s   Z "!"JKO (''/	C<##4x7G7G7NN  #&"5"5b"9((,gkk599--$***"334GKI''(HII??9T::(##""(&.  t;//0CQG	C<##<""5)* 
 y>U777##$HII+	  
 	
r.   c           	          [        UR                  [        5      (       a  [        S5      e[	        U5      nU" U5      R                  5       nU R                  UUUUUUS9$ )a  
Return keys that can be used as verifiers of the provided signature.

Tries to recover the public key that can be used to verify the
signature, usually returns two keys like that.

:param signature: the byte string with the encoded signature
:type signature: bytes-like object
:param data: the data to be hashed for signature verification
:type data: bytes-like object
:param curve: the curve over which the signature was performed
:type curve: ~ecdsa.curves.Curve
:param hashfunc: The default hash function that will be used for
    verification, needs to implement the same interface as hashlib.sha1
:type hashfunc: callable
:param sigdecode: Callable to define the way the signature needs to
    be decoded to an object, needs to handle `signature` as the
    first parameter, the curve order (an int) as the second and return
    a tuple with two integers, "r" as the first one and "s" as the
    second one. See :func:`ecdsa.util.sigdecode_string` and
    :func:`ecdsa.util.sigdecode_der` for examples.
:param bool allow_truncate: if True, the provided hashfunc can generate
    values larger than the bit size of the order of the curve, the
    extra bits (at the end of the digest) will be truncated.
:type sigdecode: callable

:return: Initialised VerifyingKey objects
:rtype: list of VerifyingKey
%Method unsupported for Edwards curves)rk   	sigdecoder<   )rW   r;   r   rd   r   r:   $from_public_key_recovery_with_digest)ri   	signaturedatar;   rk   r   r<   r:   s           r/   from_public_key_recovery%VerifyingKey.from_public_key_recovery  sh    N ekk9--DEEt$$&&(77) 8 
 	
r.   c                 ~   [        UR                  [        5      (       a  [        S5      eUR                  nU" XR                  5       5      u  p[        R                  " X5      n
[        U5      n[        X#U5      nU
R                  X5      nU Vs/ s H  oR                  UR                  X45      PM      nnU$ s  snf )aE  
Return keys that can be used as verifiers of the provided signature.

Tries to recover the public key that can be used to verify the
signature, usually returns two keys like that.

:param signature: the byte string with the encoded signature
:type signature: bytes-like object
:param digest: the hash value of the message signed by the signature
:type digest: bytes-like object
:param curve: the curve over which the signature was performed
:type curve: ~ecdsa.curves.Curve
:param hashfunc: The default hash function that will be used for
    verification, needs to implement the same interface as hashlib.sha1
:type hashfunc: callable
:param sigdecode: Callable to define the way the signature needs to
    be decoded to an object, needs to handle `signature` as the
    first parameter, the curve order (an int) as the second and return
    a tuple with two integers, "r" as the first one and "s" as the
    second one. See :func:`ecdsa.util.sigdecode_string` and
    :func:`ecdsa.util.sigdecode_der` for examples.
:type sigdecode: callable
:param bool allow_truncate: if True, the provided hashfunc can generate
    values larger than the bit size of the order of the curve (and
    the length of provided `digest`), the extra bits (at the end of the
    digest) will be truncated.

:return: Initialised VerifyingKey object
:rtype: VerifyingKey
r   )rW   r;   r   rd   rg   r8   r   	Signaturer   r@   recover_public_keysrm   rj   )ri   r   r:   r;   rk   r   r<   rg   rssigdigest_as_numberpkspkverifying_keyss                  r/   r   1VerifyingKey.from_public_key_recovery_with_digest  s    P ekk9--DEEOO	OO$56ooa# (7>
 %%&6B HK
GJ!!"((E<s 	 
 
s   %B:c                 \    US;   d   eU R                   R                  R                  U5      $ )a  
Convert the public key to a byte string.

The method by default uses the :term:`raw encoding` (specified
by `encoding="raw"`. It can also output keys in :term:`uncompressed`,
:term:`compressed` and :term:`hybrid` formats.

Remember that the curve identification is not part of the encoding
so to decode the point using :func:`~VerifyingKey.from_string`, curve
needs to be specified.

Note: while the method is called "to_string", it's a misnomer from
Python 2 days when character strings and byte strings shared type.
On Python 3 the returned type will be `bytes`.

:return: :term:`raw encoding` of the public key (public point) on the
    curve
:rtype: bytes
)rawr   rN   r   )rG   rj   to_bytes)rI   encodings     r/   rP   VerifyingKey.to_string  s.    ( JJJJ{{  ))(33r.   c                 N    [         R                  " U R                  X5      S5      $ )aq  
Convert the public key to the :term:`PEM` format.

The PEM header of the key will be ``BEGIN PUBLIC KEY``.

The format of the key is described in the
:func:`~VerifyingKey.from_der()` method.
This method supports only "named curve" encoding of keys.

:param str point_encoding: specification of the encoding format
    of public keys. "uncompressed" is most portable, "compressed" is
    smallest. "hybrid" is uncommon and unsupported by most
    implementations, it is as big as "uncompressed".
:param str curve_parameters_encoding: the encoding for curve parameters
    to use, by default tries to use ``named_curve`` encoding,
    if that is not possible, falls back to ``explicit`` encoding.

:return: portable encoding of the public key
:rtype: bytes

.. warning:: The PEM is encoded to US-ASCII, it needs to be
    re-encoded if the system is incompatible (e.g. uses UTF-16)
z
PUBLIC KEYr   topemto_der)rI   point_encodingcurve_parameters_encodings      r/   to_pemVerifyingKey.to_pem#  s$    4 yyKKB
 	
r.   c           	      0   US:X  a  [        S5      eU R                  U5      n[        U R                  R                  [        5      (       an  [
        R                  " [
        R                  " [
        R                  " U R                  R                  6 5      [
        R                  " [        U5      S5      5      $ [
        R                  " [
        R                  " [        U R                  R                  X!5      5      [
        R                  " US5      5      $ )a  
Convert the public key to the :term:`DER` format.

The format of the key is described in the
:func:`~VerifyingKey.from_der()` method.
This method supports only "named curve" encoding of keys.

:param str point_encoding: specification of the encoding format
    of public keys. "uncompressed" is most portable, "compressed" is
    smallest. "hybrid" is uncommon and unsupported by most
    implementations, it is as big as "uncompressed".
:param str curve_parameters_encoding: the encoding for curve parameters
    to use, by default tries to use ``named_curve`` encoding,
    if that is not possible, falls back to ``explicit`` encoding.

:return: DER encoding of the public key
:rtype: bytes
r   z%raw point_encoding not allowed in DERr   )rd   rP   rW   r;   r   r   encode_sequence
encode_oidr   encode_bitstringbytesr   r   )rI   r   r   r   s       r/   r   VerifyingKey.to_derB  s    * U"DEENN>2	djj&&	22&&##CNNDJJNN$CD$$U9%5q9  ""'

!!";L   A.
 	
r.   c                 t    [         R                  " U R                  R                  U R	                  5       5      $ )zb
Convert the public key to the SSH format.

:return: SSH encoding of the public key
:rtype: bytes
)r	   serialize_publicr;   r7   rP   rI   s    r/   to_sshVerifyingKey.to_sshi  s,     ##JJOONN
 	
r.   c                 z   [        U5      n[        U R                  R                  [        5      (       a'  [        U5      n U R                  R                  X!5      $ U=(       d    U R                  nU" U5      R                  5       nU R                  XXE5      $ ! [        [        4 a  n[        SU5      eSnAff = f)a  
Verify a signature made over provided data.

Will hash `data` to verify the signature.

By default expects signature in :term:`raw encoding`. Can also be used
to verify signatures in ASN.1 DER encoding by using
:func:`ecdsa.util.sigdecode_der`
as the `sigdecode` parameter.

:param signature: encoding of the signature
:type signature: sigdecode method dependent
:param data: data signed by the `signature`, will be hashed using
    `hashfunc`, if specified, or default hash function
:type data: :term:`bytes-like object`
:param hashfunc: The default hash function that will be used for
    verification, needs to implement the same interface as hashlib.sha1
:type hashfunc: callable
:param sigdecode: Callable to define the way the signature needs to
    be decoded to an object, needs to handle `signature` as the
    first parameter, the curve order (an int) as the second and return
    a tuple with two integers, "r" as the first one and "s" as the
    second one. See :func:`ecdsa.util.sigdecode_string` and
    :func:`ecdsa.util.sigdecode_der` for examples.
:type sigdecode: callable
:param bool allow_truncate: if True, the provided digest can have
    bigger bit-size than the order of the curve, the extra bits (at
    the end of the digest) will be truncated. Use it when verifying
    SHA-384 output using NIST256p or in similar situations. Defaults to
    True.

:raises BadSignatureError: if the signature is invalid or malformed

:return: True if the verification was successful
:rtype: bool
Signature verification failedN)r   rW   r;   r   rG   verifyrd   r   r    rF   r:   verify_digest)rI   r   r   rk   r   r<   er:   s           r/   r   VerifyingKey.verifyu  s    \ t$djj&&	22'	2IL{{))$:: 4t44$&&(!!)YOO  34 L'(GKKLs   B B:)B55B:c                 d   [        U5      n[        UU R                  U5      n U" XR                  R                  5      u  pg[        R                  " Xg5      n	U R                  R                  XY5      (       a  g[        S5      e! [
        R                  [        4 a  n[        SU5      eSnAff = f)a]  
Verify a signature made over provided hash value.

By default expects signature in :term:`raw encoding`. Can also be used
to verify signatures in ASN.1 DER encoding by using
:func:`ecdsa.util.sigdecode_der`
as the `sigdecode` parameter.

:param signature: encoding of the signature
:type signature: sigdecode method dependent
:param digest: raw hash value that the signature authenticates.
:type digest: :term:`bytes-like object`
:param sigdecode: Callable to define the way the signature needs to
    be decoded to an object, needs to handle `signature` as the
    first parameter, the curve order (an int) as the second and return
    a tuple with two integers, "r" as the first one and "s" as the
    second one. See :func:`ecdsa.util.sigdecode_string` and
    :func:`ecdsa.util.sigdecode_der` for examples.
:type sigdecode: callable
:param bool allow_truncate: if True, the provided digest can have
    bigger bit-size than the order of the curve, the extra bits (at
    the end of the digest) will be truncated. Use it when verifying
    SHA-384 output using NIST256p or in similar situations.

:raises BadSignatureError: if the signature is invalid or malformed
:raises BadDigestError: if the provided digest is too big for the curve
    associated with this VerifyingKey and allow_truncate was not set

:return: True if the verification was successful
:rtype: bool
z!Malformed formatting of signatureNTr   )r   r@   r;   rG   r8   r   r   r   r    r   r   verifies)
rI   r   r:   r   r<   r=   r   r   r   r   s
             r/   r   VerifyingKey.verify_digest  s    P !(-JJ
	LY(9(9:DA ooa#;;,, ?@@ !!#56 	L#$GKK	Ls   B B/B**B/)r;   rF   rG   N)F)r   )r   N)r(   r)   r*   r+   r,   rK   rS   r[   r_   classmethodr   r   rm   rv   r~   r   r   r   r   r   rP   r   r   r   r   r   r-   r&   r.   r/   r"   r"   [   s(   

! "T$) )V&"P  >M >M@  "'
 '
R  "V
 V
p  "1
 1
f  "7 7r40 HL
@ HL%
N

  "8P| #6Ar.   r"   c                   R   \ rS rSrSrSS jrS rS r\S 5       r	\S 5       r
\\S\4S	 j5       r\\\4S
 j5       r\\\4S j5       r\\S4S j5       r\\S4S j5       rS r   SS jrS r   SS jrS rS rS\S4S jrS\SS4S jrSS\SS4S jrS\SS4S jrSS jrSrg) r#   i  a)  
Class for handling keys that can create signatures (private keys).

:ivar `~ecdsa.curves.Curve` curve: The Curve over which all the
    cryptographic operations will take place
:ivar default_hashfunc: the function that will be used for hashing the
    data. Should implement the same API as :py:class:`hashlib.sha1`
:ivar int baselen: the length of a :term:`raw encoding` of private key
:ivar `~ecdsa.keys.VerifyingKey` verifying_key: the public key
    associated with this private key
:ivar `~ecdsa.ecdsa.Private_key` privkey: the actual private key
Nc                 n    U(       d  [        S5      eSU l        SU l        SU l        SU l        SU l        g)rD   z0Please use SigningKey.generate() to construct meN)rE   r;   rF   r5   verifying_keyprivkeyrH   s     r/   rK   SigningKey.__init__  s6    *NOO
 $!r.   c                     [        U[        5      (       aY  U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ [
        $ rV   )rW   r#   r;   r   r   rX   rY   s     r/   r[   SigningKey.__eq__   sZ    eZ((

ekk) 2&&%*=*==2LLEMM1
 r.   c                     X:X  + $ r^   r&   rY   s     r/   r_   SigningKey.__ne__
  ra   r.   c                 b   U(       d  [         R                  nU" UR                  5      n[        R                  " UR
                  U5      nUR                  5       n[        R                  UR                  5       U5      nU " SS9nXl	        SUl
        UR                  Ul        XGl        Xgl        U$ )z2Generate a private key on a Twisted Edwards curve.Trc   N)osurandomr5   r   
PrivateKeyrg   
public_keyr"   r~   r;   rF   r   r   )ri   r;   entropyrandomprivate_keyr   r   rI   s           r/   _twisted_edwards_keygen"SigningKey._twisted_edwards_keygen  s     jjG'&&u? ++-
$00!!#U
 t4
 $}}"*r.   c                 R    [        UR                  U5      nU R                  XAU5      $ )z.Generate a private key on a Weierstrass curve.)r   r8   from_secret_exponent)ri   r;   r   rk   secexps        r/   _weierstrass_keygenSigningKey._weierstrass_keygen#  s'     5;;0''x@@r.   c                     [        UR                  [        5      (       a  U R                  X5      $ U R	                  XU5      $ )aM  
Generate a random private key.

:param curve: The curve on which the point needs to reside, defaults
    to NIST192p
:type curve: ~ecdsa.curves.Curve
:param entropy: Source of randomness for generating the private keys,
    should provide cryptographically secure random numbers if the keys
    need to be secure. Uses os.urandom() by default.
:type entropy: callable
:param hashfunc: The default hash function that will be used for
    signing, needs to implement the same interface
    as hashlib.sha1
:type hashfunc: callable

:return: Initialised SigningKey object
:rtype: SigningKey
)rW   r;   r   r   r   )ri   r;   r   rk   s       r/   generateSigningKey.generate)  s9    ( ekk9--..u>>&&ux@@r.   c                 $   [        UR                  [        5      (       a  [        S5      eU " SS9nX$l        X4l        UR
                  Ul        UR                  nSUs=::  a  U:  d  O  [        SR                  U5      5      eUR                  U-  n[        US5      (       a  UR                  5       n[        R                  XbUS5      Ul        UR                  R                  n[         R"                  " Xq5      Ul        XTR$                  l        U$ )a  
Create a private key from a random integer.

Note: it's a low level method, it's recommended to use the
:func:`~SigningKey.generate` method to create private keys.

:param int secexp: secret multiplier (the actual private key in ECDSA).
    Needs to be an integer between 1 and the curve order.
:param curve: The curve on which the point needs to reside
:type curve: ~ecdsa.curves.Curve
:param hashfunc: The default hash function that will be used for
    signing, needs to implement the same interface
    as hashlib.sha1
:type hashfunc: callable

:raises MalformedPointError: when the provided secexp is too large
    or too small for the curve selected
:raises RuntimeError: if the generation of public key from private
    key failed

:return: Initialised SigningKey object
:rtype: SigningKey
zHEdwards keys don't support setting the secret scalar (exponent) directlyTrc   r   z<Invalid value for secexp, expected integer between 1 and {0}scaleF)rW   r;   r   rd   rF   r5   r8   r   r6   rg   hasattrr   r"   rm   r   rG   r   Private_keyr   )ri   r   r;   rk   rI   npubkey_pointrG   s           r/   r   SigningKey.from_secret_exponentA  s    2 ekk9--&  t4
 (}}KKFQ%$$*F1I  /<))'--/L);;5
 ##**((8r.   c                 8   [        U5      n[        U5      UR                  :w  a.  [        SR	                  [        U5      UR                  5      5      e[        UR                  [        5      (       a  U " SS9nX$l        SUl        UR                  Ul        [        R                  " UR                  U5      Ul        [        R                  UR                  R                  5       R                  5       U5      Ul        U$ [#        U5      nU R%                  XRU5      $ )aH  
Decode the private key from :term:`raw encoding`.

Note: the name of this method is a misnomer coming from days of
Python 2, when binary strings and character strings shared a type.
In Python 3, the expected type is `bytes`.

:param string: the raw encoding of the private key
:type string: :term:`bytes-like object`
:param curve: The curve on which the point needs to reside
:type curve: ~ecdsa.curves.Curve
:param hashfunc: The default hash function that will be used for
    signing, needs to implement the same interface
    as hashlib.sha1
:type hashfunc: callable

:raises MalformedPointError: if the length of encoding doesn't match
    the provided curve or the encoded values is too large
:raises RuntimeError: if the generation of public key from private
    key failed

:return: Initialised SigningKey object
:rtype: SigningKey
z9Invalid length of private key, received {0}, expected {1}Trc   N)r   r4   r5   r   r6   rW   r;   r   rF   r   r   rg   r   r"   r~   r   r   r   r   )ri   r}   r;   rk   rI   r   s         r/   r~   SigningKey.from_stringt  s    4 !(v;%--'%%vc&k5==A  ekk9--48DJ$(D! ==DL ++EOOVDDL!-!9!9'')446"D K!&)''x@@r.   c                    [         (       d%  [        U[        5      (       a  UR                  5       nUR	                  S5      nUS:X  a  UR                  S5      nU R                  [        R                  " XS 5      UU5      $ )a  
Initialise from key stored in :term:`PEM` format.

The PEM formats supported are the un-encrypted RFC5915
(the ssleay format) supported by OpenSSL, and the more common
un-encrypted RFC5958 (the PKCS #8 format).

The legacy format files have the header with the string
``BEGIN EC PRIVATE KEY``.
PKCS#8 files have the header ``BEGIN PRIVATE KEY``.
Encrypted files (ones that include the string
``Proc-Type: 4,ENCRYPTED``
right after the PEM header) are not supported.

See :func:`~SigningKey.from_der` for ASN.1 syntax of the objects in
this files.

:param string: text with PEM-encoded private ECDSA key
:type string: str
:param valid_curve_encodings: list of allowed encoding formats
    for curve parameters. By default (``None``) all are supported:
    ``named_curve`` and ``explicit``.
:type valid_curve_encodings: :term:`set-like object`


:raises MalformedPointError: if the length of encoding doesn't match
    the provided curve or the encoded values is too large
:raises RuntimeError: if the generation of public key from private
    key failed
:raises UnexpectedDER: if the encoding of the PEM file is incorrect

:return: Initialised SigningKey object
:rtype: SigningKey
s   -----BEGIN EC PRIVATE KEY-----s   -----BEGIN PRIVATE KEY-----N)	r   rW   strencodefindindexr   r   r   )ri   r}   rk   r   private_key_indexs        r/   r   SigningKey.from_pem  st    H sz&#..]]_F
 #KK(IJ" &-K L||IIf/01!
 	
r.   c                    [        U5      nSn[        R                  " U5      u  pFUS:w  a-  [        R                  " S[        R
                  " U5      -  5      e[        R                  " U5      u  pt[        R                  " U5      (       Ga  US;  a  [        R                  " SU-  5      e[        R                  " U5      u  p[        R                  " U5      u  pU	[        R                  [        R                  4;   a  U
(       a  [        R                  " S5      e[        R                  " U5      u  p[        R                  " U5      u  pU(       a  [        R                  " S5      eU	[        R                  :X  a  [        nOU	[        R                  :X  d   e[        nU R                  XS5      $ U	[        [        [         4;  a  [        R                  " SU	< S	35      e["        R$                  " X5      n[        R                  " U5      u  pM[        R                  " U5      u  pFUS:w  a-  [        R                  " S[        R
                  " U5      -  5      e[        R                  " U5      u  ptUS
:w  a  [        R                  " SU-  5      e[        R                  " U5      u  pU(       dP  [        R&                  " U5      u  nnnUS:w  a  [        R                  " SU-  5      e["        R$                  " UU5      n[)        U5      UR*                  :  a  SUR*                  [)        U5      -
  -  U-   nU R                  XU5      $ )am  
Initialise from key stored in :term:`DER` format.

The DER formats supported are the un-encrypted RFC5915
(the ssleay format) supported by OpenSSL, and the more common
un-encrypted RFC5958 (the PKCS #8 format).

Both formats contain an ASN.1 object following the syntax specified
in RFC5915::

    ECPrivateKey ::= SEQUENCE {
      version        INTEGER { ecPrivkeyVer1(1) }} (ecPrivkeyVer1),
      privateKey     OCTET STRING,
      parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
      publicKey  [1] BIT STRING OPTIONAL
    }

`publicKey` field is ignored completely (errors, if any, in it will
be undetected).

Two formats are supported for the `parameters` field: the named
curve and the explicit encoding of curve parameters.
In the legacy ssleay format, this implementation requires the optional
`parameters` field to get the curve name. In PKCS #8 format, the curve
is part of the PrivateKeyAlgorithmIdentifier.

The PKCS #8 format includes an ECPrivateKey object as the `privateKey`
field within a larger structure::

    OneAsymmetricKey ::= SEQUENCE {
        version                   Version,
        privateKeyAlgorithm       PrivateKeyAlgorithmIdentifier,
        privateKey                PrivateKey,
        attributes            [0] Attributes OPTIONAL,
        ...,
        [[2: publicKey        [1] PublicKey OPTIONAL ]],
        ...
    }

The `attributes` and `publicKey` fields are completely ignored; errors
in them will not be detected.

:param string: binary string with DER-encoded private ECDSA key
:type string: :term:`bytes-like object`
:param valid_curve_encodings: list of allowed encoding formats
    for curve parameters. By default (``None``) all are supported:
    ``named_curve`` and ``explicit``.
    Ignored for EdDSA.
:type valid_curve_encodings: :term:`set-like object`

:raises MalformedPointError: if the length of encoding doesn't match
    the provided curve or the encoded values is too large
:raises RuntimeError: if the generation of public key from private
    key failed
:raises UnexpectedDER: if the encoding of the DER file is incorrect

:return: Initialised SigningKey object
:rtype: SigningKey
Nr.   z#trailing junk after DER privkey: %s)r   r   z7expected version '0' or '1' at start of privkey, got %dz#Non NULL parameters for a EdDSA keyz+trailing junk after the encoded private keyz!unexpected algorithm identifier ''r   z4expected version '1' at start of DER privkey, got %dr   z%expected tag 0 in DER privkey, got %d    )r   r   r   r   r   r   remove_integeris_sequencer   r   r   r   remove_octet_stringr~   r   r   r   r   r   remove_constructedr4   r5   )ri   r}   rk   r   r   r;   r   versionsequencealgorithm_oidalgorithm_identifierkey_str_derkey_str_privkey_strtagcurve_oid_strs                    r/   r   SigningKey.from_der  s   z F#&&q)C<##58H8H8OO  ''*
 ??1f$''M 
 --a0KH252C2CH2M/Meii 88'++=  "%!8!8!; !44[A
++E  !GKK/#E(EII555!Ewt<<_h	$JJ''>KM  NN#7OE **1-DA **1-HA|''9&&u-. 
 ++A.JG a<##F 
 003$'$:$:1$=!Cax'';cA  NN=2GHE {emm+5==3{+;;<{J  {8<<r.   c                     [        U R                  R                  [        5      (       a  [        U R                  R
                  5      $ U R                  R                  n[        XR                  R                  5      nU$ )a  
Convert the private key to :term:`raw encoding`.

Note: while the method is named "to_string", its name comes from
Python 2 days, when binary and character strings used the same type.
The type used in Python 3 is `bytes`.

:return: raw encoding of private key
:rtype: bytes
)	rW   r;   r   r   r   r   secret_multiplierr   r8   )rI   r   r   s      r/   rP   SigningKey.to_string  sX     djj&&	221122//V\\%7%78r.   c                 t    US;   d   eUS:X  a  SOSn[         R                  " U R                  XU5      U5      $ )a  
Convert the private key to the :term:`PEM` format.

See :func:`~SigningKey.from_pem` method for format description.

Only the named curve format is supported.
The public key will be included in generated string.

The PEM header will specify ``BEGIN EC PRIVATE KEY`` or
``BEGIN PRIVATE KEY``, depending on the desired format.

:param str point_encoding: format to use for encoding public point
:param str format: either ``ssleay`` (default) or ``pkcs8``
:param str curve_parameters_encoding: format of encoded curve
    parameters, default depends on the curve, if the curve has
    an associated OID, ``named_curve`` format will be used,
    if no OID is associated with the curve, the fallback of
    ``explicit`` parameters will be used.

:return: PEM encoded private key
:rtype: bytes

.. warning:: The PEM is encoded to US-ASCII, it needs to be
    re-encoded if the system is incompatible (e.g. uses UTF-16)
ssleaypkcs8r  zEC PRIVATE KEYzPRIVATE KEYr   )rI   r   r6   r   headers        r/   r   SigningKey.to_pem  sF    @ ,,,,%+x%7!]yyKK0IJ
 	
r.   c                 <   [         R                  " U R                  5       5      n[         R                  " [         R                  " S5      [         R                  " [         R
                  " U R                  R                  6 5      [         R                  " U5      5      $ )z'Create a PKCS#8 encoding of EdDSA keys.r   )r   encode_octet_stringrP   r   encode_integerr   r;   r   )rI   ec_private_keys     r/   _encode_eddsaSigningKey._encode_eddsa  sg    001AB""q!

 ?@##N3
 	
r.   c           	         US:X  a  [        S5      eUS;   d   e[        U R                  R                  [        5      (       a!  US:w  a  [        S5      eU R	                  5       $ U R                  5       R                  U5      n[        R                  " S5      [        R                  " U R                  5       5      /nUS:X  a?  UR                  [        R                  " SU R                  R                  U5      5      5        UR                  [        R                  " S[        R                  " US5      5      5        [        R                  " U6 nUS:X  a  U$ [        R                  " [        R                  " S5      [        R                  " [        R                  " [         6 U R                  R                  U5      5      [        R                  " U5      5      $ )	a  
Convert the private key to the :term:`DER` format.

See :func:`~SigningKey.from_der` method for format specification.

Only the named curve format is supported.
The public key will be included in the generated string.

:param str point_encoding: format to use for encoding public point
    Ignored for EdDSA
:param str format: either ``ssleay`` (default) or ``pkcs8``.
    EdDSA keys require ``pkcs8``.
:param str curve_parameters_encoding: format of encoded curve
    parameters, default depends on the curve, if the curve has
    an associated OID, ``named_curve`` format will be used,
    if no OID is associated with the curve, the fallback of
    ``explicit`` parameters will be used.
    Ignored for EdDSA.

:return: DER encoded private key
:rtype: bytes
r   zraw encoding not allowed in DERr  r  z+Only PKCS#8 format supported for EdDSA keysr   r  r   )rd   rW   r;   r   r  get_verifying_keyrP   r   r  r  appendencode_constructedr   r   r   r   r   )rI   r   r6   r   
encoded_vkpriv_key_elemsr  s          r/   r   SigningKey.to_der  s   < U">??,,,,djj&&	22  !NOO%%''++-77G
q!##DNN$45
 X!!&&tzz(()BC 	""1c&:&::q&IJ	
 ,,n=X!!&& ""1%##NNO4JJ%%&?@ ''7	 	r.   c                     [         R                  " U R                  R                  U R                  R                  5       U R                  5       5      $ )z\
Convert the private key to the SSH format.

:return: SSH encoded private key
:rtype: bytes
)r	   serialize_privater;   r7   r   rP   r   s    r/   r   SigningKey.to_ssh
  s>     $$JJOO((*NN
 	
r.   c                     U R                   $ )z
Return the VerifyingKey associated with this private key.

Equivalent to reading the `verifying_key` field of an instance.

:return: a public key that can be used to verify the signatures made
    with this SigningKey
:rtype: VerifyingKey
)r   r   s    r/   r  SigningKey.get_verifying_key  s     !!!r.   r.   c                 2   U=(       d    U R                   n[        U5      n[        U R                  R                  [        5      (       a  U R
                  R                  U5      $ [        U5      nU" U5      R                  5       nU R                  UUUUSS9$ )a=  
Create signature over data.

For Weierstrass curves it uses the deterministic RFC6979 algorithm.
For Edwards curves it uses the standard EdDSA algorithm.

For ECDSA the data will be hashed using the `hashfunc` function before
signing.
For EdDSA the data will be hashed with the hash associated with the
curve (SHA-512 for Ed25519 and SHAKE-256 for Ed448).

This is the recommended method for performing signatures when hashing
of data is necessary.

:param data: data to be hashed and computed signature over
:type data: :term:`bytes-like object`
:param hashfunc: hash function to use for computing the signature,
    if unspecified, the default hash function selected during
    object initialisation will be used (see
    `VerifyingKey.default_hashfunc`). The object needs to implement
    the same interface as hashlib.sha1.
    Ignored with EdDSA.
:type hashfunc: callable
:param sigencode: function used to encode the signature.
    The function needs to accept three parameters: the two integers
    that are the signature and the order of the curve over which the
    signature was computed. It needs to return an encoded signature.
    See `ecdsa.util.sigencode_string` and `ecdsa.util.sigencode_der`
    as examples of such functions.
    Ignored with EdDSA.
:type sigencode: callable
:param extra_entropy: additional data that will be fed into the random
    number generator used in the RFC6979 process. Entirely optional.
    Ignored with EdDSA.
:type extra_entropy: :term:`bytes-like object`

:return: encoded signature over `data`
:rtype: bytes or sigencode function dependent type
T)rk   	sigencodeextra_entropyr<   )	rF   r   rW   r;   r   r   signr:   sign_digest_deterministic)rI   r   rk   r*  r+  r:   s         r/   sign_deterministicSigningKey.sign_deterministic#  s    \ 4t44t$djj&&	22<<$$T**'6$&&(--' . 
 	
r.   Fc           	         [        U R                  R                  [        5      (       a  [        S5      eU R                  R
                  nU=(       d    U R                  n[        U5      n[        U5      nS nSn [        R                  " U R                  R                  R                  5       UUUUUS9n	 U R                  UUU	US9u  pn U" XU5      $ ! [         a    US-  n Of = fMr  )a  
Create signature for digest using the deterministic RFC6979 algorithm.

`digest` should be the output of cryptographically secure hash function
like SHA256 or SHA-3-256.

This is the recommended method for performing signatures when no
hashing of data is necessary.

:param digest: hash of data that will be signed
:type digest: :term:`bytes-like object`
:param hashfunc: hash function to use for computing the random "k"
    value from RFC6979 process,
    if unspecified, the default hash function selected during
    object initialisation will be used (see
    :attr:`.VerifyingKey.default_hashfunc`). The object needs to
    implement
    the same interface as :func:`~hashlib.sha1` from :py:mod:`hashlib`.
:type hashfunc: callable
:param sigencode: function used to encode the signature.
    The function needs to accept three parameters: the two integers
    that are the signature and the order of the curve over which the
    signature was computed. It needs to return an encoded signature.
    See :func:`~ecdsa.util.sigencode_string` and
    :func:`~ecdsa.util.sigencode_der`
    as examples of such functions.
:type sigencode: callable
:param extra_entropy: additional data that will be fed into the random
    number generator used in the RFC6979 process. Entirely optional.
:type extra_entropy: :term:`bytes-like object`
:param bool allow_truncate: if True, the provided digest can have
    bigger bit-size than the order of the curve, the extra bits (at
    the end of the digest) will be truncated. Use it when signing
    SHA-384 output using NIST256p or in similar situations.

:return: encoded signature for the `digest` hash
:rtype: bytes or sigencode function dependent type
r   c                 
    XU4$ r   r&   )r   r   r8   s      r/   
simple_r_s8SigningKey.sign_digest_deterministic.<locals>.simple_r_s  s    ;r.   r   )	retry_genr+  )r*  kr<   r   )rW   r;   r   rd   r   r  rF   r   r
   
generate_krg   r8   sign_digestr   )rI   r:   rk   r*  r+  r<   r   r2  r4  r5  r   r   r8   s                r/   r-  $SigningKey.sign_digest_deterministicb  s    \ djj&&	22DEE//4t44 ('6	 	""

$$**,#+A	"..(#1	 / e  u%%  Q	# s   8C C)(C)Tc                    U=(       d    U R                   n[        U5      n[        U R                  R                  [        5      (       a  U R                  U5      $ U" U5      R                  5       nU R                  XrXEU5      $ )aX  
Create signature over data.

Uses the probabilistic ECDSA algorithm for Weierstrass curves
(NIST256p, etc.) and the deterministic EdDSA algorithm for the
Edwards curves (Ed25519, Ed448).

This method uses the standard ECDSA algorithm that requires a
cryptographically secure random number generator.

It's recommended to use the :func:`~SigningKey.sign_deterministic`
method instead of this one.

:param data: data that will be hashed for signing
:type data: :term:`bytes-like object`
:param callable entropy: randomness source, :func:`os.urandom` by
    default. Ignored with EdDSA.
:param hashfunc: hash function to use for hashing the provided
    ``data``.
    If unspecified the default hash function selected during
    object initialisation will be used (see
    :attr:`.VerifyingKey.default_hashfunc`).
    Should behave like :func:`~hashlib.sha1` from :py:mod:`hashlib`.
    The output length of the
    hash (in bytes) must not be longer than the length of the curve
    order (rounded up to the nearest byte), so using SHA256 with
    NIST256p is ok, but SHA256 with NIST192p is not. (In the 2**-96ish
    unlikely event of a hash output larger than the curve order, the
    hash will effectively be wrapped mod n).
    If you want to explicitly allow use of large hashes with small
    curves set the ``allow_truncate`` to ``True``.
    Use ``hashfunc=hashlib.sha1`` to match openssl's
    ``-ecdsa-with-SHA1`` mode,
    or ``hashfunc=hashlib.sha256`` for openssl-1.0.0's
    ``-ecdsa-with-SHA256``.
    Ignored for EdDSA
:type hashfunc: callable
:param sigencode: function used to encode the signature.
    The function needs to accept three parameters: the two integers
    that are the signature and the order of the curve over which the
    signature was computed. It needs to return an encoded signature.
    See :func:`~ecdsa.util.sigencode_string` and
    :func:`~ecdsa.util.sigencode_der`
    as examples of such functions.
    Ignored for EdDSA
:type sigencode: callable
:param int k: a pre-selected nonce for calculating the signature.
    In typical use cases, it should be set to None (the default) to
    allow its generation from an entropy source.
    Ignored for EdDSA.
:param bool allow_truncate: if ``True``, the provided digest can have
    bigger bit-size than the order of the curve, the extra bits (at
    the end of the digest) will be truncated. Use it when signing
    SHA-384 output using NIST256p or in similar situations. True by
    default.
    Ignored for EdDSA.

:raises RSZeroError: in the unlikely event when *r* parameter or
    *s* parameter of the created signature is equal 0, as that would
    leak the key. Caller should try a better entropy source, retry with
    different ``k``, or use the
    :func:`~SigningKey.sign_deterministic` in such case.

:return: encoded signature of the hash of `data`
:rtype: bytes or sigencode function dependent type
)rF   r   rW   r;   r   r.  r:   r7  )rI   r   r   rk   r*  r5  r<   hs           r/   r,  SigningKey.sign  sn    V 4t44t$djj&&	22**400TN!!#I.IIr.   c                    [        U R                  R                  [        5      (       a  [        S5      e[	        U5      n[        UU R                  U5      nU R                  XbU5      u  pxU" XxU R                  R                  5      $ )a  
Create signature over digest using the probabilistic ECDSA algorithm.

This method uses the standard ECDSA algorithm that requires a
cryptographically secure random number generator.

This method does not hash the input.

It's recommended to use the
:func:`~SigningKey.sign_digest_deterministic` method
instead of this one.

:param digest: hash value that will be signed
:type digest: :term:`bytes-like object`
:param callable entropy: randomness source, os.urandom by default
:param sigencode: function used to encode the signature.
    The function needs to accept three parameters: the two integers
    that are the signature and the order of the curve over which the
    signature was computed. It needs to return an encoded signature.
    See `ecdsa.util.sigencode_string` and `ecdsa.util.sigencode_der`
    as examples of such functions.
:type sigencode: callable
:param int k: a pre-selected nonce for calculating the signature.
    In typical use cases, it should be set to None (the default) to
    allow its generation from an entropy source.
:param bool allow_truncate: if True, the provided digest can have
    bigger bit-size than the order of the curve, the extra bits (at
    the end of the digest) will be truncated. Use it when signing
    SHA-384 output using NIST256p or in similar situations.

:raises RSZeroError: in the unlikely event when "r" parameter or
    "s" parameter of the created signature is equal 0, as that would
    leak the key. Caller should try a better entropy source, retry with
    different 'k', or use the
    :func:`~SigningKey.sign_digest_deterministic` in such case.

:return: encoded signature for the `digest` hash
:rtype: bytes or sigencode function dependent type
r   )	rW   r;   r   rd   r   r@   sign_numberr   r8   )	rI   r:   r   r*  r5  r<   r=   r   r   s	            r/   r7  SigningKey.sign_digest  sv    ^ djj&&	22DEE (-JJ

 3t||1122r.   c                 B   [        U R                  R                  [        5      (       a  [        S5      eU R                  R
                  nUb  UnO[        XB5      nSUs=::  a  U:  d   e   eU R                  R                  X5      nUR                  UR                  4$ )a;  
Sign an integer directly.

Note, this is a low level method, usually you will want to use
:func:`~SigningKey.sign_deterministic` or
:func:`~SigningKey.sign_digest_deterministic`.

:param int number: number to sign using the probabilistic ECDSA
    algorithm.
:param callable entropy: entropy source, os.urandom by default
:param int k: pre-selected nonce for signature operation. If unset
    it will be selected at random using the entropy source.

:raises RSZeroError: in the unlikely event when "r" parameter or
    "s" parameter of the created signature is equal 0, as that would
    leak the key. Caller should try a better entropy source, retry with
    different 'k', or use the
    :func:`~SigningKey.sign_digest_deterministic` in such case.

:return: the "r" and "s" parameters of the signature
:rtype: tuple of ints
r   r   )
rW   r;   r   rd   r   r8   r   r,  r   r   )rI   r=   r   r5  r8   _kr   s          r/   r=  SigningKey.sign_number=  s    . djj&&	22DEE""=B5*BBll+uucee|r.   )r5   r;   rF   r   r   r   )r   r  N)NN)r(   r)   r*   r+   r,   rK   r[   r_   r   r   r   r   r   r   r   r~   r   r   rP   r   r  r   r   r  r   r.  r-  r,  r7  r=  r-   r&   r.   r/   r#   r#     sX   !  ( A A
 $dT A A. 084 0 0d '/$ +A +AZ '+4 1
 1
f '+4 k= k=Z& &"&	%
N
 &"&	CJ

" "=
D "M&d "
PJj "
83t"r.   r#   ).r,   r   hashlibr   r   sixr    r   r   r   r	   r
   r   curvesr   r   r   r   r   utilr   r   r   r   r   r   r   r   r   r   r   _compatr   errorsr   r   r   __all__	Exceptionr    r!   r@   objectr"   r#   r&   r.   r/   <module>rL     s      	      3 3  ? ? @ @  % ' 1		 		Y 	@J
A6 J
AZw wr.   