
    jZ(                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSK	J
r
Jr  SSKJrJr  SSKJr  SSKJr  SSKJr  \" S	5      rS
r " S S\5      r " S S\5      rS rS rS rS rS%S jrS rS&S jr S&S jr!SSS.S jr"S'S jr# " S S5      r$SS\$S4S jr%SS\$SS4S  jr& " S! S"5      r' " S# S$\'5      r(g)(a_  
Functions for creating and restoring url-safe signed JSON objects.

The format used looks like this:

>>> signing.dumps("hello")
'ImhlbGxvIg:1QaUZC:YIye-ze3TTx7gtSv422nZA4sgmk'

There are two components here, separated by a ':'. The first component is a
URLsafe base64 encoded JSON of the object passed to dumps(). The second
component is a base64 encoded hmac/SHA-256 hash of "$first_component:$secret"

signing.loads(s) checks the signature and returns the deserialized object.
If the signature fails, a BadSignature exception is raised.

>>> signing.loads("ImhlbGxvIg:1QaUZC:YIye-ze3TTx7gtSv422nZA4sgmk")
'hello'
>>> signing.loads("ImhlbGxvIg:1QaUZC:YIye-ze3TTx7gtSv42-modified")
...
BadSignature: Signature "ImhlbGxvIg:1QaUZC:YIye-ze3TTx7gtSv42-modified" does
not match

You can optionally compress the JSON prior to base64 encoding it to save
space, using the compress=True argument. This checks if compression actually
helps and only applies compression if the result is a shorter string:

>>> signing.dumps(list(range(1, 20)), compress=True)
'.eJwFwcERACAIwLCF-rCiILN47r-GyZVJsNgkxaFxoDgxcOHGxMKD_T7vhAml:1QaUaL:BA0thEZrp4FQVXIXuOvYJtLJSrQ'

The fact that the string is compressed is signalled by the prefixed '.' at the
start of the base64 JSON.

There are 65 url-safe characters: the 64 used by url-safe base64 and the ':'.
These functions make use of all of them.
    N)settings)constant_time_comparesalted_hmac)RemovedInDjango70Warningdjango_file_prefixesforce_bytes)import_string)_lazy_re_compilez^[A-z0-9-_=]*$>0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzc                       \ rS rSrSrSrg)BadSignature7   zSignature does not match. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       K/var/www/html/KUNJ/venv/lib/python3.13/site-packages/django/core/signing.pyr   r   7   s    #r   r   c                       \ rS rSrSrSrg)SignatureExpired=   z3Signature timestamp is older than required max_age.r   Nr   r   r   r   r   r   =   s    =r   r   c                     U S:X  a  gU S:  a  SOSn[        U 5      n SnU S:  a"  [        U S5      u  p[        U   U-   nU S:  a  M"  X-   $ )Nr   0- >   )absdivmodBASE62_ALPHABET)ssignencoded	remainders       r   
b62_encoder)   C   s]    Ava%3RDAAG
a%a}!),w6 a% >r   c                     U S:X  a  gSnU S   S:X  a  U SS  n SnSnU  H  nUS-  [         R                  U5      -   nM      X-  $ )Nr   r      r   r!   )r$   index)r%   r&   decodeddigits       r   
b62_decoder0   O   s\    CxDts{abEGB,!6!6u!== >r   c                 L    [         R                  " U 5      R                  S5      $ )N   =)base64urlsafe_b64encodestrip)r%   s    r   
b64_encoder6   \   s    ##A&,,T22r   c                 V    S[        U 5      * S-  -  n[        R                  " X-   5      $ )Nr2      )lenr3   urlsafe_b64decode)r%   pads     r   
b64_decoder<   `   s)    
3q6'A+
C##AG,,r   c           	          Uc$  [         R                  " S[        [        5       S9  Sn[	        [        XX#S9R                  5       5      R                  5       $ )NzThe default argument for algorithm in base64_hmac() will change from 'sha1' to 'sha256' in Django 7.0. Pass an explicit algorithm to silence this warning.)categoryskip_file_prefixessha1	algorithm)warningswarnr   r   r6   r   digestdecode)saltvaluekeyrB   s       r   base64_hmacrJ   f   sR    1 .35	
 	D:AACfhr   c                     S[        U 5      -   $ )Ns   django.http.cookiesr   )rI   s    r   _cookie_signer_keyrL   u   s    !K$444r   r    c                 (    S[        U5       SU U  3$ )Nzdjango.http.cookies.v2::)r9   cookie_namerG   s     r   _cookie_signer_saltrQ   z   s    $SYKq{mDDr   c                 
    X-   $ Nr   rO   s     r   _cookie_signer_legacy_saltrT      s    r   )rG   max_agec                    [        [        X5      S9R                  XS9$ ! [         aT  n[        R
                  (       a9  [        U[        5      (       d$  [        [        X5      S9R                  XS9s S nA$ e S nAff = f)N)rG   )rU   )	get_cookie_signerrQ   unsignr   r   "SIGNED_COOKIE_LEGACY_SALT_FALLBACK
isinstancer   rT   )signed_valuerP   rG   rU   excs        r   _unsign_cookier]      s     !&9+&LMTT U 
 	
  66z!@
 @
 %/Bf\f34 	s!   ! 
A?AA:3A?9A::A?c                     [        [        R                  5      nU" [        [        R                  5      [        [        [        R                  5      U S9$ )N)rI   fallback_keysrG   )r
   r   SIGNING_BACKENDrL   
SECRET_KEYmapSECRET_KEY_FALLBACKS)rG   Signers     r   rW   rW      sA    8334Fx223,h.K.KL r   c                   $    \ rS rSrSrS rS rSrg)JSONSerializer   zK
Simple wrapper around json to be used in signing.dumps and
signing.loads.
c                 J    [         R                  " USS9R                  S5      $ )N),rN   )
separatorslatin-1)jsondumpsencode)selfobjs     r   rm   JSONSerializer.dumps   s    zz#*5<<YGGr   c                 L    [         R                  " UR                  S5      5      $ )Nrk   )rl   loadsrF   )ro   datas     r   rs   JSONSerializer.loads   s    zz$++i011r   r   N)r   r   r   r   r   rm   rs   r   r   r   r   rf   rf      s    
H2r   rf   zdjango.core.signingFc                 0    [        XS9R                  XUS9$ )a  
Return URL-safe, hmac signed base64 compressed JSON string. If key is
None, use settings.SECRET_KEY instead. The hmac algorithm is the default
Signer algorithm.

If compress is True (not the default), check if compressing using zlib can
save some space. Prepend a '.' to signify compression. This is included
in the signature, to protect against zip bombs.

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 without good cause is a security risk.

The serializer is expected to return a bytestring.
)rI   rG   )
serializercompress)TimestampSignersign_object)rp   rI   rG   rw   rx   s        r   rm   rm      s&    & s.::X ;  r   c                 4    [        XUS9R                  U UUS9$ )zp
Reverse of dumps(), raise BadSignature if signature fails.

The serializer is expected to accept a bytestring.
)rI   rG   r_   )rw   rU   )ry   unsign_object)r%   rI   rG   rw   rU   r_   s         r   rs   rs      s.     -m	  r   c                   Z    \ rS rSrSSSSSS.S jrSS jrS rS r\S	4S
 jr	\4S jr
Srg)rd      NrN   )rI   seprG   rB   r_   c                   U=(       d    [         R                  U l        Ub  UO[         R                  U l        X l        U=(       d1    U R                  R                  < SU R                  R                  < 3U l	        U=(       d    SU l
        [        R                  U R
                  5      (       a  [        SU-  5      eg )N.sha256zJUnsafe Signer separator: %r (cannot be empty or consist of only A-z0-9-_=))r   ra   rI   rc   r_   r   	__class__r   r   rG   rB   _SEP_UNSAFEmatch
ValueError)ro   rI   r   rG   rB   r_   s         r   __init__Signer.__init__   s     -(-- ( .. 	
  
NN%%NN##
	 #.hTXX&&"$'(  'r   c                 p    U=(       d    U R                   n[        U R                  S-   XU R                  S9$ )NsignerrA   )rI   rJ   rG   rB   )ro   rH   rI   s      r   	signatureSigner.signature   s+    oTXX499x/t~~VVr   c                 J    U< U R                   < U R                  U5      < 3$ rS   )r   r   )ro   rH   s     r   r&   Signer.sign   s     $((DNN5,ABBr   c                 0   U R                   U;  a  [        SU R                   -  5      eUR                  U R                   S5      u  p#U R                  /U R                  Q H&  n[        X0R                  X$5      5      (       d  M$  Us  $    [        SU-  5      e)NzNo "%s" found in valuer+   zSignature "%s" does not match)r   r   rsplitrI   r_   r   r   )ro   r[   rH   sigrI   s        r   rX   Signer.unsign   s    88<'7$((BCC!((15
HH2t112C$S..*DEE 3 :S@AAr   Fc                    U" 5       R                  U5      nSnU(       a5  [        R                  " U5      n[        U5      [        U5      S-
  :  a  UnSn[	        U5      R                  5       nU(       a  SU-   nU R                  U5      $ )a5  
Return URL-safe, hmac signed base64 compressed JSON string.

If compress is True (not the default), check if compressing using zlib
can save some space. Prepend a '.' to signify compression. This is
included in the signature, to protect against zip bombs.

The serializer is expected to return a bytestring.
Fr+   Tr   )rm   zlibrx   r9   r6   rF   r&   )ro   rp   rw   rx   rt   is_compressed
compressedbase64ds           r   rz   Signer.sign_object   sx     |!!#&t,J:#d)a-0! $T"))+GmGyy!!r   c                     U R                   " U40 UD6R                  5       nUS S S:H  nU(       a  USS  n[        U5      nU(       a  [        R                  " U5      nU" 5       R                  U5      $ )Nr+      .)rX   rn   r<   r   
decompressrs   )ro   
signed_objrw   kwargsr   r   rt   s          r   r|   Signer.unsign_object  sl     ++j3F3::<Ra[D(
abkG'"??4(D|!!$''r   )rB   r_   rI   rG   r   rS   )r   r   r   r   r   r   r&   rX   rf   rz   r|   r   r   r   r   rd   rd      s;    sT*WCB +95 "2 4B (r   rd   c                   >   ^  \ rS rSrS rU 4S jrSU 4S jjrSrU =r$ )ry   i&  c                 P    [        [        [        R                  " 5       5      5      $ rS   )r)   inttime)ro   s    r   	timestampTimestampSigner.timestamp'  s    #diik*++r   c                 h   > U< U R                   < U R                  5       < 3n[        TU ]  U5      $ rS   )r   r   superr&   )ro   rH   r   s     r   r&   TimestampSigner.sign*  s)    !488T^^-=>w|E""r   c                 >  > [         TU ]  U5      nUR                  U R                  S5      u  p[	        U5      nUb`  [        U[        R                  5      (       a  UR                  5       n[        R                  " 5       U-
  nXR:  a  [        SU< SU< S35      eU$ )zS
Retrieve original value and check it wasn't signed more
than max_age seconds ago.
r+   zSignature age z > z seconds)r   rX   r   r   r0   rZ   datetime	timedeltatotal_secondsr   r   )ro   rH   rU   resultr   ager   s         r   rX   TimestampSigner.unsign.  s    
 &!==15y)	'8#5#566!//1))+	)C}&#w'WXXr   r   rS   )	r   r   r   r   r   r&   rX   r   __classcell__)r   s   @r   ry   ry   &  s    ,# r   ry   rS   )r    )z%django.core.signing.get_cookie_signer))r   r3   r   rl   r   rC   r   django.confr   django.utils.cryptor   r   django.utils.deprecationr   r   django.utils.encodingr	   django.utils.module_loadingr
   django.utils.regex_helperr   r   r$   	Exceptionr   r   r)   r0   r6   r<   rJ   rL   rQ   rT   r]   rW   rf   rm   rs   rd   ry   r   r   r   <module>r      s   "H         B S - 5 601R	9 		| 		
3-5
E 79$ "
2 
2 -.SX4 		,J( J(Zf r   