o
    syi                     @  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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    r/   N/home/ubuntu/maya3_transcribe/venv/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   )r2   r   r/   r/   r0   	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   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_typem      zPyJWK.key_typec                 C  r9   )zFThe `kid` property from the JWK.

        :rtype: str or None
        kidNr:   r;   r/   r/   r0   key_idu   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?   KeyError)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   rR   )	rC   rD   rE   r1   rF   r3   r8   rQ   rT   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   )rV   time	monotonic	timestamp)r.   rV   r/   r/   r0   r1      s   zPyJWTSetWithTimestamp.__init__r   c                 C     | j S rB   )rV   r;   r/   r/   r0   get_jwk_set      z!PyJWTSetWithTimestamp.get_jwk_setfloatc                 C  rZ   rB   )rY   r;   r/   r/   r0   get_timestamp   r\   z#PyJWTSetWithTimestamp.get_timestampN)rV   rH   )r   rH   )r   r]   )rC   rD   rE   r1   r[   r^   r/   r/   r/   r0   rU      s    

rU   )
__future__r   r6   rW   collections.abcr   typingr   
algorithmsr   r   r   
exceptionsr	   r
   r   r   r   typesr   r   rH   rU   r/   r/   r/   r0   <module>   s    s,