Your IP : 18.117.8.84


Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/jwt/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/jwt/__pycache__/api_jws.cpython-311.pyc

�

��bg[+��*�ddlmZddlZddlZddlZddlmZmZddlm	Z	m
Z
mZmZddl
mZmZmZmZddlmZmZddlmZerdd	lmZmZGd
�d��Ze��ZejZejZejZejZejZejZej Z dS)�)�annotationsN)�
TYPE_CHECKING�Any�)�	Algorithm�get_default_algorithms�
has_crypto�requires_cryptography)�DecodeError�InvalidAlgorithmError�InvalidSignatureError�InvalidTokenError)�base64url_decode�base64url_encode)�RemovedInPyjwt3Warning)�AllowedPrivateKeys�AllowedPublicKeysc��eZdZdZ		d:d;d	�Zed<d���Zd=d�Zd>d�Zd?d�Z	d@d�Z
					dAdBd%�Z				dCdDd-�Z				dCdEd/�Z
dFd0�ZdGd2�Z		dHdId6�ZdJd7�ZdKd9�ZdS)L�PyJWS�JWTN�
algorithms�list[str] | None�options�dict[str, Any] | None�return�Nonec�6�t��|_|�t|��nt|j��|_t	|j�����D]}||jvr|j|=�|�i}i|����|�|_dS)N)r�_algorithms�set�_valid_algs�list�keys�_get_default_optionsr)�selfrr�keys    �B/opt/cloudlinux/venv/lib64/python3.11/site-packages/jwt/api_jws.py�__init__zPyJWS.__init__s���
2�3�3���)�5�C�
�O�O�O�3�t�?O�;P�;P�	
��
��(�-�-�/�/�0�0�	*�	*�C��$�*�*�*��$�S�)���?��G�A�$�3�3�5�5�A��A������dict[str, bool]c�
�ddiS)N�verify_signatureT�r,r(r&r#zPyJWS._get_default_options1s
��"�D�)�)r(�alg_id�str�alg_objrc���||jvrtd���t|t��st	d���||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$r-r/s   r&�register_algorithmzPyJWS.register_algorithm5sm���T�%�%�%��?�@�@�@��'�9�-�-�	A��?�@�@�@�#*���� �����V�$�$�$�$�$r(c�z�||jvrtd���|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)r$r-s  r&�unregister_algorithmzPyJWS.unregister_algorithmBsS��
��)�)�)��1���
�

��V�$������'�'�'�'�'r(�	list[str]c�*�t|j��S)zM
        Returns a list of supported values for the 'alg' parameter.
        )r!r )r$s r&�get_algorithmszPyJWS.get_algorithmsPs���D�$�%�%�%r(�alg_namec��	|j|S#t$r9}ts|tvrt	d|�d���|�t	d��|�d}~wwxYw)z�
        For a given string name, return the matching Algorithm object.

        Example usage:

        >>> jws_obj.get_algorithm_by_name("RS256")
        zAlgorithm 'z9' could not be found. Do you have cryptography installed?�Algorithm not supportedN)rr7r	r
�NotImplementedError)r$r=�es   r&�get_algorithm_by_namezPyJWS.get_algorithm_by_nameVs���	H��#�H�-�-���	H�	H�	H��
�(�.C�"C�"C�)�e�(�e�e�e�����&�&?�@�@�a�G�����	H���s��
A�4A
�
A�HS256FT�payload�bytesr%� AllowedPrivateKeys | str | bytes�	algorithm�
str | None�headers�json_encoder�type[json.JSONEncoder] | None�is_payload_detached�bool�sort_headersc�d�g}|�|nd}	|r:|�d��}
|
r|d}	|�d��}|durd}|j|	d�}|r*|�|��|�|��|ds|d=|rd|d<nd|vr|d=t	j|d||�	�����}
|�t|
����|r|}nt|��}|�|��d
�	|��}|�
|	��}|�|��}|�||��}|�t|����|rd|d<d
�	|��}|�
d
��S)N�none�alg�b64FT)�typrQrS)�,�:)�
separators�cls�	sort_keys�.r(r�utf-8)�get�
header_typ�_validate_headers�update�json�dumps�encode�appendr�joinrB�prepare_key�sign�decode)r$rDr%rGrIrJrLrN�segments�
algorithm_�headers_alg�headers_b64�header�json_header�msg_payload�
signing_inputr/�	signature�encoded_strings                   r&razPyJWS.encodegs�����(1�'<�)�)�&�
��	+�!�+�+�e�,�,�K��
,�$�U�^�
�!�+�+�e�,�,�K��e�#�#�&*�#�*.���!L�!L���	#��"�"�7�+�+�+��M�M�'�"�"�"��e�}�	��u�
��	�!�F�5�M�M�
�f�_�_��u�
��j��z�|�|�
�
�
�
�&�(�(�	�	���(��5�5�6�6�6��	4�!�K�K�*�7�3�3�K�����$�$�$��	�	�(�+�+�
��,�,�Z�8�8���!�!�#�&�&���L�L���4�4�	����(��3�3�4�4�4��	��H�Q�K����8�,�,���$�$�W�-�-�-r(��jwt�str | bytes�AllowedPublicKeys | str | bytes�detached_payload�bytes | None�dict[str, Any]c��|r<tjdt|�������t��|�i}i|j�|�}|d}|r|st
d���|�|��\}	}
}}|�dd��durD|�t
d���|}	d�	|
�
dd	��d
|	g��}
|r|�|
||||��|	||d�S)Nzypassing additional kwargs to decode_complete() is deprecated and will be removed in pyjwt version 3. Unsupported kwargs: r+z\It is required that you pass in a value for the "algorithms" argument when calling decode().rRTFz�It is required that you pass in a value for the "detached_payload" argument to decode a message having the b64 header set to false.rYrr)rDrkro)�warnings�warn�tupler"rrr�_loadr[rc�rsplit�_verify_signature)
r$rrr%rrru�kwargs�merged_optionsr+rDrnrkros
             r&�decode_completezPyJWS.decode_complete�sV���	��M�>�',�V�[�[�]�]�';�';�>�>�'�	
�
�
��?��G�4�D�L�4�G�4��)�*<�=���	�J�	��n���
�59�J�J�s�O�O�1����	��:�:�e�T�"�"�e�+�+��'�!�Z����'�G� �I�I�}�';�';�D�!�'D�'D�Q�'G��&Q�R�R�M��	V��"�"�=�&�)�S�*�U�U�U���"�
�
�	
r(rc���|r<tjdt|�������t��|�|||||���}|dS)Nzppassing additional kwargs to decode() is deprecated and will be removed in pyjwt version 3. Unsupported kwargs: )rurD)ryrzr{r"rr�)r$rrr%rrrur�decodeds        r&rfzPyJWS.decode�s|���	��M�>�',�V�[�[�]�]�';�';�>�>�'�	
�
�
��&�&���j�'�<L�'�
�
���y�!�!r(c�f�|�|��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
        �)r|r])r$rrrIs   r&�get_unverified_headerzPyJWS.get_unverified_header�s1���*�*�S�/�/�!�$�����w�'�'�'��r(�*tuple[bytes, bytes, dict[str, Any], bytes]c��t|t��r|�d��}t|t��st	dt�����	|�dd��\}}|�dd��\}}n"#t$r}t	d��|�d}~wwxYw	t|��}n.#ttjf$r}t	d��|�d}~wwxYw	tj
|��}n%#t$r}	t	d|	����|	�d}	~	wwxYwt|t��st	d���	t|��}
n.#ttjf$r}t	d	��|�d}~wwxYw	t|��}n.#ttjf$r}t	d
��|�d}~wwxYw|
|||fS)NrZz$Invalid token type. Token must be a rYrzNot enough segmentszInvalid header paddingzInvalid header string: z,Invalid header string: must be a json objectzInvalid payload paddingzInvalid crypto padding)r2r.rarErr}�splitr1rr3�binascii�Errorr_�loads�dict)r$rrrn�crypto_segment�header_segment�payload_segment�err�header_datarkrArDros            r&r|zPyJWS._load�s0���c�3���	&��*�*�W�%�%�C��#�u�%�%�	N��L�U�L�L�M�M�M�	>�,/�J�J�t�Q�,?�,?�)�M�>�.;�.A�.A�$��.J�.J�+�N�O�O���	>�	>�	>��3�4�4�#�=�����	>����	A�*�>�:�:�K�K���8�>�*�	A�	A�	A��6�7�7�S�@�����	A����	D��Z��,�,�F�F���	D�	D�	D��;��;�;�<�<�!�C�����	D�����&�$�'�'�	N��L�M�M�M�	B�&��7�7�G�G���8�>�*�	B�	B�	B��7�8�8�c�A�����	B����	A�(��8�8�I�I���8�>�*�	A�	A�	A��6�7�7�S�@�����	A�������	�:�:sx�2B�
B*�B%�%B*�.B>�>C)�C$�$C)�-D�
D$�D�D$�E�F�2F�F�F�G�1G�Grnrkroc�j�	|d}n#t$rtd���wxYw|r|�||vrtd���	|�|��}n"#t$r}td��|�d}~wwxYw|�|��}	|�||	|��st
d���dS)NrQzAlgorithm not specifiedz&The specified alg value is not allowedr?zSignature verification failed)r7rrBr@rd�verifyr
)
r$rnrkror%rrQr/rA�prepared_keys
          r&r~zPyJWS._verify_signatures��	C���-�C�C���	C�	C�	C�'�(A�B�B�B�	C�����	R�z�-�#�Z�2G�2G�'�(P�Q�Q�Q�	J��0�0��5�5�G�G��"�	J�	J�	J�'�(A�B�B��I�����	J�����*�*�3�/�/���~�~�m�\�9�E�E�	I�'�(G�H�H�H�	I�	Is ��%�A�
A5� A0�0A5c�H�d|vr|�|d��dSdS)N�kid)�
_validate_kid)r$rIs  r&r]zPyJWS._validate_headers8s3���G������w�u�~�.�.�.�.�.��r(r�c�N�t|t��std���dS)Nz(Key ID header parameter must be a string)r2r.r)r$r�s  r&r�zPyJWS._validate_kid<s0���#�s�#�#�	P�#�$N�O�O�O�	P�	Pr()NN)rrrrrr)rr))r-r.r/rrr)r-r.rr)rr:)r=r.rr)rCNNFT)rDrEr%rFrGrHrIrrJrKrLrMrNrMrr.)rqNNN)rrrsr%rtrrrrrurvrrw)rrrsr%rtrrrrrurvrr)rrrsrrw)rrrsrr�)rqN)rnrErkrwrorEr%rtrrrr)rIrwrr)r�rrr)�__name__�
__module__�__qualname__r\r'�staticmethodr#r5r9r<rBrar�rfr�r|r~r]r�r,r(r&rrs��������J�(,�)-�B�B�B�B�B�&�*�*�*��\�*�%�%�%�%�(�(�(�(�&�&�&�&�H�H�H�H�*!(�)-�6:�$)�!�C.�C.�C.�C.�C.�P02�'+�)-�)-�
+
�+
�+
�+
�+
�`02�'+�)-�)-�
"�"�"�"�"�*	�	�	�	�$;�$;�$;�$;�V02�'+�
I�I�I�I�I�2/�/�/�/�P�P�P�P�P�Pr(r)!�
__future__rr�r_ry�typingrrrrrr	r
�
exceptionsrrr
r�utilsrrrrrr�_jws_global_objrar�rfr5r9rBr�r,r(r&�<module>r�s���"�"�"�"�"�"�������������%�%�%�%�%�%�%�%�������������������������6�5�5�5�5�5�5�5�,�,�,�,�,�,��B�A�A�A�A�A�A�A�A�cP�cP�cP�cP�cP�cP�cP�cP�L	�%�'�'��	�	��!�1��	�	��$�7��&�;��'�=��'�=���r(

?>