o
    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  sp  t  | _|| _| jdd}|std| j |s't| jtr'| jdd}|s| jdd}|dkrY|dks:|s=d}nM|d	krDd
}nF|dkrKd}n?|dkrRd}n8td| |dkr`d}n*|dkrgd}n#|dkr|sutd| j |dkr|d}ntd| td| ts|tv rt	| 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crvZECzP-256ZES256zP-384ZES384zP-521ZES512Z	secp256k1ZES256KzUnsupported crv: ZRSAZRS256octZHS256ZOKPzcrv is not found: ZEd25519ZEdDSAzUnsupported kty: z) requires 'cryptography' to be installed.z%Unable to find an algorithm for key: )r   Z_algorithms	_jwk_datagetr	   
isinstancedictr   r   r
   Zalgorithm_nameZ	Algorithmr   Zfrom_jwkkey)selfr   r   r   r    r   B/home/app/Keep/.python/lib/python3.10/site-packages/jwt/api_jwk.py__init__   sN   
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   )r"   r   r   r   r    	from_dictS   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   r#   )r$   r   r"   r   r   r    	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   r    key_typem      zPyJWK.key_typec                 C  r)   )zFThe `kid` property from the JWK.

        :rtype: str or None
        kidNr*   r+   r   r   r    key_idu   r-   zPyJWK.key_idc                 C  r)   )zFThe `use` property from the JWK.

        :rtype: str or None
        ZuseNr*   r+   r   r   r    public_key_use}   r-   zPyJWK.public_key_useN)r   r   r   r   r   r   )r"   r   r   r   r   r   )r$   r%   r   r   r   r   )r   r   )__name__
__module____qualname__r!   staticmethodr#   r(   propertyr,   r/   r0   r   r   r   r    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?)	r8   r   r   listappendr   r   r
   len)r   r8   r   errorr   r   r    r!      s&   

zPyJWKSet.__init__r"   dict[str, Any]c                 C  s   |  dg }t|S )Nr8   )r   r7   )r"   r8   r   r   r    r#      s   zPyJWKSet.from_dictr$   r%   c                 C  s   t | }t|S r1   )r&   r'   r7   r#   )r$   r"   r   r   r    r(      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: )r8   r/   KeyError)r   r.   r   r   r   r    __getitem__   s
   

zPyJWKSet.__getitem__Iterator[PyJWK]c                 C  s
   t | jS r1   )iterr8   r+   r   r   r    __iter__   s   
zPyJWKSet.__iter__N)r8   r9   r   r   )r"   r>   r   r7   )r$   r%   r   r7   )r.   r%   r   r   )r   rA   )	r2   r3   r4   r!   r5   r#   r(   r@   rC   r   r   r   r    r7      s    

r7   c                   @  s*   e Zd ZdddZdddZdd	d
ZdS )PyJWTSetWithTimestampjwk_setr7   c                 C  s   || _ t | _d S r1   )rE   time	monotonic	timestamp)r   rE   r   r   r    r!      s   zPyJWTSetWithTimestamp.__init__r   c                 C     | j S r1   )rE   r+   r   r   r    get_jwk_set      z!PyJWTSetWithTimestamp.get_jwk_setfloatc                 C  rI   r1   )rH   r+   r   r   r    get_timestamp   rK   z#PyJWTSetWithTimestamp.get_timestampN)rE   r7   )r   r7   )r   rL   )r2   r3   r4   r!   rJ   rM   r   r   r   r    rD      s    

rD   )
__future__r   r&   rF   collections.abcr   typingr   Z
algorithmsr   r   r   
exceptionsr	   r
   r   r   r   typesr   r   r7   rD   r   r   r   r    <module>   s    s,