
    1
i
                        d dl mZ d dlZd dlZd dlmZ d dlmZ ddlm	Z	m
Z
mZ ddlmZmZmZmZmZ ddlmZ  G d	 d
          Z G d d          Z G d d          ZdS )    )annotationsN)Iterator)Any   )get_default_algorithms
has_cryptorequires_cryptography)InvalidKeyErrorMissingCryptographyError
PyJWKErrorPyJWKSetError
PyJWTError)JWKDictc                      e Zd ZdddZeddd
            Zeddd            Zedd            Zedd            Z	edd            Z
dS )PyJWKNjwk_datar   	algorithm
str | NonereturnNonec                x   || _         | j                             dd          }|st          d| j                    |s5t          | j         t                    r| j                             dd          }|s| j                             dd          }|dk    r8|dk    s|sd}n|d	k    rd
}n|dk    rd}ny|dk    rd}npt          d|           |dk    rd}nU|dk    rd}nL|dk    r4|st          d| j                    |dk    rd}n$t          d|           t          d|           t
          s|t          v rt          | d          || _        	 t                      |         | _
        n&# t          $ r t          d| j                    dw xY w| j
                            | j                   | _        dS )a  A class that represents a `JSON Web Key <https://www.rfc-editor.org/rfc/rfc7517>`_.

        :param jwk_data: The decoded JWK data.
        :type jwk_data: dict[str, typing.Any]
        :param algorithm: The key algorithm. If not specified, the key's ``alg`` will be used.
        :type algorithm: str or None
        :raises InvalidKeyError: If the key type (``kty``) is not found or unsupported, or if the curve (``crv``) is not found or unsupported.
        :raises MissingCryptographyError: If the algorithm requires ``cryptography`` to be installed and it is not available.
        :raises PyJWKError: If unable to find an algorithm for the key.
        ktyNzkty is not found: algcrvECzP-256ES256zP-384ES384zP-521ES512	secp256k1ES256KzUnsupported crv: RSARS256octHS256OKPzcrv is not found: Ed25519EdDSAzUnsupported kty: z) requires 'cryptography' to be installed.z%Unable to find an algorithm for key: )	_jwk_datagetr
   
isinstancedictr   r	   r   algorithm_namer   	AlgorithmKeyErrorr   from_jwkkey)selfr   r   r   r   s        C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\jwt/api_jwk.py__init__zPyJWK.__init__   s7    "n  -- 	I!"Gt~"G"GHHH 	8Z== 	8**5$77I 	A.$$UD11Cd{{'>>> 'IIG^^ 'IIG^^ 'IIK'' (II)*Cc*C*CDDD#		#		 Q)*Ot~*O*OPPP)## 'II)*Cc*C*CDDD%&?#&?&?@@@ 	i+@@@*GGG   (	355i@DNN 	 	 	HHH 	
 >**4>::s   E0 0#Fobjc                "    t          | |          S )a;  Creates a :class:`PyJWK` object from a JSON-like dictionary.

        :param obj: The JWK data, as a dictionary
        :type obj: dict[str, typing.Any]
        :param algorithm: The key algorithm. If not specified, the key's ``alg`` will be used.
        :type algorithm: str or None
        :rtype: PyJWK
        )r   )r4   r   s     r2   	from_dictzPyJWK.from_dictT   s     S)$$$    datastrc                `    t          j        |           }t                              ||          S )aE  Create a :class:`PyJWK` object from a JSON string.
        Implicitly calls :meth:`PyJWK.from_dict()`.

        :param str data: The JWK data, as a JSON string.
        :param algorithm:  The key algorithm.  If not specific, the key's ``alg`` will be used.
        :type algorithm: str or None

        :rtype: PyJWK
        )jsonloadsr   r6   )r8   r   r4   s      r2   	from_jsonzPyJWK.from_json`   s'     jsI...r7   c                8    | j                             dd          S )zFThe `kty` property from the JWK.

        :rtype: str or None
        r   Nr(   r)   r1   s    r2   key_typezPyJWK.key_typen        ~!!%...r7   c                8    | j                             dd          S )zFThe `kid` property from the JWK.

        :rtype: str or None
        kidNr?   r@   s    r2   key_idzPyJWK.key_idv   rB   r7   c                8    | j                             dd          S )zFThe `use` property from the JWK.

        :rtype: str or None
        useNr?   r@   s    r2   public_key_usezPyJWK.public_key_use~   rB   r7   N)r   r   r   r   r   r   )r4   r   r   r   r   r   )r8   r9   r   r   r   r   )r   r   )__name__
__module____qualname__r3   staticmethodr6   r=   propertyrA   rE   rH    r7   r2   r   r      s        >; >; >; >; >;@ 	% 	% 	% 	% \	% / / / / \/ / / / X/ / / / X/ / / / X/ / /r7   r   c                  V    e Zd ZddZedd            Zedd            ZddZddZdS )PyJWKSetkeyslist[JWKDict]r   r   c                   g | _         |st          d          t          |t                    st          d          |D ]X}	 | j                             t          |                     +# t          $ r!}t          |t                    r|Y d }~Qd }~ww xY wt          | j                   dk    rt          d          d S )Nz$The JWK Set did not contain any keyszInvalid JWK Set valuer   zUThe JWK Set did not contain any usable keys. Perhaps 'cryptography' is not installed?)	rR   r   r*   listappendr   r   r   len)r1   rR   r0   errors       r2   r3   zPyJWKSet.__init__   s    !#	 	H FGGG$%% 	9 7888 	 	C	  s,,,,   e%=>>  K	 ty>>Qg   s   'A**
B4BBr4   dict[str, Any]c                L    |                      dg           }t          |          S )NrR   )r)   rQ   )r4   rR   s     r2   r6   zPyJWKSet.from_dict   s!    wwvr""~~r7   r8   r9   c                ^    t          j        |           }t                              |          S rI   )r;   r<   rQ   r6   )r8   r4   s     r2   r=   zPyJWKSet.from_json   s%    j!!#&&&r7   rD   r   c                X    | j         D ]}|j        |k    r|c S t          d|           )Nzkeyset has no key for kid: )rR   rE   r.   )r1   rD   r0   s      r2   __getitem__zPyJWKSet.__getitem__   sE    9 	 	CzS  


 !:S::;;;r7   Iterator[PyJWK]c                *    t          | j                  S rI   )iterrR   r@   s    r2   __iter__zPyJWKSet.__iter__   s    DIr7   N)rR   rS   r   r   )r4   rY   r   rQ   )r8   r9   r   rQ   )rD   r9   r   r   )r   r^   )	rJ   rK   rL   r3   rM   r6   r=   r]   ra   rO   r7   r2   rQ   rQ      s           .    \ ' ' ' \'< < < <     r7   rQ   c                  &    e Zd Zd	dZd
dZddZdS )PyJWTSetWithTimestampjwk_setrQ   c                D    || _         t          j                    | _        d S rI   )rd   time	monotonic	timestamp)r1   rd   s     r2   r3   zPyJWTSetWithTimestamp.__init__   s    ))r7   r   c                    | j         S rI   )rd   r@   s    r2   get_jwk_setz!PyJWTSetWithTimestamp.get_jwk_set   s
    |r7   floatc                    | j         S rI   )rh   r@   s    r2   get_timestampz#PyJWTSetWithTimestamp.get_timestamp   s
    ~r7   N)rd   rQ   )r   rQ   )r   rk   )rJ   rK   rL   r3   rj   rm   rO   r7   r2   rc   rc      sP        * * * *        r7   rc   )
__future__r   r;   rf   collections.abcr   typingr   
algorithmsr   r   r	   
exceptionsr
   r   r   r   r   typesr   r   rQ   rc   rO   r7   r2   <module>rt      sQ   " " " " " "   $ $ $ $ $ $       Q Q Q Q Q Q Q Q Q Q                   q/ q/ q/ q/ q/ q/ q/ q/h) ) ) ) ) ) ) )X	 	 	 	 	 	 	 	 	 	r7   