
    yPj;V                       U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
 d dlmZmZmZ d dlmZmZmZmZ ddlmZmZmZ dd	lmZmZmZmZmZmZmZmZm Z  dd
lm!Z! es e" ejF                  dd            rTd dl$Z$e$jJ                  dk\  rd dlm&Z& nd dl'm&Z& ddl(m)Z)m*Z* ddl+m,Z, ddl-m.Z.m/Z/m0Z0 ee)e,e1e2f   Z3de4d<   ee*e,e1e2f   Z5de4d<    G d d      Z6 e6       Z7ee7_8        e7jr                  Z9e7jt                  Z:e7jv                  Z;y)    )annotationsN)timegm)	ContainerIterableSequence)datetime	timedeltatimezone)TYPE_CHECKINGAnyUnioncast   )PyJWS_ALGORITHM_UNSET_jws_global_obj)	DecodeErrorExpiredSignatureErrorImmatureSignatureErrorInvalidAudienceErrorInvalidIssuedAtErrorInvalidIssuerErrorInvalidJTIErrorInvalidSubjectErrorMissingRequiredClaimError)RemovedInPyjwt3WarningSPHINX_BUILD )   
   )	TypeAlias)AllowedPrivateKeysAllowedPublicKeys)PyJWK)FullOptionsOptions
SigOptionsr!   AllowedPrivateKeyTypesAllowedPublicKeyTypesc                     e Zd ZdddZedd       ZddZdddZedddf	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ		 	 d	 	 	 	 	 	 	 ddZ
	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d d	Zd!d
Z	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ	 	 	 	 d#	 	 	 	 	 	 	 	 	 	 	 	 	 d$dZ	 	 	 	 	 	 d%dZ	 d	 	 	 	 	 d&dZd'dZ	 	 	 	 	 	 	 	 d(dZ	 	 	 	 	 	 	 	 d(dZ	 	 	 	 	 	 	 	 d(dZdd	 	 	 	 	 	 	 d)dZ	 	 	 	 	 	 d*dZy)+PyJWTNc                    |  | j                         | _        || j                  |      | _        t        | j	                               | _        y )N)options)_get_default_optionsr-   _merge_optionsr   _get_sig_options_jwsselfr-   s     C/root/$HERMES_HOME/venv/lib/python3.12/site-packages/jwt/api_jwt.py__init__zPyJWT.__init__+   sB    002..w7DL$"7"7"9:	    c                     ddddddddg dddS )NTF)verify_signature
verify_exp
verify_nbf
verify_iat
verify_aud
verify_iss
verify_sub
verify_jtirequire
strict_audenforce_minimum_key_length rC   r6   r4   r.   zPyJWT._get_default_options3   s/     !%*/
 	
r6   c                Z    | j                   d   | j                   j                  dd      dS )Nr8   rB   Fr8   rB   r-   get)r3   s    r4   r0   zPyJWT._get_sig_optionsC   s0     $-? @*.,,*:*:,e+
 	
r6   c                   || j                   S |j                  dd      s|j                  dd      |d<   |j                  dd      |d<   |j                  dd      |d<   |j                  dd      |d<   |j                  dd      |d<   |j                  d	d      |d	<   |j                  d
d      |d
<   i | j                   |S )Nr8   Tr9   Fr:   r;   r<   r=   r>   r?   rF   r2   s     r4   r/   zPyJWT._merge_optionsK   s    ?<< {{-t4$+KKe$DGL!$+KKe$DGL!$+KKe$DGL!$+KKe$DGL!$+KKe$DGL!$+KKe$DGL!$+KKe$DGL!*$,,*'**r6   Tc                   t        |t              st        d      |j                         }dD ]A  }t        |j	                  |      t
              s#t        ||   j                               ||<   C d|v rt        |d   t              st        d      | j                  |||      }| j                  j                  ||||||      S )a  Encode the ``payload`` as JSON Web Token.

        :param payload: JWT claims, e.g. ``dict(iss=..., aud=..., sub=...)``
        :type payload: dict[str, typing.Any]
        :param key: a key suitable for the chosen algorithm:

            * for **asymmetric algorithms**: PEM-formatted private key, a multiline string
            * for **symmetric algorithms**: plain string, sufficiently long for security

        :type key: str or bytes or PyJWK or :py:class:`jwt.algorithms.AllowedPrivateKeys`
        :param algorithm: algorithm to sign the token with, e.g. ``"ES256"``.
            If ``headers`` includes ``alg``, it will be preferred to this parameter.
            If ``key`` is a :class:`PyJWK` object, by default the key algorithm will be used.
        :type algorithm: str or None
        :param headers: additional JWT header fields, e.g. ``dict(kid="my-key-id")``.
        :type headers: dict[str, typing.Any] or None
        :param json_encoder: custom JSON encoder for ``payload`` and ``headers``
        :type json_encoder: json.JSONEncoder or None

        :rtype: str
        :returns: a JSON Web Token

        :raises TypeError: if ``payload`` is not a ``dict``
        zGExpecting a dict object, as JWT only supports JSON objects as payloads.)expiatnbfisszIssuer (iss) must be a string.)headersjson_encoder)sort_headers)
isinstancedict	TypeErrorcopyrG   r   r   utctimetuplestr_encode_payloadr1   encode)	r3   payloadkey	algorithmrN   rO   rP   
time_claimjson_payloads	            r4   rX   zPyJWT.encodeZ   s    D '4(,  ,,./ 	QJ'++j18<&,WZ-@-M-M-O&P
#	Q GJwu~s$C<==++% , 
 yy%   
 	
r6   c                P    t        j                  |d|      j                  d      S )z
        Encode a given payload to the bytes to be signed.

        This method is intended to be overridden by subclasses that need to
        encode the payload in a different way, e.g. compress the payload.
        ),:)
separatorsclszutf-8)jsondumpsrX   )r3   rY   rN   rO   s       r4   rW   zPyJWT._encode_payload   s)     zz!
 &/		r6   c                   |r6t        j                  dt        |j                                t        d       |d}n|j                  dd      }|!||k7  rt        j                  dt        d       | j                  |      }||j                  dd	      d
}| j                  j                  |||||      }| j                  |      }| j                  |||||
|	       ||d<   |S )u$  Identical to ``jwt.decode`` except for return value which is a dictionary containing the token header (JOSE Header),
        the token payload (JWT Payload), and token signature (JWT Signature) on the keys "header", "payload",
        and "signature" respectively.

        :param jwt: the token to be decoded
        :type jwt: str or bytes
        :param key: the key suitable for the allowed algorithm
        :type key: str or bytes or PyJWK or :py:class:`jwt.algorithms.AllowedPublicKeys`

        :param algorithms: allowed algorithms, e.g. ``["ES256"]``

            .. warning::

               Do **not** compute the ``algorithms`` parameter based on
               the ``alg`` from the token itself, or on any other data
               that an attacker may be able to influence, as that might
               expose you to various vulnerabilities (see `RFC 8725 §2.1
               <https://www.rfc-editor.org/rfc/rfc8725.html#section-2.1>`_). Instead,
               either hard-code a fixed value for ``algorithms``, or
               configure it in the same place you configure the
               ``key``. Make sure not to mix symmetric and asymmetric
               algorithms that interpret the ``key`` in different ways
               (e.g. HS\* and RS\*).
        :type algorithms: typing.Sequence[str] or None

        :param jwt.types.Options options: extended decoding and validation options
            Refer to :py:class:`jwt.types.Options` for more information.

        :param audience: optional, the value for ``verify_aud`` check
        :type audience: str or typing.Iterable[str] or None
        :param issuer: optional, the value for ``verify_iss`` check
        :type issuer: str or typing.Container[str] or None
        :param leeway: a time margin in seconds for the expiration check
        :type leeway: float or datetime.timedelta
        :rtype: dict[str, typing.Any]
        :returns: Decoded JWT with the JOSE Header on the key ``header``, the JWS
         Payload on the key ``payload``, and the JWS Signature on the key ``signature``.
        zypassing additional kwargs to decode_complete() is deprecated and will be removed in pyjwt version 3. Unsupported kwargs:    
stacklevelTr8   zThe `verify` argument to `decode` does nothing in PyJWT 2.0 and newer. The equivalent is setting `verify_signature` to False in the `options` dictionary. This invocation has a mismatch between the kwarg and the option entry.)categoryrh   rB   FrE   )rZ   
algorithmsr-   detached_payload)audienceissuerleewaysubjectrY   )warningswarntuplekeysr   rG   DeprecationWarningr/   r1   decode_complete_decode_payload_validate_claims)r3   jwtrZ   rj   r-   verifyrk   rl   rm   ro   rn   kwargsr8   merged_optionssig_optionsdecodedrY   s                    r4   ru   zPyJWT.decode_complete   s#   r MM'',V[[]';&<> ' ?#&{{+=tD
 &,<"<MMY , ,,W5 !1*8*<*<,e+#
 ))++!- , 
 &&w/ 	 	
 %	r6   c                    	 t        j                  |d         }t	        |t
              st        d      |S # t        $ r}t        d|       |d}~ww xY w)a  
        Decode the payload from a JWS dictionary (payload, signature, header).

        This method is intended to be overridden by subclasses that need to
        decode the payload in a different way, e.g. decompress compressed
        payloads.
        rY   zInvalid payload string: Nz-Invalid payload string: must be a json object)rc   loads
ValueErrorr   rQ   rR   )r3   r}   rY   es       r4   rv   zPyJWT._decode_payload  sa    	E&*jj1C&DG '4(MNN	  	E 8<=1D	Es   7 	A AAc                    |r6t        j                  dt        |j                                t        d       | j                  |||||||||	|

      }t        t        t        t        f   |d         S )u  Verify the ``jwt`` token signature and return the token claims.

        :param jwt: the token to be decoded
        :type jwt: str or bytes
        :param key: the key suitable for the allowed algorithm
        :type key: str or bytes or PyJWK or :py:class:`jwt.algorithms.AllowedPublicKeys`

        :param algorithms: allowed algorithms, e.g. ``["ES256"]``
            If ``key`` is a :class:`PyJWK` object, allowed algorithms will default to the key algorithm.

            .. warning::

               Do **not** compute the ``algorithms`` parameter based on
               the ``alg`` from the token itself, or on any other data
               that an attacker may be able to influence, as that might
               expose you to various vulnerabilities (see `RFC 8725 §2.1
               <https://www.rfc-editor.org/rfc/rfc8725.html#section-2.1>`_). Instead,
               either hard-code a fixed value for ``algorithms``, or
               configure it in the same place you configure the
               ``key``. Make sure not to mix symmetric and asymmetric
               algorithms that interpret the ``key`` in different ways
               (e.g. HS\* and RS\*).
        :type algorithms: typing.Sequence[str] or None

        :param jwt.types.Options options: extended decoding and validation options
            Refer to :py:class:`jwt.types.Options` for more information.

        :param audience: optional, the value for ``verify_aud`` check
        :type audience: str or typing.Iterable[str] or None
        :param subject: optional, the value for ``verify_sub`` check
        :type subject: str or None
        :param issuer: optional, the value for ``verify_iss`` check
        :type issuer: str or typing.Container[str] or None
        :param leeway: a time margin in seconds for the expiration check
        :type leeway: float or datetime.timedelta
        :rtype: dict[str, typing.Any]
        :returns: the JWT claims
        zppassing additional kwargs to decode() is deprecated and will be removed in pyjwt version 3. Unsupported kwargs: rf   rg   )ry   rk   rl   ro   rm   rn   rY   )
rp   rq   rr   rs   r   ru   r   rR   rV   r   )r3   rx   rZ   rj   r-   ry   rk   rl   ro   rm   rn   rz   r}   s                r4   decodezPyJWT.decode/  s    r MM'',V[[]';&<> ' &&- ' 
 DcNGI$677r6   c                   t        |t              r|j                         }|!t        |t        t        f      st        d      | j                  ||d          t        j                  t        j                        j                         }d|v r|d   r| j                  |||       d|v r|d   r| j                  |||       d|v r|d	   r| j                  |||       |d
   r| j                  ||       |d   r$| j!                  |||j#                  dd             |d   r| j%                  ||       |d   r| j'                  |       y y )Nz+audience must be a string, iterable or Noner@   )tzrK   r;   rL   r:   rJ   r9   r=   r<   rA   Fstrictr>   r?   )rQ   r	   total_secondsrV   r   rS   _validate_required_claimsr   nowr
   utc	timestamp_validate_iat_validate_nbf_validate_exp_validate_iss_validate_audrG   _validate_sub_validate_jti)r3   rY   r-   rl   rm   ro   rn   r   s           r4   rw   zPyJWT._validate_claims~  sH    fi())+F
8c8_(MIJJ&&w	0BCllhll+557G 5wV4G 5wV4G 5wV4< w/< '++lE*J   < w0< w' !r6   c                J    |D ]  }|j                  |      t        |       y N)rG   r   )r3   rY   claimsclaims       r4   r   zPyJWT._validate_required_claims  s-    
  	7E{{5!)/66	7r6   c                    d|vryt        |d   t              st        d      | |j                  d      |k7  rt        d      yy)z
        Checks whether "sub" if in the payload is valid or not.
        This is an Optional claim

        :param payload(dict): The payload which needs to be validated
        :param subject(str): The subject of the token
        subNzSubject must be a stringzInvalid subject)rQ   rV   r   rG   )r3   rY   ro   s      r4   r   zPyJWT._validate_sub  sV     '%.#.%&@AA{{5!W,)*;<< - r6   c                b    d|vryt        |j                  d      t              st        d      y)z
        Checks whether "jti" if in the payload is valid or not
        This is an Optional claim

        :param payload(dict): The payload which needs to be validated
        jtiNzJWT ID must be a string)rQ   rG   rV   r   )r3   rY   s     r4   r   zPyJWT._validate_jti  s3     '++e,c2!";<< 3r6   c                z    	 t        |d         }|||z   kD  rt        d      y # t        $ r t        d      d w xY w)NrK   z)Issued At claim (iat) must be an integer.z The token is not yet valid (iat))intr   r   r   )r3   rY   r   rn   rK   s        r4   r   zPyJWT._validate_iat  sX    	gen%C
 #,()KLL  	  	&;	   $ :c                z    	 t        |d         }|||z   kD  rt        d      y # t        $ r t        d      d w xY w)NrL   z*Not Before claim (nbf) must be an integer.z The token is not yet valid (nbf))r   r   r   r   )r3   rY   r   rn   rL   s        r4   r   zPyJWT._validate_nbf  sW    	Vgen%C #,()KLL    	VJKQUU	Vr   c                z    	 t        |d         }|||z
  k  rt        d      y # t        $ r t        d      d w xY w)NrJ   z/Expiration Time claim (exp) must be an integer.zSignature has expired)r   r   r   r   )r3   rY   r   rn   rJ   s        r4   r   zPyJWT._validate_exp  sX    	gen%C 3< '(?@@ !  	A	r   Fr   c                  |d|vs|d   sy t        d      d|vs|d   st        d      |d   |rGt        |t              st        d      t        t              st        d      |k7  rt        d      y t        t              rgt        t              st        d      t        d D              rt        d      t        |t              r|g}t        fd|D              rt        d	      y )
NaudzInvalid audiencezInvalid audience (strict)z&Invalid claim format in token (strict)zAudience doesn't match (strict)zInvalid claim format in tokenc              3  >   K   | ]  }t        |t                 y wr   )rQ   rV   ).0cs     r4   	<genexpr>z&PyJWT._validate_aud.<locals>.<genexpr>*  s     ?!:a%%?s   c              3  &   K   | ]  }|v 
 y wr   rC   )r   r   audience_claimss     r4   r   z&PyJWT._validate_aud.<locals>.<genexpr>0  s     >cs/)>s   zAudience doesn't match)r   r   rQ   rV   listanyall)r3   rY   rl   r   r   s       @r4   r   zPyJWT._validate_aud  s
    G#75> ''9::wu~ ,E22!%. h,*+FGG os3*+STT?**+LMMos+./O/40&'FGG???&'FGGh$ zH>X>>&'?@@ ?r6   c                    |y d|vrt        d      |d   }t        |t              st        d      t        |t              r||k7  rt        d      y 	 ||vrt        d      y # t        $ r t        d      d w xY w)NrM   z%Payload Issuer (iss) must be a stringzInvalid issuerz.Issuer param must be "str" or "Container[str]")r   rQ   rV   r   rS   )r3   rY   rm   rM   s       r4   r   zPyJWT._validate_iss3  s     >+E22en#s#$%LMMfc"f}()9:: f$,-=>> % (Ds   A% %A;r   )r-   Options | NonereturnNone)r   r%   )r   r'   )r-   r   r   r%   )rY   dict[str, Any]rZ   r(   r[   
str | NonerN   dict[str, Any] | NonerO   type[json.JSONEncoder] | NonerP   boolr   rV   )NN)rY   r   rN   r   rO   r   r   bytes)	r   NNNNNNNr   )rx   str | bytesrZ   r)   rj   Sequence[str] | Noner-   r   ry   bool | Nonerk   bytes | Nonerl   str | Iterable[str] | Nonerm   str | Container[str] | Nonero   r   rn   float | timedeltarz   r   r   r   )r}   r   r   r   )rx   r   rZ   z'AllowedPublicKeys | PyJWK | str | bytesrj   r   r-   r   ry   r   rk   r   rl   r   ro   r   rm   r   rn   r   rz   r   r   r   )NNNr   )rY   r   r-   r%   rl   zIterable[str] | str | Nonerm   Container[str] | str | Nonero   r   rn   r   r   r   )rY   r   r   zIterable[str]r   r   )rY   r   ro   r   r   r   )rY   r   r   r   )rY   r   r   floatrn   r   r   r   )rY   r   rl   r   r   r   r   r   )rY   r   rm   r   r   r   )__name__
__module____qualname__r5   staticmethodr.   r0   r/   r   rX   rW   ru   rv   r   rw   r   r   r   r   r   r   r   r   rC   r6   r4   r+   r+   *   s   ; 
 

+& !1)-6:!@
@
 $@
 	@

 '@
 4@
 @
 
@
J *.6:	 ' 4	
 
* &(+/"&")- 04.2"$%oo #o )	o
  o o 'o -o ,o o "o" #o$ 
%ob& 8:+/"&")- 04".2$%M8M8 5M8 )	M8
  M8 M8 'M8 -M8 M8 ,M8 "M8" #M8$ 
%M8f 04.2"$%(((( (( -	((
 ,(( (( "(( 
((T77 7 
	7 >B=%=0:=	=*=MM M 	M
 
MMM M 	M
 
MAA A 	A
 
A* 0A0A -0A
 0A 
0Ad%/J	r6   r+   )<
__future__r   rc   osrp   calendarr   collections.abcr   r   r   r   r	   r
   typingr   r   r   r   api_jwsr   r   r   
exceptionsr   r   r   r   r   r   r   r   r   r   r   getenvsysversion_infor!   typing_extensionsrj   r"   r#   api_jwkr$   typesr%   r&   r'   rV   r   r(   __annotations__r)   r+   _jwt_global_objr1   rX   ru   r   rC   r6   r4   <module>r      s    "  	   9 9 2 2 2 2 = =
 
 
 -D>267
7"$ 	0A77(-.@%e.S(TIT',->sE-Q'R9R` `F '& 			!11			r6   