HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/jwt/__pycache__/algorithms.cpython-310.pyc
o

weht�@s�ddlmZddlZddlZddlZddlZddlmZmZddl	m
Z
mZmZm
Z
mZmZmZddlmZddlmZmZddlmZmZmZmZmZmZmZmZmZej d	kr`dd
l	m!Z!ndd
l"m!Z!zjddl#m$Z$ddl%m&Z&dd
l'm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7m8Z8ddl9m:Z:m;Z;ddl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDddlEmFZFmGZGmHZHmIZImJZJmKZKmLZLdZMWneNy�dZMYnwe
�re=e?BZOe2e4BZPe:e;Be7Be8BZQeOePBeQBZRe=e2Be:Be7BZSe?e4Be;Be8BZThd�ZUd)dd�ZVGdd�de�ZWGdd�deW�ZXGdd �d eW�ZYeM�rKGd!d"�d"eW�ZZGd#d$�d$eW�Z[Gd%d&�d&eZ�Z\Gd'd(�d(eW�Z]dSdS)*�)�annotationsN)�ABC�abstractmethod)�
TYPE_CHECKING�Any�ClassVar�NoReturn�Union�cast�overload���InvalidKeyError)�HashlibHash�JWKDict)	�base64url_decode�base64url_encode�der_to_raw_signature�force_bytes�from_base64url_uint�
is_pem_format�
is_ssh_key�raw_to_der_signature�to_base64url_uint)��)�Literal)�InvalidSignature)�default_backend)�hashes)�padding)
�ECDSA�	SECP256K1�	SECP256R1�	SECP384R1�	SECP521R1�
EllipticCurve�EllipticCurvePrivateKey�EllipticCurvePrivateNumbers�EllipticCurvePublicKey�EllipticCurvePublicNumbers)�Ed448PrivateKey�Ed448PublicKey)�Ed25519PrivateKey�Ed25519PublicKey)�
RSAPrivateKey�RSAPrivateNumbers�RSAPublicKey�RSAPublicNumbers�rsa_crt_dmp1�rsa_crt_dmq1�rsa_crt_iqmp�rsa_recover_prime_factors)�Encoding�NoEncryption�
PrivateFormat�PublicFormat�load_pem_private_key�load_pem_public_key�load_ssh_public_keyTF>�ES256�ES384�ES512�ES521�EdDSA�PS256�PS384�PS512�RS256�RS384�RS512�ES256K�return�dict[str, Algorithm]cCs�t�ttj�ttj�ttj�d�}trG|�ttj�ttj�ttj�ttj�ttj�ttj�ttj�ttj�t	t	j�t	t	j�t	t	j�t
�d��|S)zE
    Returns the algorithms that are implemented by the library.
    )�none�HS256�HS384�HS512)rFrGrHr>rIr?rAr@rCrDrErB)�
NoneAlgorithm�
HMACAlgorithm�SHA256�SHA384�SHA512�
has_crypto�update�RSAAlgorithm�ECAlgorithm�RSAPSSAlgorithm�OKPAlgorithm)�default_algorithms�r\�G/home/arjun/projects/env/lib/python3.10/site-packages/jwt/algorithms.py�get_default_algorithmsps0����r^c@s�eZdZdZd"dd�Zed#d	d
��Zed$dd
��Zed%dd��Ze	e
ed&dd����Ze	e
ed'd(dd����Ze
ed'd)dd���Ze
ed*dd ���Zd!S)+�	AlgorithmzH
    The interface for an algorithm used to sign and verify tokens.
    �bytestr�bytesrJcCsjt|dd�}|durt�tr-t|t�r-t|tj�r-tj|�t	�d�}|�
|�t|���St||��
��S)z�
        Compute a hash digest using the specified algorithm's hash algorithm.

        If there is no hash algorithm, raises a NotImplementedError.
        �hash_algN)�backend)�getattr�NotImplementedErrorrU�
isinstance�type�
issubclassr�
HashAlgorithm�HashrrVra�finalize�digest)�selfr`rbrlr\r\r]�compute_hash_digest�s��
�
zAlgorithm.compute_hash_digest�keyrcC�dS)z�
        Performs necessary validation and conversions on the key and returns
        the key value in the proper format for sign() and verify().
        Nr\�rmror\r\r]�prepare_key��zAlgorithm.prepare_key�msgcCrp)zn
        Returns a digital signature for the specified message
        using the specified key value.
        Nr\�rmrtror\r\r]�sign�rszAlgorithm.sign�sig�boolcCrp)zz
        Verifies that the specified digital signature is valid
        for the specified message and key values.
        Nr\�rmrtrorwr\r\r]�verify�rszAlgorithm.verify�as_dict�
Literal[True]rcC�dS�Nr\��key_objr{r\r\r]�to_jwk��zAlgorithm.to_jwkF�Literal[False]�strcCr}r~r\rr\r\r]r��r��Union[JWKDict, str]cCrp)z3
        Serializes a given key into a JWK
        Nr\rr\r\r]r��rs�jwk�
str | JWKDictcCrp)zJ
        Deserializes a given key from JWK back into a key object
        Nr\�r�r\r\r]�from_jwk�rszAlgorithm.from_jwkN)r`rarJra)rorrJr)rtrarorrJra)rtrarorrwrarJrx)r{r|rJr�F)r{r�rJr�)r{rxrJr�)r�r�rJr)
�__name__�
__module__�__qualname__�__doc__rnrrrrvrzr�staticmethodr�r�r\r\r\r]r_�s.
r_c@sLeZdZdZddd�Zdd
d�Zddd�Zedd dd��Zed!dd��Z	dS)"rPzZ
    Placeholder for use when no signing or verification
    operations are required.
    ro�
str | NonerJ�NonecCs |dkrd}|durtd��|S)N�z*When alg = "none", key value must be None.r
rqr\r\r]rr�s
zNoneAlgorithm.prepare_keyrtracCrp)N�r\rur\r\r]rv��zNoneAlgorithm.signrwrxcCrp)NFr\ryr\r\r]rz�r�zNoneAlgorithm.verifyFr�rr{rcC�t��r~�rerr\r\r]r���zNoneAlgorithm.to_jwkr�r�cCr�r~r�r�r\r\r]r��r�zNoneAlgorithm.from_jwkN)ror�rJr�)rtraror�rJra)rtraror�rwrarJrxr�)r�rr{rxrJr)r�r�rJr)
r�r�r�r�rrrvrzr�r�r�r\r\r\r]rP�s

	
rPc@s�eZdZUdZejZded<ejZ	ded<ej
Zded<d)d
d�Zd*dd�Z
eed+dd���Zeed,d-dd���Zed,d.dd��Zed/d d!��Zd0d#d$�Zd1d&d'�Zd(S)2rQzf
    Performs signing and verification operations using HMAC
    and the specified hash function.
    zClassVar[HashlibHash]rRrSrTrbrrJr�cC�
||_dSr~�rb�rmrbr\r\r]�__init__�
zHMACAlgorithm.__init__ro�str | bytesracCs$t|�}t|�st|�rtd��|S)NzdThe specified key is an asymmetric key or x509 certificate and should not be used as an HMAC secret.)rrrr�rmro�	key_bytesr\r\r]rrs�zHMACAlgorithm.prepare_keyr�r{r|rcCr}r~r\rr\r\r]r��zHMACAlgorithm.to_jwkFr�r�cCr}r~r\rr\r\r]r�r�rxr�cCs(tt|����dd�}|r|St�|�S)N�oct)�k�kty)rr�decode�json�dumps)r�r{r�r\r\r]r�s�
r�r�cCshzt|t�rt�|�}n
t|t�r|}nt�Wnty"td��w|�d�dkr.td��t|d�S)N�Key is not valid JSONr�r�zNot an HMAC keyr�)	rfr�r��loads�dict�
ValueErrorr�getr)r��objr\r\r]r�)s

��zHMACAlgorithm.from_jwkrtcCst�|||j���Sr~)�hmac�newrbrlrur\r\r]rv:�zHMACAlgorithm.signrwcCst�||�||��Sr~)r��compare_digestrvryr\r\r]rz=r�zHMACAlgorithm.verifyN)rbrrJr�)ror�rJra)r�r�r{r|rJrr�)r�r�r{r�rJr�)r�r�r{rxrJr�)r�r�rJra)rtrarorarJra)rtrarorarwrarJrx)r�r�r�r��hashlib�sha256rR�__annotations__�sha384rS�sha512rTr�rrrr�r�r�rvrzr\r\r\r]rQ�s&



rQc@s�eZdZUdZejZded<ejZded<ejZded<d,d
d�Z	d-dd�Z
eed.dd���Z
eed/d0dd���Z
e	d/d1dd��Z
ed2d d!��Zd3d%d&�Zd4d)d*�Zd+S)5rWz~
        Performs signing and verification operations using
        RSASSA-PKCS-v1_5 and the specified hash function.
        �$ClassVar[type[hashes.HashAlgorithm]]rRrSrTrb�type[hashes.HashAlgorithm]rJr�cCr�r~r�r�r\r\r]r�Mr�zRSAAlgorithm.__init__ro�AllowedRSAKeys | str | bytes�AllowedRSAKeyscCs�t|ttf�r	|St|ttf�std��t|�}z|�d�r&ttt	|��WSttt
|dd��WSty?ttt|��YSw)N�Expecting a PEM-formatted key.sssh-rsa��password)
rfr/r1rar��	TypeErrorr�
startswithr
r=r;r�r<r�r\r\r]rrPs
��zRSAAlgorithm.prepare_keyr�r{r|rcCr}r~r\rr\r\r]r�cr�zRSAAlgorithm.to_jwkFr�r�cCr}r~r\rr\r\r]r�hr�rxr�cCs�d}t|d�rD|��}ddgt|jj���t|jj���t|j���t|j���t|j	���t|j
���t|j���t|j���d�
}n t|d�r`|��}ddgt|j���t|j���d�}nt
d��|rh|St�|�S)N�private_numbers�RSArv)
r��key_ops�n�e�d�p�q�dp�dq�qirz)r�r�r�r��Not a public or private key)�hasattrr�r�public_numbersr�r�r�r�r�r��dmp1�dmq1�iqmprr�r�)r�r{r��numbersr\r\r]r�ms2
�

�
r�r�c		s�zt|t�rt�|��n
t|t�r|�nt�Wnty"td��w��d�dkr.td��d�vr�d�vr�d�vr�d�vrBtd	��gd
�}�fdd�|D�}t|�}|r]t	|�s]td
��t
t�d�t�d��}|r�tt�d�t�d�t�d�t�d�t�d�t�d�|d�}|��St�d�}t
|j||j�\}}t|||t||�t||�t||�|d�}|��Sd�vr�d�vr�t
t�d�t�d����Std��)Nr�r�r�zNot an RSA keyr�r�r��othz5Unsupported RSA private key: > 2 primes not supported)r�r�r�r�r�csg|]}|�v�qSr\r\)�.0�prop�r�r\r]�
<listcomp>�sz)RSAAlgorithm.from_jwk.<locals>.<listcomp>z@RSA key must include all parameters if any are present besides dr�r�r�r�r�)r�r�r�r�r�r�r�r�)rfr�r�r�r�r�rr��any�allr2rr0r6r�r�r3r4r5�private_key�
public_key)	r��other_props�props_found�any_props_foundr�r�r�r�r�r\r�r]r��sz

����

�





��
��


��zRSAAlgorithm.from_jwkrtrar/cCs|�|t��|���Sr~)rvr �PKCS1v15rbrur\r\r]rv�szRSAAlgorithm.signr1rwcCs4z|�||t��|���WdStyYdSw)NTF)rzr r�rbrryr\r\r]rz�s�zRSAAlgorithm.verifyN�rbr�rJr�)ror�rJr�)r�r�r{r|rJrr�)r�r�r{r�rJr�)r�r�r{rxrJr�)r�r�rJr��rtraror/rJra�rtraror1rwrarJrx)r�r�r�r�rrRr�rSrTr�rrrr�r�r�rvrzr\r\r\r]rWCs(


�(
GrWc@s�eZdZUdZejZded<ejZded<ejZded<d,d
d�Z	d-dd�Z
d.dd�Zd/dd�Ze
ed0dd ���Ze
ed1d2d$d ���Ze	!d1d3d&d ��Zed4d)d*��Zd+S)5rXzr
        Performs signing and verification operations using
        ECDSA and the specified hash function
        r�rRrSrTrbr�rJr�cCr�r~r�r�r\r\r]r��r�zECAlgorithm.__init__ro�AllowedECKeys | str | bytes�
AllowedECKeyscCs�t|ttf�r	|St|ttf�std��t|�}z|�d�r#t|�}nt	|�}Wnt
y7t|dd�}Ynwt|ttf�sCtd��|S)Nr�secdsa-sha2-r�zcExpecting a EllipticCurvePrivateKey/EllipticCurvePublicKey. Wrong key provided for ECDSA algorithms)
rfr'r)rar�r�rr�r=r<r�r;r)rmror��
crypto_keyr\r\r]rr�s(

����zECAlgorithm.prepare_keyrtrar'cCs |�|t|����}t||j�Sr~)rvr!rbr�curve)rmrtro�der_sigr\r\r]rvszECAlgorithm.sign�'AllowedECKeys'rwrxcCsnzt||j�}Wn
tyYdSwzt|t�r|��n|}|�||t|����WdSt	y6YdSw)NFT)
rr�r�rfr'r�rzr!rbr)rmrtrorwr�r�r\r\r]rzs�
���zECAlgorithm.verifyr�r{r|rcCr}r~r\rr\r\r]r�)r�zECAlgorithm.to_jwkFr�r�cCr}r~r\rr\r\r]r�.r�r�cCs�t|t�r|����}nt|t�r|��}ntd��t|jt�r#d}n#t|jt�r,d}nt|jt	�r5d}nt|jt
�r>d}ntd|j����d|t|j��
�t|j��
�d�}t|t�rgt|��j��
�|d	<|rk|St�|�S)
Nr��P-256�P-384�P-521�	secp256k1�Invalid curve: �EC)r��crv�x�yr�)rfr'r�r�r)rr�r#r$r%r"rr�r�r�r��
private_valuer�r�)r�r{r�r�r�r\r\r]r�3s8


�
��
r�r�cCszt|t�rt�|�}n
t|t�r|}nt�Wnty"td��w|�d�dkr.td��d|vs6d|vr:td��t|�d��}t|�d��}|�d�}|dkrlt	|�t	|�kr_d	krhntd
��t
�}nhtd
��|dkr�t	|�t	|�kr~dkr�ntd
��t�}nItd
��|dkr�t	|�t	|�kr�dkr�ntd��t�}n*td��|dkr�t	|�t	|�kr�d	kr�ntd��t
�}ntd��td|����ttj|dd�tj|dd�|d�}d|vr�|��St|�d��}t	|�t	|�k�rtdt	|�|��ttj|dd�|���S)Nr�r�r�zNot an Elliptic curve keyr�r�r�r�� z)Coords should be 32 bytes for curve P-256r��0z)Coords should be 48 bytes for curve P-384r��Bz)Coords should be 66 bytes for curve P-521r�z-Coords should be 32 bytes for curve secp256k1r��big)�	byteorder)r�r�r�r�z!D should be {} bytes for curve {})rfr�r�r�r�r�rr�r�lenr#r$r%r"r*�int�
from_bytesr�r(r�)r�r�r�r�r��	curve_objr�r�r\r\r]r�Zsv

��
�������
���zECAlgorithm.from_jwkNr�)ror�rJr�)rtraror'rJra)rtraror�rwrarJrx)r�r�r{r|rJrr�)r�r�r{r�rJr�)r�r�r{rxrJr�)r�r�rJr�)r�r�r�r�rrRr�rSrTr�rrrvrzrr�r�r�r\r\r\r]rX�s(




�&rXc@s$eZdZdZddd�Zddd
�ZdS)rYzA
        Performs a signature using RSASSA-PSS with MGF1
        rtraror/rJcCs,|�|tjt�|���|��jd�|���S)N��mgf�salt_length)rvr �PSS�MGF1rb�digest_sizerur\r\r]rv�s��zRSAPSSAlgorithm.signr1rwrxc	CsJz|�||tjt�|���|��jd�|���WdSty$YdSw)Nr�TF)rzr r�r�rbr�rryr\r\r]rz�s��	�zRSAPSSAlgorithm.verifyNr�r�)r�r�r�r�rvrzr\r\r\r]rY�s

rYc@s|eZdZdZd'dd�Zd(dd�Zd)dd�Zd*dd�Zee	d+dd���Z
ee	d,d-dd���Z
e	d,d.d!d��Z
e	d/d$d%��Zd&S)0rZz�
        Performs signing and verification operations using EdDSA

        This class requires ``cryptography>=2.6`` to be installed.
        �kwargsrrJr�cKr}r~r\)rmrr\r\r]r��r�zOKPAlgorithm.__init__ro�AllowedOKPKeys | str | bytes�AllowedOKPKeyscCs�t|ttf�r?t|t�r|�d�n|}t|t�r|�d�n|}d|vr(t|�}nd|vr3t|dd�}n|dd�dkr?t|�}t|tt	t
tf�sLtd��|S)	N�utf-8z-----BEGIN PUBLICz-----BEGIN PRIVATEr�r�zssh-zcExpecting a EllipticCurvePrivateKey/EllipticCurvePublicKey. Wrong key provided for EdDSA algorithms)
rfrar�r��encoder<r;r=r-r.r+r,r)rmro�key_strr�r\r\r]rr�s"

��zOKPAlgorithm.prepare_keyrtr��#Ed25519PrivateKey | Ed448PrivateKeyracCs"t|t�r
|�d�n|}|�|�S)aS
            Sign a message ``msg`` using the EdDSA private key ``key``
            :param str|bytes msg: Message to sign
            :param Ed25519PrivateKey}Ed448PrivateKey key: A :class:`.Ed25519PrivateKey`
                or :class:`.Ed448PrivateKey` isinstance
            :return bytes signature: The signature, as bytes
            r)rfr�rrv)rmrtro�	msg_bytesr\r\r]rv�s

zOKPAlgorithm.signrwrxcCsrz.t|t�r|�d�n|}t|t�r|�d�n|}t|ttf�r$|��n|}|�||�WdSty8YdSw)a�
            Verify a given ``msg`` against a signature ``sig`` using the EdDSA key ``key``

            :param str|bytes sig: EdDSA signature to check ``msg`` against
            :param str|bytes msg: Message to sign
            :param Ed25519PrivateKey|Ed25519PublicKey|Ed448PrivateKey|Ed448PublicKey key:
                A private or public EdDSA key instance
            :return bool verified: True if signature is valid, False if not.
            rTF)rfr�rr-r+r�rzr)rmrtrorwr�	sig_bytesr�r\r\r]rz�s
���zOKPAlgorithm.verifyr{r|rcCr}r~r\�ror{r\r\r]r�r�zOKPAlgorithm.to_jwkFr�r�cCr}r~r\r
r\r\r]r�	r�r�cCs�t|ttf�r.|jtjtjd�}t|t�rdnd}tt|���	�d|d�}|r)|St
�|�St|tt
f�rp|jtjtjt�d�}|��jtjtjd�}t|t�rRdnd}tt|���	�tt|���	�d|d�}|rk|St
�|�Std��)	N)�encoding�format�Ed25519�Ed448�OKP)r�r�r�)rr�encryption_algorithm)r�r�r�r�r�)rfr.r,�public_bytesr7�Rawr:rrr�r�r�r-r+�
private_bytesr9r8r�r)ror{r�r�r�r�r\r\r]r�sB��
���
r�r�c
Cszt|t�rt�|�}n
t|t�r|}nt�Wnty"td��w|�d�dkr.td��|�d�}|dkrB|dkrBtd|����d	|vrJtd
��t|�d	��}z+d|vrf|dkr`t	�
|�WSt�
|�WSt|�d��}|dkrwt�
|�WSt�
|�WSty�}ztd�|�d}~ww)
Nr�r�rzNot an Octet Key Pairr�r
rr�r�zOKP should have "x" parameterr�zInvalid key parameter)rfr�r�r�r�r�rr�rr.�from_public_bytesr,r-�from_private_bytesr+)r�r�r�r�r��errr\r\r]r�=s>

��

��zOKPAlgorithm.from_jwkN)rrrJr�)rorrJr)rtr�rorrJra)rtr�rorrwr�rJrx)rorr{r|rJrr�)rorr{r�rJr�)rorr{rxrJr�)r�r�rJr)r�r�r�r�r�rrrvrzrr�r�r�r\r\r\r]rZ�s 




.rZ)rJrK)^�
__future__rr�r�r��sys�abcrr�typingrrrrr	r
r�
exceptionsr�typesrr�utilsrrrrrrrrr�version_infor�typing_extensions�cryptography.exceptionsr�cryptography.hazmat.backendsr�cryptography.hazmat.primitivesr�)cryptography.hazmat.primitives.asymmetricr �,cryptography.hazmat.primitives.asymmetric.ecr!r"r#r$r%r&r'r(r)r*�/cryptography.hazmat.primitives.asymmetric.ed448r+r,�1cryptography.hazmat.primitives.asymmetric.ed25519r-r.�-cryptography.hazmat.primitives.asymmetric.rsar/r0r1r2r3r4r5r6�,cryptography.hazmat.primitives.serializationr7r8r9r:r;r<r=rU�ModuleNotFoundErrorr�r�r�AllowedKeys�AllowedPrivateKeys�AllowedPublicKeys�requires_cryptographyr^r_rPrQrWrXrYrZr\r\r\r]�<module>sh$,
0($

����
"KF&7���