
    qi                        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
      Z G d d      Z G d d      Zy)    )annotationsN)Iterator)Any   )get_default_algorithms
has_cryptorequires_cryptography)InvalidKeyErrorMissingCryptographyError
PyJWKErrorPyJWKSetError
PyJWTError)JWKDictc                  t    e Zd Zdd	dZedd
d       Zeddd       Zedd       Zedd       Z	edd       Z
y)PyJWKNc                h   t               | _        || _        | j                  j                  dd      }|st	        d| j                         |s6t        | j                  t              r| j                  j                  dd      }|s| j                  j                  dd      }|dk(  r0|dk(  s|sd}ny|d	k(  rd
}nq|dk(  rd}ni|dk(  rd}nat	        d|       |dk(  rd}nK|dk(  rd}nC|dk(  r0|st	        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                  | j                        | _        y)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)selfjwk_data	algorithmr   r   s        =/opt/pipecat/venv/lib/python3.12/site-packages/jwt/api_jwk.py__init__zPyJWK.__init__   s    23!nn  -!$6t~~6F"GHHZ=**5$7I..$$UD1Cd{'> 'IG^ 'IG^ 'IK' (I),=cU*CDD#	#	),>t~~>N*OPP)# 'I),=cU*CDD%(9#&?@@i+@@*+FG  ((((!--i8DNDT^^DTUVV>>**4>>:    c                    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   )objr.   s     r/   	from_dictzPyJWK.from_dictS   s     S)$$r1   c                X    t        j                  |       }t        j                  ||      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   r4   )datar.   r3   s      r/   	from_jsonzPyJWK.from_json_   s#     jjsI..r1   c                :    | j                   j                  dd      S )zFThe `kty` property from the JWK.

        :rtype: str or None
        r   Nr$   r%   r,   s    r/   key_typezPyJWK.key_typem        ~~!!%..r1   c                :    | j                   j                  dd      S )zFThe `kid` property from the JWK.

        :rtype: str or None
        kidNr;   r<   s    r/   key_idzPyJWK.key_idu   r>   r1   c                :    | j                   j                  dd      S )zFThe `use` property from the JWK.

        :rtype: str or None
        useNr;   r<   s    r/   public_key_usezPyJWK.public_key_use}   r>   r1   N)r-   r   r.   
str | NonereturnNone)r3   r   r.   rF   rG   r   )r8   strr.   rH   rG   r   )rG   rF   )__name__
__module____qualname__r0   staticmethodr4   r9   propertyr=   rA   rD    r1   r/   r   r      sl    =;~ 	% 	% / / / / / / / /r1   r   c                  H    e Zd ZddZedd       Zed	d       Zd
dZddZy)PyJWKSetc                P   g | _         |st        d      t        |t              st        d      |D ]'  }	 | j                   j	                  t        |             ) t        | j                         dk(  rt        d      y # t        $ r}t        |t              r|Y d }~nd }~ww xY w)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?)	keysr   r&   listappendr   r   r   len)r,   rS   r+   errors       r/   r0   zPyJWKSet.__init__   s    	 FGG$% 788 	C		  s,	 tyy>Qg    e%=>K	s   $B  	B%	B  B%c                <    | j                  dg       }t        |      S )NrS   )r%   rQ   )r3   rS   s     r/   r4   zPyJWKSet.from_dict   s    wwvr"~r1   c                V    t        j                  |       }t        j                  |      S rE   )r6   r7   rQ   r4   )r8   r3   s     r/   r9   zPyJWKSet.from_json   s!    jj!!#&&r1   c                f    | j                   D ]  }|j                  |k(  s|c S  t        d|       )Nzkeyset has no key for kid: )rS   rA   KeyError)r,   r@   r+   s      r/   __getitem__zPyJWKSet.__getitem__   s;    99 	CzzS 
	 4SE:;;r1   c                ,    t        | j                        S rE   )iterrS   r<   s    r/   __iter__zPyJWKSet.__iter__   s    DIIr1   N)rS   zlist[JWKDict]rG   rH   )r3   zdict[str, Any]rG   rQ   )r8   rI   rG   rQ   )r@   rI   rG   r   )rG   zIterator[PyJWK])	rJ   rK   rL   r0   rM   r4   r9   r\   r_   rO   r1   r/   rQ   rQ      s9    .   ' '<r1   rQ   c                  $    e Zd ZddZddZddZy)PyJWTSetWithTimestampc                D    || _         t        j                         | _        y rE   )jwk_settime	monotonic	timestamp)r,   rc   s     r/   r0   zPyJWTSetWithTimestamp.__init__   s    )r1   c                    | j                   S rE   )rc   r<   s    r/   get_jwk_setz!PyJWTSetWithTimestamp.get_jwk_set   s    ||r1   c                    | j                   S rE   )rf   r<   s    r/   get_timestampz#PyJWTSetWithTimestamp.get_timestamp   s    ~~r1   N)rc   rQ   )rG   rQ   )rG   float)rJ   rK   rL   r0   rh   rj   rO   r1   r/   ra   ra      s    *r1   ra   )
__future__r   r6   rd   collections.abcr   typingr   
algorithmsr   r   r	   
exceptionsr
   r   r   r   r   typesr   r   rQ   ra   rO   r1   r/   <module>rr      sK    "   $  Q Q  p/ p/f) )X	 	r1   