%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/jwt/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/jwt/__pycache__/algorithms.cpython-35.pyc



[��Y;"�@s�ddlZddlZddlmZmZmZddlmZddlm	Z	m
Z
y�ddlmZddl
mZmZmZddlmZmZdd	lmZmZdd
lmZmZddlmZddlmZd
ZWnek
rdZYnXdd�Z Gdd�de!�Z"Gdd�de"�Z#Gdd�de"�Z$er�Gdd�de"�Z%Gdd�de"�Z&Gdd�de%�Z'dS)�N�)�constant_time_compare�string_types�	text_type)�InvalidKeyError)�der_to_raw_signature�raw_to_der_signature)�hashes)�load_pem_private_key�load_pem_public_key�load_ssh_public_key)�
RSAPrivateKey�RSAPublicKey)�EllipticCurvePrivateKey�EllipticCurvePublicKey)�ec�padding)�default_backend)�InvalidSignatureTFcCs�dt�dttj�dttj�dttj�i}tr�|jdttj�dttj�dttj�dttj�d	ttj�d
ttj�dt	t	j�dt	t	j�d
t	t	j�i	�|S)zE
    Returns the algorithms that are implemented by the library.
    ZnoneZHS256ZHS384ZHS512ZRS256ZRS384ZRS512ZES256ZES384ZES512ZPS256ZPS384ZPS512)
�
NoneAlgorithm�
HMACAlgorithm�SHA256�SHA384�SHA512�
has_crypto�update�RSAAlgorithm�ECAlgorithm�RSAPSSAlgorithm)Zdefault_algorithms�r�0/usr/lib/python3/dist-packages/jwt/algorithms.py�get_default_algorithmss 	r!c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�	AlgorithmzH
    The interface for an algorithm used to sign and verify tokens.
    cCs
t�dS)z�
        Performs necessary validation and conversions on the key and returns
        the key value in the proper format for sign() and verify().
        N)�NotImplementedError)�self�keyrrr �prepare_key;szAlgorithm.prepare_keycCs
t�dS)zn
        Returns a digital signature for the specified message
        using the specified key value.
        N)r#)r$�msgr%rrr �signBszAlgorithm.signcCs
t�dS)zz
        Verifies that the specified digital signature is valid
        for the specified message and key values.
        N)r#)r$r'r%�sigrrr �verifyIszAlgorithm.verifyN)�__name__�
__module__�__qualname__�__doc__r&r(r*rrrr r"7sr"c@s:eZdZdZdd�Zdd�Zdd�ZdS)	rzZ
    Placeholder for use when no signing or verification
    operations are required.
    cCs.|dkrd}|dk	r*td��|S)N�z*When alg = "none", key value must be None.)r)r$r%rrr r&Vs
zNoneAlgorithm.prepare_keycCsdS)N�r)r$r'r%rrr r(_szNoneAlgorithm.signcCsdS)NFr)r$r'r%r)rrr r*bszNoneAlgorithm.verifyN)r+r,r-r.r&r(r*rrrr rQs	rc@saeZdZdZejZejZej	Z
dd�Zdd�Zdd�Z
dd	�Zd
S)rzf
    Performs signing and verification operations using HMAC
    and the specified hash function.
    cCs
||_dS)N)�hash_alg)r$r1rrr �__init__oszHMACAlgorithm.__init__cs�t�t�r,t�t�r,td��t�t�rJ�jd��ddddg}t�fdd�|D��r�td	���S)
Nz+Expecting a string- or bytes-formatted key.zutf-8s-----BEGIN PUBLIC KEY-----s-----BEGIN CERTIFICATE-----s-----BEGIN RSA PUBLIC KEY-----sssh-rsacsg|]}|�k�qSrr)�.0Zstring_value)r%rr �
<listcomp>�s	z-HMACAlgorithm.prepare_key.<locals>.<listcomp>zdThe specified key is an asymmetric key or x509 certificate and should not be used as an HMAC secret.)�
isinstancer�bytes�	TypeErrorr�encode�anyr)r$r%Zinvalid_stringsr)r%r r&rs 		zHMACAlgorithm.prepare_keycCstj|||j�j�S)N)�hmac�newr1Zdigest)r$r'r%rrr r(�szHMACAlgorithm.signcCst||j||��S)N)rr()r$r'r%r)rrr r*�szHMACAlgorithm.verifyN)r+r,r-r.�hashlibZsha256rZsha384rZsha512rr2r&r(r*rrrr rfs			rc@saeZdZdZejZejZejZdd�Zdd�Z	dd�Z
dd	�Zd
S)rz~
        Performs signing and verification operations using
        RSASSA-PKCS-v1_5 and the specified hash function.
        cCs
||_dS)N)r1)r$r1rrr r2�szRSAAlgorithm.__init__cCs�t|t�st|t�r"|St|t�r�t|t�rO|jd�}yF|jd�ryt|dt��}nt	|dddt��}Wq�t
k
r�t|dt��}Yq�Xntd��|S)Nzutf-8sssh-rsa�backend�passwordzExpecting a PEM-formatted key.)
r5r
rrrr8�
startswithrrr
�
ValueErrorrr7)r$r%rrr r&�s
zRSAAlgorithm.prepare_keycCs5|jtj�|j��}|j|�|j�S)N)�signerr�PKCS1v15r1r�finalize)r$r'r%rArrr r(�s
	
zRSAAlgorithm.signcCs]|j|tj�|j��}|j|�y|j�dSWntk
rXdSYnXdS)NTF)�verifierrrBr1rr*r)r$r'r%r)rDrrr r*�s	


zRSAAlgorithm.verifyN)r+r,r-r.r	rrrr2r&r(r*rrrr r�s				rc@saeZdZdZejZejZejZdd�Zdd�Z	dd�Z
dd	�Zd
S)rzr
        Performs signing and verification operations using
        ECDSA and the specified hash function
        cCs
||_dS)N)r1)r$r1rrr r2�szECAlgorithm.__init__cCs�t|t�st|t�r"|St|t�r�t|t�rO|jd�}yt|dt��}Wq�tk
r�t	|dddt��}Yq�Xnt
d��|S)Nzutf-8r=r>zExpecting a PEM-formatted key.)r5rrrrr8rrr@r
r7)r$r%rrr r&�s
#zECAlgorithm.prepare_keycCsG|jtj|j���}|j|�|j�}t||j�S)N)rAr�ECDSAr1rrCr�curve)r$r'r%rA�der_sigrrr r(�s
zECAlgorithm.signcCs�yt||j�}Wntk
r.dSYnX|j|tj|j���}|j|�y|j�dSWnt	k
r�dSYnXdS)NFT)
rrFr@rDrrEr1rr*r)r$r'r%r)rGrDrrr r*�s
	!


zECAlgorithm.verifyN)r+r,r-r.r	rrrr2r&r(r*rrrr r�s			rc@s.eZdZdZdd�Zdd�ZdS)rzA
        Performs a signature using RSASSA-PSS with MGF1
        cCsV|jtjdtj|j��d|jj�|j��}|j|�|j�S)N�mgf�salt_length)rAr�PSS�MGF1r1�digest_sizerrC)r$r'r%rArrr r(s	
zRSAPSSAlgorithm.signcCs~|j|tjdtj|j��d|jj�|j��}|j|�y|j�dSWntk
rydSYnXdS)NrHrITF)	rDrrJrKr1rLrr*r)r$r'r%r)rDrrr r*s	


zRSAPSSAlgorithm.verifyN)r+r,r-r.r(r*rrrr rsr)(r<r:�compatrrr�
exceptionsrZutilsrrZcryptography.hazmat.primitivesr	Z,cryptography.hazmat.primitives.serializationr
rrZ-cryptography.hazmat.primitives.asymmetric.rsar
rZ,cryptography.hazmat.primitives.asymmetric.ecrrZ)cryptography.hazmat.primitives.asymmetricrrZcryptography.hazmat.backendsrZcryptography.exceptionsrr�ImportErrorr!�objectr"rrrrrrrrr �<module>s.

'9:

Zerion Mini Shell 1.0