%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core18/2887/usr/lib/python3/dist-packages/jwt/__pycache__/
Upload File :
Create Path :
Current File : //snap/core18/2887/usr/lib/python3/dist-packages/jwt/__pycache__/algorithms.cpython-36.pyc

3

�M�bX3�@s�ddlZddlZddlZddlmZmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZy�ddlmZddlmZmZmZddlmZmZmZmZmZmZm Z m!Z!dd	l"m#Z#m$Z$dd
l%m&Z&m'Z'ddl(m)Z)ddl*m+Z+d
Z,Wne-k
�rdZ,YnXe.ddddddddddg
�Z/dd�Z0Gdd�de1�Z2Gdd�de2�Z3Gdd �d e2�Z4e,�r�Gd!d"�d"e2�Z5Gd#d$�d$e2�Z6Gd%d&�d&e5�Z7dS)'�N�)�constant_time_compare�string_types)�InvalidKeyError)
�base64url_decode�base64url_encode�der_to_raw_signature�force_bytes�
force_unicode�from_base64url_uint�raw_to_der_signature�to_base64url_uint�
is_pem_format�
is_ssh_key)�hashes)�load_pem_private_key�load_pem_public_key�load_ssh_public_key)�
RSAPrivateKey�RSAPublicKey�RSAPrivateNumbers�RSAPublicNumbers�rsa_recover_prime_factors�rsa_crt_dmp1�rsa_crt_dmq1�rsa_crt_iqmp)�EllipticCurvePrivateKey�EllipticCurvePublicKey)�ec�padding)�default_backend)�InvalidSignatureTF�RS256�RS384�RS512�ES256�ES384�ES521�ES512�PS256�PS384�PS512cCs�t�ttj�ttj�ttj�d�}tr�|jttj�ttj�ttj�ttj�ttj�ttj�ttj�t	t	j�t	t	j�t	t	j�d�
�|S)zE
    Returns the algorithms that are implemented by the library.
    )ZnoneZHS256ZHS384ZHS512)
r"r#r$r%r&r'r(r)r*r+)
�
NoneAlgorithm�
HMACAlgorithm�SHA256�SHA384�SHA512�
has_crypto�update�RSAAlgorithm�ECAlgorithm�RSAPSSAlgorithm)Zdefault_algorithms�r6�0/usr/lib/python3/dist-packages/jwt/algorithms.py�get_default_algorithms's"r8c@s@eZdZdZdd�Zdd�Zdd�Zedd	��Zed
d��Z	dS)
�	AlgorithmzH
    The interface for an algorithm used to sign and verify tokens.
    cCst�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�keyr6r6r7�prepare_keyGszAlgorithm.prepare_keycCst�dS)zn
        Returns a digital signature for the specified message
        using the specified key value.
        N)r:)r;�msgr<r6r6r7�signNszAlgorithm.signcCst�dS)zz
        Verifies that the specified digital signature is valid
        for the specified message and key values.
        N)r:)r;r>r<�sigr6r6r7�verifyUszAlgorithm.verifycCst�dS)z7
        Serializes a given RSA key into a JWK
        N)r:)�key_objr6r6r7�to_jwk\szAlgorithm.to_jwkcCst�dS)zb
        Deserializes a given RSA key from JWK back into a PublicKey or PrivateKey object
        N)r:)�jwkr6r6r7�from_jwkcszAlgorithm.from_jwkN)
�__name__�
__module__�__qualname__�__doc__r=r?rA�staticmethodrCrEr6r6r6r7r9Csr9c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r,zZ
    Placeholder for use when no signing or verification
    operations are required.
    cCs |dkrd}|dk	rtd��|S)N�z*When alg = "none", key value must be None.)r)r;r<r6r6r7r=ps
zNoneAlgorithm.prepare_keycCsdS)N�r6)r;r>r<r6r6r7r?yszNoneAlgorithm.signcCsdS)NFr6)r;r>r<r@r6r6r7rA|szNoneAlgorithm.verifyN)rFrGrHrIr=r?rAr6r6r6r7r,ks	r,c@sZeZdZdZejZejZej	Z
dd�Zdd�Ze
dd��Ze
dd	��Zd
d�Zdd
�ZdS)r-zf
    Performs signing and verification operations using HMAC
    and the specified hash function.
    cCs
||_dS)N)�hash_alg)r;rMr6r6r7�__init__�szHMACAlgorithm.__init__cCs$t|�}t|�st|�r td��|S)NzdThe specified key is an asymmetric key or x509 certificate and should not be used as an HMAC secret.)r	rrr)r;r<r6r6r7r=�s
zHMACAlgorithm.prepare_keycCstjttt|���dd��S)N�oct)�k�kty)�json�dumpsr
rr	)rBr6r6r7rC�szHMACAlgorithm.to_jwkcCs,tj|�}|jd�dkr td��t|d�S)NrQrOzNot an HMAC keyrP)rR�loads�getrr)rD�objr6r6r7rE�s
zHMACAlgorithm.from_jwkcCstj|||j�j�S)N)�hmac�newrMZdigest)r;r>r<r6r6r7r?�szHMACAlgorithm.signcCst||j||��S)N)rr?)r;r>r<r@r6r6r7rA�szHMACAlgorithm.verifyN)rFrGrHrI�hashlibZsha256r.Zsha384r/Zsha512r0rNr=rJrCrEr?rAr6r6r6r7r-�s
	r-c@sZeZdZdZejZejZejZdd�Zdd�Z	e
dd��Ze
dd	��Zd
d�Z
dd
�ZdS)r3z~
        Performs signing and verification operations using
        RSASSA-PKCS-v1_5 and the specified hash function.
        cCs
||_dS)N)rM)r;rMr6r6r7rN�szRSAAlgorithm.__init__cCs�t|t�st|t�r|St|t�r~t|�}y.|jd�rFt|t�d�}nt|dt�d�}Wq�t	k
rzt
|t�d�}Yq�Xntd��|S)Nsssh-rsa)�backend)�passwordrZzExpecting a PEM-formatted key.)�
isinstancerrrr	�
startswithrr r�
ValueErrorr�	TypeError)r;r<r6r6r7r=�s



zRSAAlgorithm.prepare_keycCs�d}t|dd�r�|j�}ddgtt|jj��tt|jj��tt|j��tt|j��tt|j	��tt|j
��tt|j��tt|j��d�
}nBt|dd�r�|j�}ddgtt|j��tt|j��d�}nt
d��tj|�S)N�private_numbers�RSAr?)
rQ�key_ops�n�e�d�p�q�dp�dq�qirA)rQrbrcrdzNot a public or private key)�getattrr`r
r
�public_numbersrcrdrerfrg�dmp1�dmq1�iqmprrRrS)rBrV�numbersr6r6r7rC�s*zRSAAlgorithm.to_jwkc	s�ytj|��Wntk
r*td��YnX�jd�dkrBtd��d�koXd�koXd�k�rfd�krltd	��d
ddd
dg}�fdd�|D�}t|�}|r�t|�r�td��tt�d�t�d��}|�rt	t�d�t�d
�t�d�t�d�t�d
�t�d�|d�}nHt�d�}t
|j||j�\}}t	|||t
||�t||�t||�|d�}|jt��Sd�k�r�d�k�r�tt�d�t�d��}|jt��Std��dS)NzKey is not valid JSONrQrazNot an RSA keyrerdrcZothz5Unsupported RSA private key: > 2 primes not supportedrfrgrhrirjcsg|]}|�k�qSr6r6)�.0Zprop)rVr6r7�
<listcomp>sz)RSAAlgorithm.from_jwk.<locals>.<listcomp>z@RSA key must include all parameters if any are present besides d)rerfrgrmrnrorlzNot a public or private key)rRrTr^rrU�any�allrrrrrcrdrrrZprivate_keyr Z
public_key)	rDZother_propsZprops_foundZany_props_foundrlrprerfrgr6)rVr7rE�sT






zRSAAlgorithm.from_jwkcCs|j|tj�|j��S)N)r?r�PKCS1v15rM)r;r>r<r6r6r7r?2szRSAAlgorithm.signcCs6y|j||tj�|j��dStk
r0dSXdS)NTF)rArrurMr!)r;r>r<r@r6r6r7rA5s
zRSAAlgorithm.verifyN)rFrGrHrIrr.r/r0rNr=rJrCrEr?rAr6r6r6r7r3�s$?r3c@sBeZdZdZejZejZejZdd�Zdd�Z	dd�Z
dd	�Zd
S)r4zr
        Performs signing and verification operations using
        ECDSA and the specified hash function
        cCs
||_dS)N)rM)r;rMr6r6r7rNEszECAlgorithm.__init__cCs�t|t�st|t�r|St|t�r~t|�}y,|jd�rFt|t�d�}nt|t�d�}Wq�t	k
rzt
|dt�d�}Yq�Xntd��|S)Nsecdsa-sha2-)rZ)r[rZzExpecting a PEM-formatted key.)r\rrrr	r]rr rr^rr_)r;r<r6r6r7r=Hs



zECAlgorithm.prepare_keycCs"|j|tj|j���}t||j�S)N)r?r�ECDSArMr�curve)r;r>r<�der_sigr6r6r7r?`szECAlgorithm.signcCs\yt||j�}Wntk
r$dSXy|j||tj|j���dStk
rVdSXdS)NFT)rrwr^rArrvrMr!)r;r>r<r@rxr6r6r7rAeszECAlgorithm.verifyN)rFrGrHrIrr.r/r0rNr=r?rAr6r6r6r7r4<sr4c@s eZdZdZdd�Zdd�ZdS)r5zA
        Performs a signature using RSASSA-PSS with MGF1
        cCs*|j|tjtj|j��|jjd�|j��S)N)�mgf�salt_length)r?r�PSS�MGF1rM�digest_size)r;r>r<r6r6r7r?vs
zRSAPSSAlgorithm.signc
CsJy0|j||tjtj|j��|jjd�|j��dStk
rDdSXdS)N)ryrzTF)rArr{r|rMr}r!)r;r>r<r@r6r6r7rA�s

zRSAPSSAlgorithm.verifyN)rFrGrHrIr?rAr6r6r6r7r5qs
r5)8rYrWrR�compatrr�
exceptionsrZutilsrrrr	r
rrr
rrZcryptography.hazmat.primitivesrZ,cryptography.hazmat.primitives.serializationrrrZ-cryptography.hazmat.primitives.asymmetric.rsarrrrrrrrZ,cryptography.hazmat.primitives.asymmetric.ecrrZ)cryptography.hazmat.primitives.asymmetricrrZcryptography.hazmat.backendsr Zcryptography.exceptionsr!r1�ImportError�setZrequires_cryptographyr8�objectr9r,r-r3r4r5r6r6r6r7�<module>s60(
(-5

Zerion Mini Shell 1.0