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  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 r“t|› 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Ú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: )Ú	_jwk_dataÚgetr	   Ú
isinstanceÚdictr   r   r
   Zalgorithm_namer   Z	AlgorithmÚKeyErrorr   Zfrom_jwkÚkey)Úselfr   r   r   r   © r    úQC:\Users\psant\Downloads\PAF backend\school\venv\Lib\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
        N)r   )r#   r   r    r    r!   Ú	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
        N)Ú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_typen   ó   zPyJWK.key_typec                 C  r*   )zFThe `kid` property from the JWK.

        :rtype: str or None
        ÚkidNr+   r,   r    r    r!   Úkey_idv   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-   r0   r1   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?)	r9   r   r   ÚlistÚappendr   r   r
   Úlen)r   r9   r   Úerrorr    r    r!   r"   ˆ   s&   

€üÿÿzPyJWKSet.__init__r#   údict[str, Any]c                 C  s   |   dg ¡}t|ƒS )Nr9   )r   r8   )r#   r9   r    r    r!   r$   Ÿ   s   zPyJWKSet.from_dictr%   r&   c                 C  s   t  | ¡}t |¡S r2   )r'   r(   r8   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: )r9   r0   r   )r   r/   r   r    r    r!   Ú__getitem__©   s
   

ÿzPyJWKSet.__getitem__úIterator[PyJWK]c                 C  s
   t | jƒS r2   )Úiterr9   r,   r    r    r!   Ú__iter__¯   s   
zPyJWKSet.__iter__N)r9   r:   r   r   )r#   r?   r   r8   )r%   r&   r   r8   )r/   r&   r   r   )r   rA   )	r3   r4   r5   r"   r6   r$   r)   r@   rC   r    r    r    r!   r8   ‡   s    

r8   c                   @  s*   e Zd Zddd„Zddd„Zdd	d
„ZdS )ÚPyJWTSetWithTimestampÚjwk_setr8   c                 C  s   || _ t ¡ | _d S r2   )rE   ÚtimeÚ	monotonicÚ	timestamp)r   rE   r    r    r!   r"   ´   s   zPyJWTSetWithTimestamp.__init__r   c                 C  ó   | j S r2   )rE   r,   r    r    r!   Úget_jwk_set¸   ó   z!PyJWTSetWithTimestamp.get_jwk_setÚfloatc                 C  rI   r2   )rH   r,   r    r    r!   Úget_timestamp»   rK   z#PyJWTSetWithTimestamp.get_timestampN)rE   r8   )r   r8   )r   rL   )r3   r4   r5   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   r8   rD   r    r    r    r!   Ú<module>   s    t,