HEX
Server: nginx/1.24.0
System: Linux localhost 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64
User: www (1000)
PHP: 8.3.27
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: //proc/93580/root/lib/python3/dist-packages/jwt/__pycache__/api_jws.cpython-310.pyc
o

�l�i#�@s�ddlZddlZddlmZddlmZmZmZmZm	Z	ddl
mZmZm
Z
mZddlmZmZmZmZddlmZmZGdd	�d	�Ze�ZejZejZejZejZejZejZdS)
�N)�Mapping)�Any�Dict�List�Optional�Type�)�	Algorithm�get_default_algorithms�
has_crypto�requires_cryptography)�DecodeError�InvalidAlgorithmError�InvalidSignatureError�InvalidTokenError)�base64url_decode�base64url_encodec
@seZdZdZd-dd�Zedd��Zdd�Zd	d
�Zdd�Z		
		d.de
dedeedee
deeejdefdd�Z			d/dededeede
de
eeff
dd�Z			d/dededeede
def
dd�Zdd�Zd d!�Z		d0d"d#�Zd$hZd%d&�d'd(�Zd)d*�Zd+d,�ZdS)1�PyJWS�JWTNcCslt�|_|durt|�nt|j�|_t|j���D]}||jvr$|j|=q|dur+i}i|���|�|_dS)N)r
�_algorithms�set�_valid_algs�list�keys�_get_default_options�options)�self�
algorithmsr�key�r�-/usr/lib/python3/dist-packages/jwt/api_jws.py�__init__s�
�zPyJWS.__init__cCsddiS)N�verify_signatureTrrrrr r'szPyJWS._get_default_optionscCs>||jvr	td��t|t�std��||j|<|j�|�dS)zW
        Registers a new Algorithm for use when creating and verifying tokens.
        z Algorithm already has a handler.z!Object is not of type `Algorithm`N)r�
ValueError�
isinstancer	�	TypeErrorr�add)r�alg_id�alg_objrrr �register_algorithm+s


zPyJWS.register_algorithmcCs*||jvr	td��|j|=|j�|�dS)z�
        Unregisters an Algorithm for use when creating and verifying tokens
        Throws KeyError if algorithm is not registered.
        zJThe specified algorithm could not be removed because it is not registered.N)r�KeyErrorr�remove)rr'rrr �unregister_algorithm8s
�zPyJWS.unregister_algorithmcCs
t|j�S)zM
        Returns a list of supported values for the 'alg' parameter.
        )rr)rrrr �get_algorithmsFs
zPyJWS.get_algorithms�HS256�payloadr�	algorithm�headers�json_encoder�returnc
Cs g}|durd}|rd|vr|dr|d}|j|d�}|r1|j|dd�|�|�|ds1|d=tj|d|d���}|�t|��|�t|��d	�|�}	z|j	|}
|
�
|�}|
�|	|�}Wnty~}zt
su|tvrutd
|�|�td�|�d}~ww|�t|��d	�|�}
|
�d�S)
N�none�alg)�typr5T��encodingr6)�,�:)�
separators�cls�.zFAlgorithm '%s' could not be found. Do you have cryptography installed?�Algorithm not supported�utf-8)�
header_typ�_validate_headers�update�json�dumps�encode�appendr�joinr�prepare_key�signr*rr�NotImplementedError�decode)rr/rr0r1r2�segments�header�json_header�
signing_inputr(�	signature�e�encoded_stringrrr rELsL
��


���
��	

zPyJWS.encode��jwtrrcKsp|duri}i|j�|�}|d}|r|std��|�|�\}}	}
}|�|
�|r2|�|	|
|||�||
|d�S)Nr"z\It is required that you pass in a value for the "algorithms" argument when calling decode().)r/rMrP)rr
�_loadrA�_verify_signature)rrTrrr�kwargs�merged_optionsr"r/rOrMrPrrr �decode_complete�s �
�zPyJWS.decode_completecKs |j||||fi|��}|dS)Nr/)rY)rrTrrrrW�decodedrrr rK�szPyJWS.decodecCs|�|�d}|�|�|S)z�Returns back the JWT header parameters as a dict()

        Note: The signature is not verified so the header parameters
        should not be fully trusted until signature verification is complete
        �)rUrA)rrTr1rrr �get_unverified_header�s
zPyJWS.get_unverified_headerc
Csjt|t�r
|�d�}t|t�stdt����z|�dd�\}}|�dd�\}}Wnty9}ztd�|�d}~wwzt|�}Wnt	t
jfyT}ztd�|�d}~wwzt�
|�}Wntyo}	ztd|	�|	�d}	~	wwt|t�sytd��zt|�}
Wnt	t
jfy�}ztd	�|�d}~wwzt|�}Wnt	t
jfy�}ztd
�|�d}~ww|
|||fS)Nr?z$Invalid token type. Token must be a r=rzNot enough segmentszInvalid header paddingzInvalid header string: %sz,Invalid header string: must be a json objectzInvalid payload paddingzInvalid crypto padding)r$�strrE�bytesr
�rsplit�splitr#rr%�binascii�ErrorrC�loadsr)rrTrO�crypto_segment�header_segment�payload_segment�err�header_datarMrQr/rPrrr rU�sL



��
����

��
��zPyJWS._loadc	
Csv|�d�}|dur||vrtd��z|j|}|�|�}|�|||�s'td��WdSty:}ztd�|�d}~ww)Nr5z&The specified alg value is not allowedzSignature verification failedr>)�getrrrH�verifyrr*)	rrOrMrPrrr5r(rQrrr rV�s
	

�
��zPyJWS._verify_signature�b64Fr7cCs8d|vr|�|d�|sd|vr|�|�dSdSdS)N�kid�crit)�
_validate_kid�_validate_crit)rr1r8rrr rA�s
�zPyJWS._validate_headerscCst|t�s	td��dS)Nz(Key ID header parameter must be a string)r$r]r)rrlrrr rns
�zPyJWS._validate_kidcCsv|d}t|t�rt|�dkrtd��|D]#}t|t�s td��||jvr,td|����||vr8td|�d���qdS)Nrmrz/Invalid 'crit' header: must be a non-empty listz-Invalid 'crit' header: values must be stringsz Unsupported critical extension: zCritical extension 'z' is missing from headers)r$r�lenrr]�_supported_crit)rr1rm�extrrr ros


���zPyJWS._validate_crit)NN)r.NN)rSNN)rSN)�__name__�
__module__�__qualname__r@r!�staticmethodrr)r,r-r^r]rrrrC�JSONEncoderrErrrYrKr\rUrVrqrArnrorrrr rs|



������
�:�����

�"�����
�+
��r)rarC�collections.abcr�typingrrrrrrr	r
rr�
exceptionsr
rrr�utilsrrr�_jws_global_objrErYrKr)r,r\rrrr �<module>s"