
    2Bf$                     R   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y)    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y)	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      S/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/itsdangerous/signer.pyget_signaturezSigningAlgorithm.get_signature   s    !##    sigc                 N    t        j                  || 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GGr   N)__name__
__module____qualname____doc__bytesr   boolr    r   r   r
   r
      sG    $ $u $ $HE H% He H Hr   r
   c                   $    e Zd ZdZdededefdZy)NoneAlgorithmz`Provides an algorithm that does not perform any signing and
    returns an empty signature.
    r   r   r   c                      y)Nr   r    r   s      r   r   zNoneAlgorithm.get_signature%   s    r   N)r   r   r   r   r   r   r    r   r   r"   r"       s!     u  r   r"   c                       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y)HMACAlgorithmz*Provides signature generation using HMACs.default_digest_methodNdigest_methodc                 .    || j                   }|| _        y N)r&   r'   )r   r'   s     r   __init__zHMACAlgorithm.__init__1   s      66M%2r   r   r   r   c                 f    t        j                  ||| j                        }|j                         S )N)msg	digestmod)r   newr'   digest)r   r   r   macs       r   r   zHMACAlgorithm.get_signature7   s&    hhs1C1CDzz|r   r)   )r   r   r   r   staticmethodhashlibsha1r&   _tAny__annotations__r*   r   r   r    r   r   r%   r%   )   sI    4
 %1$>266>3bff 3 u  r   r%   
secret_keyr   c                     t        | t        t        f      rt        |       gS | D cg c]  }t        |       c}S c c}w r)   )
isinstancestrr   r   )r7   ss     r   _make_keys_listr<   <   s6    *sEl+:&''#-.aJqM...s   <c                   l   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y)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_derivationNr7   saltsepkey_derivationr'   	algorithmc                 <   t        |      | _        t        |      | _        | j                  t        v rt        d      |t        |      }nd}|| _        || j                  }|| _        || j                  }|| _
        |t        | j                        }|| _        y )NzThe given separator cannot be used because it may be contained in the signature itself. ASCII letters, digits, and '-_=' must not be used.   itsdangerous.Signer)r<   secret_keysr   rB   r   
ValueErrorrA   r@   rC   r&   r'   r%   rD   )r   r7   rA   rB   rC   r'   rD   s          r   r*   zSigner.__init__x   s     ,;:+F$S/88''7  d#D)D	!!88N#1  66M%2%d&8&8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.
        )rG   )r   s    r   r7   zSigner.secret_key   s    
 ##r   c                 |   || j                   d   }nt        |      }| j                  dk(  rDt        j                  t
        | j                  | j                  |z         j                               S | j                  dk(  rGt        j                  t
        | j                  | j                  dz   |z         j                               S | j                  dk(  rLt        j                  || j                        }|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.
        rJ   concatr?   s   signerr   )r-   nonezUnknown key derivation method)rG   r   rC   r4   castr   r'   rA   r/   r   r.   update	TypeError)r   r7   r0   s      r   
derive_keyzSigner.derive_key   s    ))"-J#J/J(*775$"4"4TYY5K"L"S"S"UVV  O377t))$))i*?**LMTTV    F*((:1C1CDCJJtyy!::<  F*;<<r   r   c                     t        |      }| j                         }| j                  j                  ||      }t	        |      S )z*Returns the signature for the given value.)r   rQ   rD   r   r   )r   r   r   r   s       r   r   zSigner.get_signature   s9    5!oonn**36S!!r   c                 Z    t        |      }|| j                  z   | j                  |      z   S )zSigns the given string.)r   rB   r   )r   r   s     r   signzSigner.sign   s+    5!txx$"4"4U";;;r   r   c                     	 t        |      }t        |      }t        | j                        D ]2  }| j                  |      }| j                  j                  |||      s2 y y# t        $ r Y yw xY w)z+Verifies the signature for the given value.FT)r   	Exceptionr   reversedrG   rQ   rD   r   )r   r   r   r7   r   s        r   r   zSigner.verify_signature   sw    	$C 5!"4#3#34 	J//*-C~~..sE3?		   		s   A# #	A/.A/signed_valuec                     t        |      }| j                  |vrt        d| j                  d      |j                  | j                  d      \  }}| j	                  ||      r|S t        d|d|      )zUnsigns the given string.zNo z found in valuer   z
Signature z does not match)payload)r   rB   r   rsplitr   )r   rX   r   r   s       r   unsignzSigner.unsign   su    !,/88<'TXXL@AA!((15
s  ,LZwo>NNr   c                 F    	 | j                  |       y# t        $ r Y yw xY w)znOnly validates the given signed value. Returns ``True`` if
        the signature exists and is valid.
        TF)r\   r   )r   rX   s     r   validatezSigner.validate   s(    	KK% 		s    	  )rF      .NNNr)   )r   r   r   r   r1   r2   r3   r&   r4   r5   r6   r@   r:   _t_secret_key_t_opt_str_bytes_t_str_bytesOptionalr
   r*   propertyr   r7   rQ   r   rT   r   r   r\   r^   r    r   r   r>   r>   C   s9   #V %1$>266> #2C1
 "8 +/-137,5!,5 ,5 	,5
 C(,5 {{266*,5 ;;/0,5\ $E $ $=%5 = =B"< "E "<, <5 <
l  $ "O< OE O\ d r   r>   )r2   r   typingr4   encodingr   r   r   r   excr   Unionr:   r   rb   rc   ra   Iterabler`   r
   r"   r%   Listr<   r>   r    r   r   <module>rk      s       & # #   xxU
#;;|, \2L@AH H $ $ &/ /"''%. /~ ~r   