o
    O`                     @   s   d dl Z d dlZd dlmZ ejd  dkr ejd dkr eje _d dlZzd dlZW n e	y7   d dl
ZY nw d dlZddgZG dd deZG d	d deZdS )
    N)compat         JwtJwtDecodeErrorc                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r   r   W/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/twilio/jwt/__init__.pyr      s    c                   @   s   e Zd ZdZe ZddeddfddZdd Zd	d
 Ze	dddZ
edd Zedd ZdddZe	dddZdd ZdS )r   z(Base class for building a Json Web TokenNHS256i  c                 C   sH   || _ 	 || _	 || _	 || _	 || _	 || _	 || _	 d | _d | _d S N)	
secret_keyissuersubject	algorithmnbfttlvalid_until_Jwt__decoded_payload_Jwt__decoded_headers)selfr   r   r   r   r   r   r   r   r   r   __init__   s    
zJwt.__init__c                 C   s   t d)z+:rtype: dict the payload of the JWT to sendz Subclass must provide a payload.)NotImplementedErrorr   r   r   r   _generate_payload3   s   zJwt._generate_payloadc                 C   s   i S )zP:rtype dict: Additional headers to include in the JWT, defaults to an empty dictr   r   r   r   r   _generate_headers7   s   zJwt._generate_headersc              
   C   sL   t ||dd|dd|dd|dd|ddd}||_||_|S )z
        Class specific implementation of from_jwt which should take jwt components and return
        and instance of this Class with jwt information loaded.
        :return: Jwt object containing the headers, payload and key
        issNsubalgexpr   )r   r   r   r   r   r   )r   getr   r   )clsheaderspayloadkeyjwtr   r   r   	_from_jwt;   s   




zJwt._from_jwtc                 C   s   | j r| j S |   }| j|d< tt | j |d< | jd ur5| j| jkr0tt |d< n| j|d< | j	r=| j	|d< | j
rE| j
|d< |S )Nr   r!   r   r   )r   r   copyr   inttimer   r   GENERATEr   r   )r   r%   r   r   r   r%   N   s   




zJwt.payloadc                 C   s.   | j r| j S |   }d|d< | j|d< |S )NJWTtypr    )r   r   r)   r   )r   r$   r   r   r   r$   b   s   
zJwt.headersc                 C   sd   | j std| j }|r||d< |p| j}| j }|r(tt | |d< tj	|| j ||dS )z
        Encode this JWT object into a JWT string
        :param str algorithm: override the algorithm used to encode the JWT
        :param int ttl: override the ttl configured in the constructor
        :rtype: str The JWT string
        z+JWT does not have a signing key configured.r    r!   )r   r$   )
r   
ValueErrorr$   r)   r   r%   r*   r+   jwt_libencode)r   r   r   r$   r%   r   r   r   to_jwtl   s   


z
Jwt.to_jwt c              
   C   sr   |rdnd}zt jt|||dddd}t |}W n ty1 } z
tt|dt|d}~ww | |||S )av  
        Decode a JWT string into a Jwt object
        :param str jwt: JWT string
        :param Optional[str] key: key used to verify JWT signature, if not provided then validation
                                  is skipped.
        :raises JwtDecodeError if decoding JWT fails for any reason.
        :return: A DecodedJwt object containing the jwt information.
        TF)verify_signature
verify_exp
verify_nbf)optionsmessageN)	r0   decodebytesget_unverified_header	Exceptionr   getattrstrr(   )r#   r'   r&   verifyr%   r$   er   r   r   from_jwt   s   

zJwt.from_jwtc                 C   s   d |  S )Nz<JWT {}>)formatr2   r   r   r   r   __str__   s   zJwt.__str__r   )NN)r3   )r   r	   r
   __doc__objectr,   r   r   r   classmethodr(   propertyr%   r$   r2   rA   rC   r   r   r   r   r      s$    



	)hmacsys
twilio.jwtr   version_infocompare_digestr'   r0   jsonImportError
simplejsonr+   __all__r<   r   rE   r   r   r   r   r   <module>   s    