o
    h Ž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 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Ú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   úUC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\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
        N)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
        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_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,