
    qi}V                    Z   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jD                  dd            rwd dl#Z#e#jH                  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        e7jr                  Z9e7jt                  Z:e7jv                  Z;y)    )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dddZedd       ZddZdddZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 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     =/opt/pipecat/venv/lib/python3.12/site-packages/jwt/api_jwt.py__init__zPyJWT.__init__1   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_options9   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_optionsI   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?   rE   r2   s     r4   r/   zPyJWT._merge_optionsQ   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   c                   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copyrF   r   r   utctimetuplestr_encode_payloadr1   encode)	r3   payloadkey	algorithmrM   rN   rO   
time_claimjson_payloads	            r4   rW   zPyJWT.encode`   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dumpsrW   )r3   rX   rM   rN   s       r4   rV   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                  |      }d|i}| 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.)categoryrg   )rY   
algorithmsr-   detached_payload)audienceissuerleewaysubjectrX   )warningswarntuplekeysr   rF   DeprecationWarningr/   r1   decode_complete_decode_payload_validate_claims)r3   jwtrY   ri   r-   verifyrj   rk   rl   rn   rm   kwargsr8   merged_optionssig_optionsdecodedrX   s                    r4   rt   zPyJWT.decode_complete   s   r MM'',V[[]';&<> ' ?#&{{+=tD
 &,<"<MMY , ,,W5  0#
 ))++!- , 
 &&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.
        rX   zInvalid payload string: Nz-Invalid payload string: must be a json object)rb   loads
ValueErrorr   rP   rQ   )r3   r|   rX   es       r4   ru   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: re   rf   )rx   rj   rk   rn   rl   rm   rX   )
ro   rp   rq   rr   r   rt   r   rQ   rU   r   )r3   rw   rY   ri   r-   rx   rj   rk   rn   rl   rm   ry   r|   s                r4   decodezPyJWT.decode2  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@   )tzrJ   r;   rK   r:   rI   r9   r=   r<   rA   Fstrictr>   r?   )rP   r	   total_secondsrU   r   rR   _validate_required_claimsr   nowr
   utc	timestamp_validate_iat_validate_nbf_validate_exp_validate_iss_validate_audrF   _validate_sub_validate_jti)r3   rX   r-   rk   rl   rn   rm   r   s           r4   rv   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)rF   r   )r3   rX   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)rP   rU   r   rF   )r3   rX   rn   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)rP   rF   rU   r   )r3   rX   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)NrJ   z)Issued At claim (iat) must be an integer.z The token is not yet valid (iat))intr   r   r   )r3   rX   r   rm   rJ   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)NrK   z*Not Before claim (nbf) must be an integer.z The token is not yet valid (nbf))r   r   r   r   )r3   rX   r   rm   rK   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)NrI   z/Expiration Time claim (exp) must be an integer.zSignature has expired)r   r   r   r   )r3   rX   r   rm   rI   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   )rP   rU   ).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>3  s     >cs/)>s   zAudience doesn't match)r   r   rP   rU   listanyall)r3   rX   rk   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)NrL   z%Payload Issuer (iss) must be a stringzInvalid issuerz.Issuer param must be "str" or "Container[str]")r   rP   rU   r   rR   )r3   rX   rl   rL   s       r4   r   zPyJWT._validate_iss6  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#   )HS256NNT)rX   dict[str, Any]rY   r(   rZ   
str | NonerM   dict[str, Any] | NonerN   type[json.JSONEncoder] | NonerO   boolr   rU   )NN)rX   r   rM   r   rN   r   r   bytes)	r   NNNNNNNr   )rw   str | bytesrY   r)   ri   Sequence[str] | Noner-   r   rx   bool | Nonerj   bytes | Nonerk   str | Iterable[str] | Nonerl   str | Container[str] | Nonern   r   rm   float | timedeltary   r   r   r   )r|   r   r   r   )rw   r   rY   z'AllowedPublicKeys | PyJWK | str | bytesri   r   r-   r   rx   r   rj   r   rk   r   rn   r   rl   r   rm   r   ry   r   r   r   )NNNr   )rX   r   r-   r#   rk   zIterable[str] | str | Nonerl   Container[str] | str | Nonern   r   rm   r   r   r   )rX   r   r   zIterable[str]r   r   )rX   r   rn   r   r   r   )rX   r   r   r   )rX   r   r   floatrm   r   r   r   )rX   r   rk   r   r   r   r   r   )rX   r   rl   r   r   r   )__name__
__module____qualname__r5   staticmethodr.   r0   r/   rW   rV   rt   ru   r   rv   r   r   r   r   r   r   r   r   rC   r6   r4   r+   r+   0   s   ; 
 

+& !()-6:!@
@
 $@
 	@

 '@
 4@
 @
 
@
J *.6:	 ' 4	
 
* &(+/"&")- 04.2"$%ll #l )	l
  l l 'l -l ,l l "l" #l$ 
%l\& 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   rb   osro   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   r   getenvsysversion_infor    typing_extensionsri   r!   api_jwkr"   typesr#   r$   r%   r&   r'   rU   r   r(   __annotations__r)   r+   _jwt_global_objr1   rW   rt   r   rC   r6   r4   <module>r      s"   "  	   9 9 2 2 2 2 +
 
 
 -D>267
7"$ 	0&77E,12DeSRW2W,X	X+01BE3PU1U+VyV,1%e2C,D	D+0U1B+CyC] ]@ '& 			!11			r6   