
    E d$                     X   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
 ej        eef         Zej        e         Zej        ej        e         ef         Z G d d	          Z G d
 de          Z G d de          Zdedej        e         fdZ G d d          ZdS )    N   )_base64_alphabet)base64_decode)base64_encode
want_bytes)BadSignaturec                   >    e Zd ZdZdededefdZdedededefdZdS )	SigningAlgorithmzgSubclasses must implement :meth:`get_signature` to provide
    signature generation functionality.
    keyvaluereturnc                     t                      )z2Returns the signature for the given key and value.)NotImplementedErrorselfr   r   s      \C:\Users\ChattiNader\Documents\MyHotelMatch\api\dev\Lib\site-packages\itsdangerous/signer.pyget_signaturezSigningAlgorithm.get_signature   s    !###    sigc                 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)__name__
__module____qualname____doc__bytesr   boolr    r   r   r   r      s         $ $u $ $ $ $ $HE H% He H H H H H H Hr   r   c                   &    e Zd ZdZdededefdZdS )NoneAlgorithmz`Provides an algorithm that does not perform any signing and
    returns an empty signature.
    r   r   r   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#   r#       sG          u       r   r#   c                   t    e Zd ZU dZ eej                  Zej	        e
d<   d
dej	        fdZdededefd	ZdS )HMACAlgorithmz*Provides signature generation using HMACs.default_digest_methodNdigest_methodc                 &    || j         }|| _        d S N)r'   r(   )r   r(   s     r   __init__zHMACAlgorithm.__init__1   s      6M%2r   r   r   r   c                 b    t          j        ||| j                  }|                                S )N)msg	digestmod)r   newr(   digest)r   r   r   macs       r   r   zHMACAlgorithm.get_signature7   s)    hs1CDDDzz||r   r*   )r   r   r   r   staticmethodhashlibsha1r'   _tAny__annotations__r+   r   r   r!   r   r   r&   r&   )   s         44
 %1L$>$>26>>>3 3bf 3 3 3 3 u       r   r&   
secret_keyr   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>@   s    ...aJqMM...r   )
isinstancestrr   r   )r8   s    r   _make_keys_listr@   <   s=    *sEl++ (:&&''..:....r   c                   P   e Zd ZU dZ eej                  Zej	        e
d<   dZee
d<   	 	 	 	 	 dded	ed
edej        e         dej        ej	                 dej        e         fdZedefd            ZddedefdZdedefdZdedefdZdededefdZdedefdZdedef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'   django-concatdefault_key_derivation   itsdangerous.Signer   .Nr8   saltsepkey_derivationr(   	algorithmc                 @   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.rE   )r@   secret_keysr   rH   r   
ValueErrorrG   rD   rI   r'   r(   r&   rJ   )r   r8   rG   rH   rI   r(   rJ   s          r   r+   zSigner.__init__x   s     ,;:+F+F$S//8'''7   d##DD)D	!!8N#1  6M%2%d&899I+4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.
        )rL   )r   s    r   r8   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.
        NrO   concatrC   s   signerr   )r.   nonezUnknown key derivation method)rL   r   rI   r5   castr   r(   rG   r0   r   r/   update	TypeError)r   r8   r1   s      r   
derive_keyzSigner.derive_key   s     )"-JJ#J//J(**75$"4"4TY5K"L"L"S"S"U"UVVV O337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   rV   rJ   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   rH   r   )r   r   s     r   signzSigner.sign   s/    5!!tx$"4"4U";";;;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   reversedrL   rV   rJ   r   )r   r   r   r8   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   rH   r	   rsplitr   )r   r]   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)ra   r	   )r   r]   s     r   validatezSigner.validate   s@    	KK%%%4 	 	 	55	s    
'')rE   rF   NNNr*   )r   r   r   r   r2   r3   r4   r'   r5   r6   r7   rD   r?   _t_secret_key_t_opt_str_bytes_t_str_bytesOptionalr   r+   propertyr   r8   rV   r   rY   r    r   ra   rc   r!   r   r   rB   rB   C   s        # #V %1L$>$>26>>> #2C111
 "8 +/-137,5 ,5!,5 ,5 	,5
 C(,5 {26*,5 ;/0,5 ,5 ,5 ,5\ $E $ $ $ X$= =%5 = = = = =B"< "E " " " "<, <5 < < < <
l  $    "O< OE O O O O\ d      r   rB   )r3   r   typingr5   encodingr   r   r   r   excr	   Unionr?   r   rf   rg   re   Iterablerd   r   r#   r&   Listr@   rB   r!   r   r   <module>ro      s         & & & & & & # # # # # # # # # # # #                  xU
#;|, \2L@AH H H H H H H H     $       $   &/ /"'%. / / / /~ ~ ~ ~ ~ ~ ~ ~ ~ ~r   