
    wdf                         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 ddl	m
Z
  G d	 d
e          Z G d de          Z G d de          Z G d de          ZdS )    N   )constant_time_compare)_base64_alphabet)base64_decode)base64_encode)
want_bytes)BadSignaturec                       e Zd ZdZd Zd ZdS )SigningAlgorithmzgSubclasses must implement :meth:`get_signature` to provide
    signature generation functionality.
    c                     t                      )z2Returns the signature for the given key and value.)NotImplementedErrorselfkeyvalues      X/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/itsdangerous/signer.pyget_signaturezSigningAlgorithm.get_signature   s    !###    c                 J    t          ||                     ||                    S )zMVerifies the given signature matches the expected
        signature.
        )r   r   )r   r   r   sigs       r   verify_signaturez!SigningAlgorithm.verify_signature   s$     %S$*<*<S%*H*HIIIr   N)__name__
__module____qualname____doc__r   r    r   r   r   r      sA         $ $ $J J J J Jr   r   c                       e Zd ZdZd ZdS )NoneAlgorithmz`Provides an algorithm that does not perform any signing and
    returns an empty signature.
    c                     dS )Nr   r   r   s      r   r   zNoneAlgorithm.get_signature!   s    sr   N)r   r   r   r   r   r   r   r   r   r      s-             r   r   c                   @    e Zd ZdZ eej                  ZddZd Z	dS )HMACAlgorithmz*Provides signature generation using HMACs.Nc                 &    || j         }|| _        d S N)default_digest_methoddigest_method)r   r%   s     r   __init__zHMACAlgorithm.__init__-   s      6M*r   c                 b    t          j        ||| j                  }|                                S )N)msg	digestmod)hmacnewr%   digest)r   r   r   macs       r   r   zHMACAlgorithm.get_signature2   s)    hs1CDDDzz||r   r#   )
r   r   r   r   staticmethodhashlibsha1r$   r&   r   r   r   r   r!   r!   %   sQ        44
 )L66+ + + +
    r   r!   c                   l    e Zd ZdZ eej                  ZdZ	 	 	 	 	 ddZ	d Z
d Zd Zd	 Zd
 Zd ZdS )Signera  This class can sign and unsign bytes, validating the signature
    provided.

    Salt can be used to namespace the hash, so that a signed string is
    only valid for a given namespace. Leaving this at the default value
    or re-using a salt value across different parts of your application
    where the same signed value in one part can mean something different
    in another part is a security risk.

    See :ref:`the-salt` for an example of what the salt is doing and how
    you can utilize it.

    .. versionadded:: 0.14
        ``key_derivation`` and ``digest_method`` were added as arguments
        to the class constructor.

    .. versionadded:: 0.18
        ``algorithm`` was added as an argument to the class constructor.
    django-concatN.c                     t          |          | _        t          |          | _        | j        t          v rt	          d          |dn|| _        || j        }|| _        || j        }|| _	        |t          | j	                  }|| _        d S )NzThe given separator cannot be used because it may be contained in the signature itself. Alphanumeric characters and `-_=` must not be used.zitsdangerous.Signer)r   
secret_keysepr   
ValueErrorsaltdefault_key_derivationkey_derivationr$   r%   r!   	algorithm)r   r6   r9   r7   r;   r%   r<   s          r   r&   zSigner.__init__[   s     %Z00c??8''':  
 .2\))t	!!8N,  6M*%d&899I"r   c                    t          | j                  }| j        dk    r/|                     || j        z                                             S | j        dk    r2|                     |dz   | j        z                                             S | j        dk    rIt          j        | j        | j                  }|                    |           |                                S | j        dk    r| j        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.
        concatr3   s   signerr*   )r)   nonezUnknown key derivation method)
r   r9   r;   r%   r6   r,   r*   r+   update	TypeError)r   r9   r-   s      r   
derive_keyzSigner.derive_keyw   s     $)$$(**%%dT_&<==DDFFF O33%%dY&6&HIIPPRRR F**(4?d6HIIICJJt::<< F**?";<<<r   c                     t          |          }|                                 }| j                            ||          }t	          |          S )z*Returns the signature for the given value.)r   rB   r<   r   r   )r   r   r   r   s       r   r   zSigner.get_signature   sC    5!!oon**366S!!!r   c                 v    t          |          t          | j                  z   |                     |          z   S )zSigns the given string.)r   r7   r   )r   r   s     r   signzSigner.sign   s2    %  :dh#7#77$:L:LU:S:SSSr   c                     |                                  }	 t          |          }n# t          $ r Y dS w xY w| j                            |||          S )z+Verifies the signature for the given value.F)rB   r   	Exceptionr<   r   )r   r   r   r   s       r   r   zSigner.verify_signature   sa    oo	$$CC 	 	 	55	~..sE3???s   & 
44c                    t          |          }t          | j                  }||vrt          d| j        z            |                    |d          \  }}|                     ||          r|S t          d|z  |          )zUnsigns the given string.zNo %r found in valuer   zSignature %r does not match)payload)r   r7   r	   rsplitr   )r   signed_valuer7   r   r   s        r   unsignzSigner.unsign   s    !,//""l""5@AAA!((a00
s  ,, 	L83>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)rL   r	   )r   rK   s     r   validatezSigner.validate   s@    	KK%%%4 	 	 	55	s    
'')Nr4   NNN)r   r   r   r   r.   r/   r0   r$   r:   r&   rB   r   rE   r   rL   rN   r   r   r   r2   r2   7   s         2 )L66 -
 # # # #8= = =*" " "T T T@ @ @	O 	O 	O    r   r2   )r/   r*   _compatr   encodingr   r   r   r   excr	   objectr   r   r!   r2   r   r   r   <module>rS      sI     * * * * * * & & & & & & # # # # # # # # # # # #                  J J J J Jv J J J     $       $   $| | | | |V | | | | |r   