o
    "“ic  ã                   @  s’   d dl mZ d dlZd dl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)Ú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 )NÚktyz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.   úK/var/www/html/premium_crap/venv/lib/python3.10/site-packages/jwt/api_jwk.pyÚ__init__   sN   ÿ
zPyJWK.__init__Úobjc                 C  s
   t | |ƒS ©N)r   )r1   r   r.   r.   r/   Ú	from_dictH   s   
zPyJWK.from_dictÚdataÚstrc                 C  s   t  | ¡}t ||¡S r2   )ÚjsonÚloadsr   r3   )r4   r   r1   r.   r.   r/   Ú	from_jsonL   s   
zPyJWK.from_jsonc                 C  ó   | j  dd ¡S )Nr   ©r%   r&   ©r-   r.   r.   r/   Úkey_typeQ   ó   zPyJWK.key_typec                 C  r9   )NÚkidr:   r;   r.   r.   r/   Úkey_idU   r=   zPyJWK.key_idc                 C  r9   )NÚuser:   r;   r.   r.   r/   Úpublic_key_useY   r=   zPyJWK.public_key_user2   )r   r   r   r   r   r   )r1   r   r   r   r   r   )r4   r5   r   r   r   r   )r   r   )Ú__name__Ú
__module__Ú__qualname__r0   Ústaticmethodr3   r8   Úpropertyr<   r?   rA   r.   r.   r.   r/   r      s    5r   c                   @  s<   e Zd Zddd„Zedd	d
„ƒZe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?)	rH   r   r'   ÚlistÚappendr   r   r	   Úlen)r-   rH   r,   Úerrorr.   r.   r/   r0   _   s&   

€üÿÿzPyJWKSet.__init__r1   údict[str, Any]c                 C  s   |   dg ¡}t|ƒS )NrH   )r&   rG   )r1   rH   r.   r.   r/   r3   v   s   zPyJWKSet.from_dictr4   r5   c                 C  s   t  | ¡}t |¡S r2   )r6   r7   rG   r3   )r4   r1   r.   r.   r/   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: )rH   r?   ÚKeyError)r-   r>   r,   r.   r.   r/   Ú__getitem__€   s
   

ÿzPyJWKSet.__getitem__N)rH   rI   r   r   )r1   rN   r   rG   )r4   r5   r   rG   )r>   r5   r   r   )rB   rC   rD   r0   rE   r3   r8   rP   r.   r.   r.   r/   rG   ^   s    
rG   c                   @  s*   e Zd Zddd„Zddd„Zdd	d
„ZdS )ÚPyJWTSetWithTimestampÚjwk_setrG   c                 C  s   || _ t ¡ | _d S r2   )rR   ÚtimeÚ	monotonicÚ	timestamp)r-   rR   r.   r.   r/   r0   ˆ   s   zPyJWTSetWithTimestamp.__init__r   c                 C  ó   | j S r2   )rR   r;   r.   r.   r/   Úget_jwk_setŒ   ó   z!PyJWTSetWithTimestamp.get_jwk_setÚfloatc                 C  rV   r2   )rU   r;   r.   r.   r/   Úget_timestamp�   rX   z#PyJWTSetWithTimestamp.get_timestampN)rR   rG   )r   rG   )r   rY   )rB   rC   rD   r0   rW   rZ   r.   r.   r.   r/   rQ   ‡   s    

rQ   )Ú
__future__r   r6   rS   Útypingr   Ú
algorithmsr   r   r   Ú
exceptionsr   r	   r
   r   r   Útypesr   r   rG   rQ   r.   r.   r.   r/   Ú<module>   s    L)