
     f%                        d dl mZ d dlmZ d dlZd dlZd dlZddl	m
Z
 ddl	mZ ddl	mZ ddl	mZ ddlmZ  G d	 d
          Z G d de          ZdddZ G d de          ZddZ G d d          ZdS )    )annotationsN   )_base64_alphabet)base64_decode)base64_encode
want_bytes)BadSignaturec                  "    e Zd ZdZddZdd	Zd
S )SigningAlgorithmzgSubclasses must implement :meth:`get_signature` to provide
    signature generation functionality.
    keybytesvaluereturnc                    t                      )z2Returns the signature for the given key and value.)NotImplementedErrorselfr   r   s      V/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/itsdangerous/signer.pyget_signaturezSigningAlgorithm.get_signature   s    !###    sigboolc                T    t          j        ||                     ||                    S )zMVerifies the given signature matches the expected
        signature.
        )hmaccompare_digestr   )r   r   r   r   s       r   verify_signaturez!SigningAlgorithm.verify_signature   s'     "3(:(:3(F(FGGGr   Nr   r   r   r   r   r   )r   r   r   r   r   r   r   r   )__name__
__module____qualname____doc__r   r    r   r   r   r      sL         $ $ $ $H H H H H Hr   r   c                      e Zd ZdZddZdS )	NoneAlgorithmz`Provides an algorithm that does not perform any signing and
    returns an empty signature.
    r   r   r   r   c                    dS )Nr   r#   r   s      r   r   zNoneAlgorithm.get_signature$   s    sr   Nr   )r   r    r!   r"   r   r#   r   r   r%   r%      s2              r   r%   r   stringr   r   t.Anyc                *    t          j        |           S )zDon't access ``hashlib.sha1`` until runtime. FIPS builds may not include
    SHA-1, in which case the import and use as a default would fail before the
    developer can configure something else.
    )hashlibsha1)r'   s    r   
_lazy_sha1r,   (   s    
 <r   c                  F    e Zd ZU dZ ee          Zded<   dddZddZ	dS )HMACAlgorithmz*Provides signature generation using HMACs.r(   default_digest_methodNdigest_methodc                &    || j         }|| _        d S N)r/   r0   )r   r0   s     r   __init__zHMACAlgorithm.__init__8   s      6M$1r   r   r   r   r   c                b    t          j        ||| j                  }|                                S )N)msg	digestmod)r   newr0   digest)r   r   r   macs       r   r   zHMACAlgorithm.get_signature>   s)    hs1CDDDzz||r   r2   )r0   r(   r   )
r   r    r!   r"   staticmethodr,   r/   __annotations__r3   r   r#   r   r   r.   r.   0   sg         44
 $0<
#;#;;;;;2 2 2 2 2     r   r.   
secret_key7str | bytes | cabc.Iterable[str] | cabc.Iterable[bytes]list[bytes]c                r    t          | t          t          f          rt          |           gS d | D             S )Nc                ,    g | ]}t          |          S r#   r   ).0ss     r   
<listcomp>z#_make_keys_list.<locals>.<listcomp>I   s    ...aJqMM...r   )
isinstancestrr   r	   )r<   s    r   _make_keys_listrF   C   s?     *sEl++ (:&&''..:....r   c                      e Zd ZU dZ ee          Zded<   dZded<   	 	 	 	 	 d$d%dZ	e
d&d            Zd'd(dZd)dZd)dZd*d Zd+d"Zd,d#Zd	S )-Signera  A signer securely signs bytes, then unsigns them to verify that
    the value hasn't been changed.

    The secret key should be a random string of ``bytes`` and should not
    be saved to code or version control. Different salts should be used
    to distinguish signing in different contexts. See :doc:`/concepts`
    for information about the security of the secret key and salt.

    :param secret_key: The secret key to sign and verify with. Can be a
        list of keys, oldest to newest, to support key rotation.
    :param salt: Extra key to combine with ``secret_key`` to distinguish
        signatures in different contexts.
    :param sep: Separator between the signature and value.
    :param key_derivation: How to derive the signing key from the secret
        key and salt. Possible values are ``concat``, ``django-concat``,
        or ``hmac``. Defaults to :attr:`default_key_derivation`, which
        defaults to ``django-concat``.
    :param digest_method: Hash function to use when generating the HMAC
        signature. Defaults to :attr:`default_digest_method`, which
        defaults to :func:`hashlib.sha1`. Note that the security of the
        hash alone doesn't apply when used intermediately in HMAC.
    :param algorithm: A :class:`SigningAlgorithm` instance to use
        instead of building a default :class:`HMACAlgorithm` with the
        ``digest_method``.

    .. versionchanged:: 2.0
        Added support for key rotation by passing a list to
        ``secret_key``.

    .. versionchanged:: 0.18
        ``algorithm`` was added as an argument to the class constructor.

    .. versionchanged:: 0.14
        ``key_derivation`` and ``digest_method`` were added as arguments
        to the class constructor.
    r(   r/   django-concatrE   default_key_derivation   itsdangerous.Signer   .Nr<   r=   saltstr | bytes | Nonesepstr | byteskey_derivation
str | Noner0   t.Any | None	algorithmSigningAlgorithm | Nonec                @   t          |          | _        t          |          | _        | j        t          v rt          d          |t          |          }nd}|| _        || j        }|| _        || j	        }|| _
        |t          | j
                  }|| _        d S )NzThe given separator cannot be used because it may be contained in the signature itself. ASCII letters, digits, and '-_=' must not be used.rK   )rF   secret_keysr	   rO   r   
ValueErrorrM   rJ   rQ   r/   r0   r.   rT   )r   r<   rM   rO   rQ   r0   rT   s          r   r3   zSigner.__init__   s     )8
(C(C$S//8'''7   d##DD)D	!!8N#1  6M$1%d&899I+4r   r   r   c                    | j         d         S )zThe newest (last) entry in the :attr:`secret_keys` list. This
        is for compatibility from before key rotation support was added.
        )rW   )r   s    r   r<   zSigner.secret_key   s    
 ##r   c                n   || j         d         }nt          |          }| j        dk    rGt          j        t
          |                     | j        |z                                                       S | j        dk    rJt          j        t
          |                     | j        dz   |z                                                       S | j        dk    rIt          j
        || j                  }|                    | j                   |                                S | j        dk    r|S t          d	          )
a  This method is called to derive the key. The default key
        derivation choices can be overridden here. Key derivation is not
        intended to be used as a security method to make a complex key
        out of a short password. Instead you should use large random
        secret keys.

        :param secret_key: A specific secret key to derive from.
            Defaults to the last item in :attr:`secret_keys`.

        .. versionchanged:: 2.0
            Added the ``secret_key`` parameter.
        NrZ   concatrI   s   signerr   )r6   nonezUnknown key derivation method)rW   r	   rQ   tcastr   r0   rM   r8   r   r7   update	TypeError)r   r<   r9   s      r   
derive_keyzSigner.derive_key   s     )"-JJ#J//J(**6%!3!3DI
4J!K!K!R!R!T!TUUU O336t))$)i*?**LMMTTVV    F**(:1CDDDCJJty!!!::<< F**;<<<r   r   c                    t          |          }|                                 }| j                            ||          }t	          |          S )z*Returns the signature for the given value.)r	   rb   rT   r   r   )r   r   r   r   s       r   r   zSigner.get_signature   sC    5!!oon**366S!!!r   c                `    t          |          }|| j        z   |                     |          z   S )zSigns the given string.)r	   rO   r   )r   r   s     r   signzSigner.sign   s/    5!!tx$"4"4U";";;;r   r   r   c                    	 t          |          }n# t          $ r Y dS w xY wt          |          }t          | j                  D ]6}|                     |          }| j                            |||          r dS 7dS )z+Verifies the signature for the given value.FT)r   	Exceptionr	   reversedrW   rb   rT   r   )r   r   r   r<   r   s        r   r   zSigner.verify_signature   s    	$$CC 	 	 	55	 5!!"4#344 	 	J//*--C~..sE3?? tt us    
  signed_valuec                    t          |          }| j        |vrt          d| j        d          |                    | j        d          \  }}|                     ||          r|S t          d|d|          )zUnsigns the given string.zNo z found in valuer   z
Signature z does not match)payload)r	   rO   r
   rsplitr   )r   ri   r   r   s       r   unsignzSigner.unsign   s    !,//8<''@TX@@@AAA!((155
s  ,, 	L>>>>NNNNr   c                T    	 |                      |           dS # t          $ r Y dS w xY w)znOnly validates the given signed value. Returns ``True`` if
        the signature exists and is valid.
        TF)rm   r
   )r   ri   s     r   validatezSigner.validate  s@    	KK%%%4 	 	 	55	s    
'')rK   rL   NNN)r<   r=   rM   rN   rO   rP   rQ   rR   r0   rS   rT   rU   )r   r   r2   )r<   rN   r   r   )r   rP   r   r   )r   rP   r   rP   r   r   )ri   rP   r   r   )ri   rP   r   r   )r   r    r!   r"   r:   r,   r/   r;   rJ   r3   propertyr<   rb   r   re   r   rm   ro   r#   r   r   rH   rH   L   s         # #V $0<
#;#;;;;; #21111
 $:%)&*-1,5 ,5 ,5 ,5 ,5\ $ $ $ X$= = = = =B" " " "< < < <
   "O O O O     r   rH   )r   )r'   r   r   r(   )r<   r=   r   r>   )
__future__r   collections.abcabccabcr*   r   typingr^   encodingr   r   r   r	   excr
   r   r%   r,   r.   rF   rH   r#   r   r   <module>rx      s   " " " " " "             & & & & & & # # # # # # # # # # # #                  H H H H H H H H     $                $   &/ / / /~ ~ ~ ~ ~ ~ ~ ~ ~ ~r   