
    ,h%                        S SK Jr  S SKJr  S SKrS SKrS SKrSSK	J
r
  SSK	Jr  SSK	Jr  SSK	Jr  SSKJr   " S	 S
5      r " S S\5      rSSS jjr " S S\5      r    SS jr " S S5      rg)    )annotationsN   )_base64_alphabet)base64_decode)base64_encode)
want_bytes)BadSignaturec                  ,    \ rS rSrSrSS jrSS jrSrg)	SigningAlgorithm   z_Subclasses must implement :meth:`get_signature` to provide
signature generation functionality.
c                    [        5       e)z2Returns the signature for the given key and value.)NotImplementedErrorselfkeyvalues      K/var/www/auris/envauris/lib/python3.13/site-packages/itsdangerous/signer.pyget_signatureSigningAlgorithm.get_signature   s    !##    c                L    [         R                  " X0R                  X5      5      $ )z=Verifies the given signature matches the expected
signature.
)hmaccompare_digestr   )r   r   r   sigs       r   verify_signature!SigningAlgorithm.verify_signature   s      ""3(:(:3(FGGr    Nr   bytesr   r   returnr   )r   r   r   r   r   r   r    bool)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__r   r   r   r   r      s    $Hr   r   c                  "    \ rS rSrSrSS jrSrg)NoneAlgorithm   zXProvides an algorithm that does not perform any signing and
returns an empty signature.
c                    g)Nr   r   r   s      r   r   NoneAlgorithm.get_signature$   s    r   r   Nr   )r"   r#   r$   r%   r&   r   r'   r   r   r   r)   r)      s    r   r)   c                .    [         R                  " U 5      $ )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)strings    r   
_lazy_sha1r1   (   s    
 <<r   c                  L    \ rS rSr% Sr\" \5      rS\S'   S	S
S jjr	SS jr
Srg)HMACAlgorithm0   z*Provides signature generation using HMACs.t.Anydefault_digest_methodNc                .    Uc  U R                   nXl        g N)r6   digest_method)r   r9   s     r   __init__HMACAlgorithm.__init__8   s      66M$1r   c                `    [         R                  " XU R                  S9nUR                  5       $ )N)msg	digestmod)r   newr9   digest)r   r   r   macs       r   r   HMACAlgorithm.get_signature>   s$    hhs1C1CDzz|r   )r9   r8   )r9   r5   r   )r"   r#   r$   r%   r&   staticmethodr1   r6   __annotations__r:   r   r'   r   r   r   r3   r3   0   s!    4
 $0
#;5;2r   r3   c                    [        U [        [        45      (       a  [        U 5      /$ U  Vs/ s H  n[        U5      PM     sn$ s  snf r8   )
isinstancestrr   r   )
secret_keyss     r   _make_keys_listrJ   C   s?     *sEl++:&''#-.:aJqM:...s   Ac                      \ rS rSr% Sr\" \5      rS\S'   Sr	S\S'        S           SS	 jjr
\SS
 j5       rSSS jjrSS jrSS jrSS jrSS jrSS jrSrg)SignerL   a^  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.
r5   r6   django-concatrG   default_key_derivationNc                @   [        U5      U l        [        U5      U l        U R                  [        ;   a  [        S5      eUb  [        U5      nOSnX l        Uc  U R                  nX@l        Uc  U R                  nXPl
        Uc  [        U R                  5      nX`l        g )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)rJ   secret_keysr   sepr   
ValueErrorsaltrO   key_derivationr6   r9   r3   	algorithm)r   rH   rU   rS   rV   r9   rW   s          r   r:   Signer.__init__   s     )8
(C$S/88''7  d#D)D	!!88N#1  66M$1%d&8&89I+4r   c                     U R                   S   $ )zThe newest (last) entry in the :attr:`secret_keys` list. This
is for compatibility from before key rotation support was added.
)rR   )r   s    r   rH   Signer.secret_key   s    
 ##r   c                   Uc  U R                   S   nO[        U5      nU R                  S:X  aE  [        R                  " [
        U R                  U R                  U-   5      R                  5       5      $ U R                  S:X  aH  [        R                  " [
        U R                  U R                  S-   U-   5      R                  5       5      $ U R                  S:X  aI  [        R                  " XR                  S9nUR                  U R                  5        UR                  5       $ U R                  S:X  a  U$ [        S5      e)	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.
rZ   concatrN   s   signerr   )r>   nonezUnknown key derivation method)rR   r   rV   tcastr   r9   rU   r@   r   r?   update	TypeError)r   rH   rA   s      r   
derive_keySigner.derive_key   s    ))"-J#J/J(*66%!3!3DII
4J!K!R!R!TUU  O366t))$))i*?**LMTTV    F*((:1C1CDCJJtyy!::<  F*;<<r   c                    [        U5      nU R                  5       nU R                  R                  X!5      n[	        U5      $ )z*Returns the signature for the given value.)r   rc   rW   r   r   )r   r   r   r   s       r   r   Signer.get_signature   s7    5!oonn**36S!!r   c                X    [        U5      nXR                  -   U R                  U5      -   $ )zSigns the given string.)r   rS   r   )r   r   s     r   signSigner.sign   s)    5!xx$"4"4U";;;r   c                     [        U5      n[        U5      n[        U R                  5       H7  nU R                  U5      nU R                  R                  XAU5      (       d  M7    g   g! [         a     gf = f)z+Verifies the signature for the given value.FT)r   	Exceptionr   reversedrR   rc   rW   r   )r   r   r   rH   r   s        r   r   Signer.verify_signature   ss    	$C 5!"4#3#34J//*-C~~..s3??	 5   		s   A) )
A65A6c                    [        U5      nU R                  U;  a  [        SU R                  < S35      eUR                  U R                  S5      u  p#U R	                  X#5      (       a  U$ [        SU< S3US9e)zUnsigns the given string.zNo z found in valuer   z
Signature z does not match)payload)r   rS   r	   rsplitr   )r   signed_valuer   r   s       r   unsignSigner.unsign   st    !,/88<'TXXL@AA!((15
  ,,LZwo>NNr   c                H     U R                  U5        g! [         a     gf = f)z^Only validates the given signed value. Returns ``True`` if
the signature exists and is valid.
TF)rr   r	   )r   rq   s     r   validateSigner.validate  s(    	KK% 		s    
!!)rW   r9   rV   rU   rR   rS   )rQ      .NNN)rH   7str | bytes | cabc.Iterable[str] | cabc.Iterable[bytes]rU   str | bytes | NonerS   str | bytesrV   z
str | Noner9   zt.Any | NonerW   zSigningAlgorithm | None)r    r   r8   )rH   ry   r    r   )r   rz   r    r   )r   rz   r   rz   r    r!   )rq   rz   r    r   )rq   rz   r    r!   )r"   r#   r$   r%   r&   rC   r1   r6   rD   rO   r:   propertyrH   rc   r   rh   r   rr   ru   r'   r   r   r   rL   rL   L   s    #V $0
#;5; #2C1
 $:%)&*-1,5K,5 !,5 	,5
 #,5 $,5 +,5\ $ $=B"<
"Or   rL   )r   )r0   r   r    r5   )rH   rx   r    zlist[bytes])
__future__r   collections.abcabccabcr.   r   typingr_   encodingr   r   r   r   excr	   r   r)   r1   r3   rJ   rL   r   r   r   <module>r      so    "     & # #   H H $  $ &/G//~ ~r   