o
    T۷i
                     @  s   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
 d
ZG dd dZG dd dZdS )    )annotationsN)Iterator)Any   )get_default_algorithms
has_cryptorequires_cryptography)InvalidKeyErrorMissingCryptographyError
PyJWKErrorPyJWKSetError
PyJWTError)JWKDictc                   @  sb   e Zd Zdddd	ZeddddZeddddZedddZedddZ	edddZ
dS )PyJWKNjwk_datar   	algorithm
str | NonereturnNonec                 C  sr  || _ | j dd}|std| j  |s#t| j tr#| j dd}|s| j dd}|dkrU|dks6|s9d}nM|d	kr@d
}nF|dkrGd}n?|dkrNd}n8td| |dkr\d}n*|dkrcd}n#|dkr|sqtd| j  |dkrxd}ntd| td| ts|tv rt| d|| _zt	 | | _
W n ty   td| j  d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    r/   A/home/ubuntu/vllm_env/lib/python3.10/site-packages/jwt/api_jwk.py__init__   sX   
zPyJWK.__init__objc                 C  s
   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   )r2   r   r/   r/   r0   	from_dictT   s   

zPyJWK.from_dictdatastrc                 C  s   t | }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   r3   )r4   r   r2   r/   r/   r0   	from_json`   s   
zPyJWK.from_jsonc                 C     | j ddS )zFThe `kty` property from the JWK.

        :rtype: str or None
        r   Nr%   r&   r.   r/   r/   r0   key_typen      zPyJWK.key_typec                 C  r9   )zFThe `kid` property from the JWK.

        :rtype: str or None
        kidNr:   r;   r/   r/   r0   key_idv   r=   zPyJWK.key_idc                 C  r9   )zFThe `use` property from the JWK.

        :rtype: str or None
        useNr:   r;   r/   r/   r0   public_key_use~   r=   zPyJWK.public_key_useN)r   r   r   r   r   r   )r2   r   r   r   r   r   )r4   r5   r   r   r   r   )r   r   )__name__
__module____qualname__r1   staticmethodr3   r8   propertyr<   r?   rA   r/   r/   r/   r0   r      s    @r   c                   @  sF   e Zd ZdddZedd	d
ZedddZdddZdddZdS )PyJWKSetkeyslist[JWKDict]r   r   c                 C  s   g | _ |s	tdt|tstd|D ]%}z
| j t| W q ty9 } zt|tr/|W Y d }~qd }~ww t| j dkrEt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?)	rI   r   r'   listappendr   r   r
   len)r.   rI   r-   errorr/   r/   r0   r1      s&   

zPyJWKSet.__init__r2   dict[str, Any]c                 C  s   |  dg }t|S )NrI   )r&   rH   )r2   rI   r/   r/   r0   r3      s   zPyJWKSet.from_dictr4   r5   c                 C  s   t | }t|S rB   )r6   r7   rH   r3   )r4   r2   r/   r/   r0   r8      s   

zPyJWKSet.from_jsonr>   r   c                 C  s,   | j D ]}|j|kr|  S qtd| )Nzkeyset has no key for kid: )rI   r?   r+   )r.   r>   r-   r/   r/   r0   __getitem__   s
   

zPyJWKSet.__getitem__Iterator[PyJWK]c                 C  s
   t | jS rB   )iterrI   r;   r/   r/   r0   __iter__   s   
zPyJWKSet.__iter__N)rI   rJ   r   r   )r2   rO   r   rH   )r4   r5   r   rH   )r>   r5   r   r   )r   rQ   )	rC   rD   rE   r1   rF   r3   r8   rP   rS   r/   r/   r/   r0   rH      s    

rH   c                   @  s*   e Zd ZdddZdddZdd	d
ZdS )PyJWTSetWithTimestampjwk_setrH   c                 C  s   || _ t | _d S rB   )rU   time	monotonic	timestamp)r.   rU   r/   r/   r0   r1      s   zPyJWTSetWithTimestamp.__init__r   c                 C     | j S rB   )rU   r;   r/   r/   r0   get_jwk_set      z!PyJWTSetWithTimestamp.get_jwk_setfloatc                 C  rY   rB   )rX   r;   r/   r/   r0   get_timestamp   r[   z#PyJWTSetWithTimestamp.get_timestampN)rU   rH   )r   rH   )r   r\   )rC   rD   rE   r1   rZ   r]   r/   r/   r/   r0   rT      s    

rT   )
__future__r   r6   rV   collections.abcr   typingr   
algorithmsr   r   r   
exceptionsr	   r
   r   r   r   typesr   r   rH   rT   r/   r/   r/   r0   <module>   s    t,