
    `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                   t                      | _        || _        | 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          || _
        || j        v r| j        |         | _        nt          d| j                   | 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: )r   _algorithms	_jwk_datagetr
   
isinstancedictr   r	   r   algorithm_name	Algorithmr   from_jwkkey)selfr   r   r   r   s        _/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/jwt/api_jwk.py__init__zPyJWK.__init__   s%    233!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   ((((!-i8DNNUT^UUVVV>**4>::    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   )r5   r   s     r2   	from_dictzPyJWK.from_dictS   s     S)$$$r4   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   r7   )r8   r   r5   s      r2   	from_jsonzPyJWK.from_json_   s'     jsI...r4   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_typem        ~!!%...r4   c                8    | j                             dd          S )zFThe `kid` property from the JWK.

        :rtype: str or None
        kidNr?   r@   s    r2   key_idzPyJWK.key_idu   rB   r4   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   r4   N)r   r   r   r   r   r   )r5   r   r   r   r   r   )r8   r9   r   r   r   r   )r   r   )__name__
__module____qualname__r3   staticmethodr7   r=   propertyrA   rE   rH    r4   r2   r   r      s        =; =; =; =; =;~ 	% 	% 	% 	% \	% / / / / \/ / / / X/ / / / X/ / / / X/ / /r4   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r5   dict[str, Any]c                L    |                      dg           }t          |          S )NrR   )r*   rQ   )r5   rR   s     r2   r7   zPyJWKSet.from_dict   s!    wwvr""~~r4   r8   r9   c                ^    t          j        |           }t                              |          S rI   )r;   r<   rQ   r7   )r8   r5   s     r2   r=   zPyJWKSet.from_json   s%    j!!#&&&r4   rD   r   c                X    | j         D ]}|j        |k    r|c S t          d|           )Nzkeyset has no key for kid: )rR   rE   KeyError)r1   rD   r0   s      r2   __getitem__zPyJWKSet.__getitem__   sE    9 	 	CzS  


 !:S::;;;r4   Iterator[PyJWK]c                *    t          | j                  S rI   )iterrR   r@   s    r2   __iter__zPyJWKSet.__iter__   s    DIr4   N)rR   rS   r   r   )r5   rY   r   rQ   )r8   r9   r   rQ   )rD   r9   r   r   )r   r_   )	rJ   rK   rL   r3   rM   r7   r=   r^   rb   rO   r4   r2   rQ   rQ      s           .    \ ' ' ' \'< < < <     r4   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   )re   time	monotonic	timestamp)r1   re   s     r2   r3   zPyJWTSetWithTimestamp.__init__   s    ))r4   r   c                    | j         S rI   )re   r@   s    r2   get_jwk_setz!PyJWTSetWithTimestamp.get_jwk_set   s
    |r4   floatc                    | j         S rI   )ri   r@   s    r2   get_timestampz#PyJWTSetWithTimestamp.get_timestamp   s
    ~r4   N)re   rQ   )r   rQ   )r   rl   )rJ   rK   rL   r3   rk   rn   rO   r4   r2   rd   rd      sP        * * * *        r4   rd   )
__future__r   r;   rg   collections.abcr   typingr   
algorithmsr   r   r	   
exceptionsr
   r   r   r   r   typesr   r   rQ   rd   rO   r4   r2   <module>ru      sQ   " " " " " "   $ $ $ $ $ $       Q Q Q Q Q Q Q Q Q Q                   p/ p/ p/ p/ p/ p/ p/ p/f) ) ) ) ) ) ) )X	 	 	 	 	 	 	 	 	 	r4   