
    `i}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 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j"        dd                    rd dl#Z#e#j$        dk    rd dlm%Z% nd dl&m%Z% ddl'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z. e(r+ddl'm/Z/m0Z0 ee/e*e1e2f         Z3de4d<   ee0e*e1e2f         Z5de4d<   n ee*e1e2f         Z3de4d<   ee*e1e2f         Z5de4d<    G d d          Z6 e6            Z7ee7_8        e7j9        Z9e7j:        Z:e7j;        Z;dS )    )annotationsN)timegm)	ContainerIterableSequence)datetime	timedeltatimezone)TYPE_CHECKINGAnyUnioncast   )PyJWS_jws_global_obj)	DecodeErrorExpiredSignatureErrorImmatureSignatureErrorInvalidAudienceErrorInvalidIssuedAtErrorInvalidIssuerErrorInvalidJTIErrorInvalidSubjectErrorMissingRequiredClaimError)RemovedInPyjwt3WarningSPHINX_BUILD )   
   )	TypeAlias)
has_crypto)PyJWK)FullOptionsOptions
SigOptions)AllowedPrivateKeysAllowedPublicKeysr    AllowedPrivateKeyTypesAllowedPublicKeyTypesc                      e Zd ZdIdJdZedKd            ZdLd
ZdIdMdZ	 	 	 	 dNdOdZ	 	 dPdQdZ		 	 	 	 	 	 	 	 	 dRdSd2Z
dTd4Z	 	 	 	 	 	 	 	 	 dRdUd6Z	 	 	 	 dVdWd9ZdXd<Z	 dIdYd=ZdZd>Zd[dAZd[dBZd[dCZdDdEd\dGZd]dHZdS )^PyJWTNoptionsOptions | NonereturnNonec                    |  |                                  | _        ||                     |          | _        t          |                                           | _        d S )N)r,   )_get_default_optionsr,   _merge_optionsr   _get_sig_options_jwsselfr,   s     _/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/jwt/api_jwt.py__init__zPyJWT.__init__1   sX    !0022..w77DL$"7"7"9"9:::			    r#   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 rF   r9   r7   r1   zPyJWT._get_default_options9   s4     !%*/
 
 	
r9   r%   c                T    | j         d         | j                             dd          dS )Nr;   rE   F)r;   rE   r,   get)r6   s    r7   r3   zPyJWT._get_sig_optionsI   s6     $-? @*.,*:*:,e+ +
 
 	
r9   c                   || j         S |                    dd          s|                    dd          |d<   |                    dd          |d<   |                    dd          |d<   |                    dd          |d<   |                    dd          |d<   |                    d	d          |d	<   |                    d
d          |d
<   i | j         |S )Nr;   Tr<   Fr=   r>   r?   r@   rA   rB   rH   r5   s     r7   r2   zPyJWT._merge_optionsQ   s    ?< {{-t44 	E$+KKe$D$DGL!$+KKe$D$DGL!$+KKe$D$DGL!$+KKe$D$DGL!$+KKe$D$DGL!$+KKe$D$DGL!$+KKe$D$DGL!*$,*'**r9   HS256Tpayloaddict[str, Any]keyr(   	algorithm
str | Noneheadersdict[str, Any] | Nonejson_encodertype[json.JSONEncoder] | Nonesort_headersboolstrc                   t          |t                    st          d          |                                }dD ]T}t          |                    |          t
                    r*t          ||                                                   ||<   Ud|v r*t          |d         t                    st          d          | 	                    |||          }| 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.)rQ   rS   )rU   )
isinstancedict	TypeErrorcopyrI   r   r   utctimetuplerW   _encode_payloadr4   encode)	r6   rL   rN   rO   rQ   rS   rU   
time_claimjson_payloads	            r7   rc   zPyJWT.encode`   s   D '4(( 	,   ,,../ 	Q 	QJ'++j118<< Q&,WZ-@-M-M-O-O&P&P
# GJwu~s$C$C<===++% , 
 
 y%   
 
 	
r9   bytesc                V    t          j        |d|                              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dumpsrc   )r6   rL   rQ   rS   s       r7   rb   zPyJWT._encode_payload   s3     z!
 
 
 &//		r9   r   r   jwtstr | bytesr)   
algorithmsSequence[str] | Noneverifybool | Nonedetached_payloadbytes | Noneaudiencestr | Iterable[str] | Noneissuerstr | Container[str] | Nonesubjectleewayfloat | timedeltakwargsr   c                   |r>t          j        dt          |                                           t          d           |d}n|                    dd          }|"||k    rt          j        dt          d           |                     |          }d|i}| 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:    
stacklevelNTr;   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.)categoryr   )rN   rp   r,   rt   )rv   rx   r{   rz   rL   )warningswarntuplekeysr   rI   DeprecationWarningr2   r4   decode_complete_decode_payload_validate_claims)r6   rn   rN   rp   r,   rr   rt   rv   rx   rz   r{   r}   r;   merged_optionssig_optionsdecodedrL   s                    r7   r   zPyJWT.decode_complete   sU   r  	M>',V[[]]';';> > '    ?#&{{+=tDD
 &,<"<"<MY ,    ,,W55  0#
 )++!- , 
 
 &&w// 	 	
 	
 	
 %	r9   r   c                    	 t          j        |d                   }n%# t          $ r}t          d|           |d}~ww xY wt	          |t
                    st          d          |S )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.
        rL   zInvalid payload string: Nz-Invalid payload string: must be a json object)rl   loads
ValueErrorr   r]   r^   )r6   r   rL   es       r7   r   zPyJWT._decode_payload"  s    	E&*j1C&D&DGG 	E 	E 	E<<<==1D	E'4(( 	OMNNNs    
?:?'AllowedPublicKeys | PyJWK | str | bytesc                   |r>t          j        dt          |                                           t          d           |                     |||||||||	|

  
        }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: r   r   )rr   rt   rv   rz   rx   r{   rL   )
r   r   r   r   r   r   r   r^   rW   r   )r6   rn   rN   rp   r,   rr   rt   rv   rz   rx   r{   r}   r   s                r7   decodezPyJWT.decode2  s    r  	M>',V[[]]';';> > '    &&- ' 
 
 DcNGI$6777r9   Iterable[str] | str | NoneContainer[str] | str | Nonec                <   t          |t                    r|                                }|+t          |t          t          f          st          d          |                     ||d                    t          j        t          j
                                                  }d|v r|d         r|                     |||           d|v r|d         r|                     |||           d|v r|d	         r|                     |||           |d
         r|                     ||           |d         r,|                     |||                    dd                     |d         r|                     ||           |d         r|                     |           d S d S )Nz+audience must be a string, iterable or NonerC   )tzrZ   r>   r[   r=   rY   r<   r@   r?   rD   FstrictrA   rB   )r]   r	   total_secondsrW   r   r_   _validate_required_claimsr   nowr
   utc	timestamp_validate_iat_validate_nbf_validate_exp_validate_iss_validate_audrI   _validate_sub_validate_jti)r6   rL   r,   rv   rx   rz   r{   r   s           r7   r   zPyJWT._validate_claims  s    fi(( 	,))++F
8c8_(M(MIJJJ&&w	0BCCClhl+++5577G 5wV444G 5wV444G 5wV444<  	0w///<  	'++lE*J*J     <  	1w000<  	(w'''''	( 	(r9   claimsIterable[str]c                X    |D ]&}|                     |          t          |          'd S N)rI   r   )r6   rL   r   claims       r7   r   zPyJWT._validate_required_claims  sB    
  	7 	7E{{5!!)/666 *	7 	7r9   c                    d|vrdS t          |d         t                    st          d          |(|                    d          |k    rt          d          dS dS )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)r]   rW   r   rI   )r6   rL   rz   s      r7   r   zPyJWT._validate_sub  st     F'%.#.. 	B%&@AAA{{5!!W,,)*;<<< ,,r9   c                    d|vrdS t          |                    d          t                    st          d          dS )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)r]   rI   rW   r   )r6   rL   s     r7   r   zPyJWT._validate_jti  sK     F'++e,,c22 	=!";<<<	= 	=r9   r   floatc                    	 t          |d                   }n# t          $ r t          d          d w xY w|||z   k    rt          d          d S )NrZ   z)Issued At claim (iat) must be an integer.z The token is not yet valid (iat))intr   r   r   )r6   rL   r   r{   rZ   s        r7   r   zPyJWT._validate_iat  su    	gen%%CC 	 	 	&; 	 #,()KLLL      3c                    	 t          |d                   }n# t          $ r t          d          d w xY w|||z   k    rt          d          d S )Nr[   z*Not Before claim (nbf) must be an integer.z The token is not yet valid (nbf))r   r   r   r   )r6   rL   r   r{   r[   s        r7   r   zPyJWT._validate_nbf  st    	Vgen%%CC 	V 	V 	VJKKQUU	V #,()KLLL  r   c                    	 t          |d                   }n# t          $ r t          d          d w xY w|||z
  k    rt          d          d S )NrY   z/Expiration Time claim (exp) must be an integer.zSignature has expired)r   r   r   r   )r6   rL   r   r{   rY   s        r7   r   zPyJWT._validate_exp  su    	gen%%CC 	 	 	A 	
 3<  '(?@@@ ! r   Fr   r   c                  |d|vs|d         sd S t          d          d|vs|d         st          d          |d         |r_t          |t                    st          d          t          t                    st          d          |k    rt          d          d S 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	          d S )
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  B   K   | ]}t          |t                     V  d S r   )r]   rW   ).0cs     r7   	<genexpr>z&PyJWT._validate_aud.<locals>.<genexpr>-  s/      ??!:a%%%??????r9   c              3      K   | ]}|vV  	d S r   rF   )r   r   audience_claimss     r7   r   z&PyJWT._validate_aud.<locals>.<genexpr>3  s(      >>cs/)>>>>>>r9   zAudience doesn't match)r   r   r]   rW   listanyall)r6   rL   rv   r   r   s       @r7   r   zPyJWT._validate_aud  s    G##75># ''9:::wu~ ,E222!%.  	h,, H*+FGGG os33 U*+STTT?***+LMMMFos++ 	0./O/400 	H&'FGGG??????? 	H&'FGGGh$$ 	" zH>>>>X>>>>> 	A&'?@@@	A 	Ar9   c                H   |d S d|vrt          d          |d         }t          |t                    st          d          t          |t                    r||k    rt          d          d S 	 ||vrt          d          d S # t          $ r t          d          d w xY w)Nr\   z%Payload Issuer (iss) must be a stringzInvalid issuerz.Issuer param must be "str" or "Container[str]")r   r]   rW   r   r_   )r6   rL   rx   r\   s       r7   r   zPyJWT._validate_iss6  s     >F+E222en#s## 	N$%LMMMfc"" 
	f}}()9::: }f$$,-=>>> %$   (D s   1B B!r   )r,   r-   r.   r/   )r.   r#   )r.   r%   )r,   r-   r.   r#   )rK   NNT)rL   rM   rN   r(   rO   rP   rQ   rR   rS   rT   rU   rV   r.   rW   )NN)rL   rM   rQ   rR   rS   rT   r.   rf   )	r   NNNNNNNr   )rn   ro   rN   r)   rp   rq   r,   r-   rr   rs   rt   ru   rv   rw   rx   ry   rz   rP   r{   r|   r}   r   r.   rM   )r   rM   r.   rM   )rn   ro   rN   r   rp   rq   r,   r-   rr   rs   rt   ru   rv   rw   rz   rP   rx   ry   r{   r|   r}   r   r.   rM   )NNNr   )rL   rM   r,   r#   rv   r   rx   r   rz   rP   r{   r|   r.   r/   )rL   rM   r   r   r.   r/   )rL   rM   rz   rP   r.   r/   )rL   rM   r.   r/   )rL   rM   r   r   r{   r   r.   r/   )rL   rM   rv   rw   r   rV   r.   r/   )rL   rM   rx   r   r.   r/   )__name__
__module____qualname__r8   staticmethodr1   r3   r2   rc   rb   r   r   r   r   r   r   r   r   r   r   r   r   rF   r9   r7   r+   r+   0   sM       ; ; ; ; ; 
 
 
 \

 
 
 
+ + + + +& !()-6:!@
 @
 @
 @
 @
J *.6:	    * &(+/"&")- 04.2"$%l l l l l\   & 8:+/"&")- 04".2$%M8 M8 M8 M8 M8f 04.2"$%(( (( (( (( ((T7 7 7 7 >B= = = = =*= = = =M M M MM M M MA A A A* 0A 0A 0A 0A 0A 0Ad     r9   r+   )<
__future__r   rl   osr   calendarr   collections.abcr   r   r   r   r	   r
   typingr   r   r   r   api_jwsr   r   
exceptionsr   r   r   r   r   r   r   r   r   r   rV   getenvsysversion_infor    typing_extensionsrp   r!   api_jwkr"   typesr#   r$   r%   r&   r'   rW   rf   r(   __annotations__r)   r+   _jwt_global_objr4   rc   r   r   rF   r9   r7   <module>r      s   " " " " " " "  				        9 9 9 9 9 9 9 9 9 9 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + + + + + + + +
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 - , , , , , DDD>26677 DJJJ
7""$$$$$$$ 	0/////&&&&&&7777777777 DEEEEEEEE,12DeSRW2W,XXXXX+01BE3PU1U+VVVVVV,1%e2C,DDDDD+0U1B+CCCCC] ] ] ] ] ] ] ]@ %''& 		!1		r9   