Your IP : 3.145.61.142


Current Path : /opt/alt/python37/lib/python3.7/site-packages/jwt/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/jwt/__pycache__/api_jws.cpython-37.pyc

B

���_��@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@s�eZdZdZd!dd�Zedd��Zdd�Zd	d
�Zdd�Z	d"e
eeee
eeejed�dd�Zd#eeeee
e
eefd�dd�Zd$eeeee
ed�dd�Zdd�Zdd�Zd%dd�Zdd�Zdd �ZdS)&�PyJWSZJWTNcCslt�|_|dk	rt|�nt|j�|_x(t|j���D]}||jkr4|j|=q4W|dkrZi}|��|�|_dS)N)r
�_algorithms�set�_valid_algs�list�keys�_get_default_options�options)�self�
algorithmsr�key�r�</opt/alt/python37/lib/python3.7/site-packages/jwt/api_jws.py�__init__s
zPyJWS.__init__cCsddiS)N�verify_signatureTrrrrrr'szPyJWS._get_default_optionscCs>||jkrtd��t|t�s$td��||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*||jkrtd��|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_algorithmsFszPyJWS.get_algorithms�HS256)�payloadr�	algorithm�headers�json_encoder�returnc
Cs�g}|dkrd}||jkr|j|d�}|r>|�|�|�|�tj|d|d���}|�t|��|�t|��d�	|�}	y$|j
|}
|
�|�}|
�|	|�}Wn6t
k
r�ts�|tkr�td|��ntd��YnX|�t|��d�	|�}|�d�S)	NZnone)�typ�alg)�,�:)�
separators�cls�.zFAlgorithm '%s' could not be found. Do you have cryptography installed?zAlgorithm not supportedzutf-8)r�
header_typ�_validate_headers�update�json�dumps�encode�appendr�joinr�prepare_key�signr)rr�NotImplementedError�decode)
rr.rr/r0r1�segments�headerZjson_header�
signing_inputr'�	signature�encoded_stringrrrr?Ls4







zPyJWS.encode�)�jwtrrrr2cKsb|dkri}|j|�}|d}|r.|s.td��|�|�\}}	}
}|rV|�|	|
|||�||
|d�S)Nr!z\It is required that you pass in a value for the "algorithms" argument when calling decode().)r.rGrI)rr
�_load�_verify_signature)rrLrrr�kwargsZmerged_optionsr!r.rHrGrIrrr�decode_complete�s
zPyJWS.decode_completecKs|j||||f|�}|dS)Nr.)rP)rrLrrrrO�decodedrrrrE�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
        �)rMr;)rrLr0rrr�get_unverified_header�s
zPyJWS.get_unverified_headerc
Cs�t|t�r|�d�}t|t�s,tdt����y$|�dd�\}}|�dd�\}}Wn,tk
r|}ztd�|�Wdd}~XYnXyt|�}Wn2t	t
jfk
r�}ztd�|�Wdd}~XYnXyt�
|�}Wn0tk
r�}	ztd|	�|	�Wdd}	~	XYnXt|t��std��yt|�}
Wn4t	t
jfk
�rR}ztd	�|�Wdd}~XYnXyt|�}Wn4t	t
jfk
�r�}ztd
�|�Wdd}~XYnX|
|||fS)Nzutf-8z$Invalid token type. Token must be a r9rzNot enough segmentszInvalid header paddingzInvalid header string: %sz,Invalid header string: must be a json objectzInvalid payload paddingzInvalid crypto padding)r#�strr?�bytesr
�rsplit�splitr"rr$�binascii�Errorr=�loadsr)rrLrHZcrypto_segmentZheader_segmentZpayload_segment�errZheader_datarG�er.rIrrrrM�s8


 zPyJWS._loadcCsr|�d�}|dk	r"||kr"td��y.|j|}|�|�}|�|||�sNtd��Wntk
rltd��YnXdS)Nr4z&The specified alg value is not allowedzSignature verification failedzAlgorithm not supported)�getrrrBZverifyrr))rrHrGrIrrr4r'rrrrN�s	


zPyJWS._verify_signaturecCsd|kr|�|d�dS)N�kid)�
_validate_kid)rr0rrrr;�szPyJWS._validate_headerscCst|t�std��dS)Nz(Key ID header parameter must be a string)r#rTr)rr^rrrr_�s
zPyJWS._validate_kid)NN)r-NN)rKNN)rKNN)rKN)�__name__�
__module__�__qualname__r:r �staticmethodrr(r+r,rUrTrrrr=�JSONEncoderr?rrrPrErSrMrNr;r_rrrrrs0


0+
r)rXr=�collections.abcr�typingrrrrrrr	r
rr�
exceptionsr
rrr�utilsrrrZ_jws_global_objr?rPrEr(r+rSrrrr�<module>sf

?>