
    [hht                       d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZ ej         d	k    rd d
l	m!Z! nd d
l"m!Z! 	 d dl#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z:m;Z; d dl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZD d dlEmFZFmGZGmHZHmIZImJZJmKZKmLZL dZMn# eN$ r dZMY nw xY we
r3e=e?z  ZOe2e4z  ZPe:e;z  e7z  e8z  ZQeOePz  eQz  ZRe=e2z  e:z  e7z  ZSe?e4z  e;z  e8z  ZTh dZUd(dZV G d de          ZW G d deW          ZX G d deW          ZYeMr: G d  d!eW          ZZ G d" d#eW          Z[ G d$ d%eZ          Z\ G d& d'eW          Z]dS dS ))    )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]c                    t                      t          t          j                  t          t          j                  t          t          j                  d} t
          r+|                     t          t          j                  t          t          j                  t          t          j                  t          t          j                  t          t          j                  t          t          j                  t          t          j                  t          t          j                  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)rG   rH   rI   r?   rJ   r@   rB   rA   rD   rE   rF   rC   )NoneAlgorithmHMACAlgorithmSHA256SHA384SHA512
has_cryptoupdateRSAAlgorithmECAlgorithmRSAPSSAlgorithmOKPAlgorithm)default_algorithmss    ]/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/jwt/algorithms.pyget_default_algorithmsr_   p   s   
 }344}344}344	   
!!%l&9::%l&9::%l&9::$[%788%k&899$[%788$[%788$&  ))?@@()?@@()?@@% 	
 	
 	
&     c                  &   e Zd ZdZddZedd            Zedd
            Zedd            Ze	e
ed d                                    Ze	e
ed!d"d                                    Ze
ed!d#d                        Ze
ed$d                        ZdS )%	AlgorithmzH
    The interface for an algorithm used to sign and verify tokens.
    bytestrbytesrK   c                   t          | dd          }|t          t          rt          |t                    rzt          |t          j                  r`t          j         |            t                                }|
                    |           t          |                                          S t           ||                                                    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NotImplementedErrorrW   
isinstancetype
issubclassr    HashAlgorithmHashr   rX   rd   finalizedigest)selfrc   rf   rp   s       r^   compute_hash_digestzAlgorithm.compute_hash_digest   s     4T22%% 		58T**		5 8V%9::		5
 [_5F5FGGGFMM'"""**+++'**1133444r`   keyr   c                    dS )z
        Performs necessary validation and conversions on the key and returns
        the key value in the proper format for sign() and verify().
        N rq   rs   s     r^   prepare_keyzAlgorithm.prepare_key         r`   msgc                    dS )zn
        Returns a digital signature for the specified message
        using the specified key value.
        Nru   rq   ry   rs   s      r^   signzAlgorithm.sign   rx   r`   sigboolc                    dS )zz
        Verifies that the specified digital signature is valid
        for the specified message and key values.
        Nru   rq   ry   rs   r}   s       r^   verifyzAlgorithm.verify   rx   r`   as_dictLiteral[True]r   c                    d S Nru   key_objr   s     r^   to_jwkzAlgorithm.to_jwk   	     	r`   FLiteral[False]strc                    d S r   ru   r   s     r^   r   zAlgorithm.to_jwk   r   r`   Union[JWKDict, str]c                    dS )z3
        Serializes a given key into a JWK
        Nru   r   s     r^   r   zAlgorithm.to_jwk   rx   r`   jwkstr | JWKDictc                    dS )zJ
        Deserializes a given key from JWK back into a key object
        Nru   r   s    r^   from_jwkzAlgorithm.from_jwk   rx   r`   N)rc   rd   rK   rd   )rs   r   rK   r   )ry   rd   rs   r   rK   rd   )ry   rd   rs   r   r}   rd   rK   r~   )r   r   rK   r   F)r   r   rK   r   )r   r~   rK   r   )r   r   rK   r   )__name__
__module____qualname____doc__rr   r   rw   r|   r   r   staticmethodr   r   ru   r`   r^   rb   rb      sX        5 5 5 5,    ^    ^    ^    ^ \ X     ^ \ X     ^ \
    ^ \  r`   rb   c                  \    e Zd ZdZddZdd	ZddZeddd            Zedd            Z	dS )rR   zZ
    Placeholder for use when no signing or verification
    operations are required.
    rs   
str | NonerK   Nonec                8    |dk    rd }|t          d          |S )N z*When alg = "none", key value must be None.r   rv   s     r^   rw   zNoneAlgorithm.prepare_key   s)    "99C?!"NOOO
r`   ry   rd   c                    dS )Nr`   ru   r{   s      r^   r|   zNoneAlgorithm.sign   s    sr`   r}   r~   c                    dS )NFru   r   s       r^   r   zNoneAlgorithm.verify   s    ur`   Fr   r   r   r	   c                    t                      r   ri   r   s     r^   r   zNoneAlgorithm.to_jwk       !###r`   r   r   c                    t                      r   r   r   s    r^   r   zNoneAlgorithm.from_jwk   r   r`   N)rs   r   rK   r   )ry   rd   rs   r   rK   rd   )ry   rd   rs   r   r}   rd   rK   r~   r   )r   r   r   r~   rK   r	   )r   r   rK   r	   )
r   r   r   r   rw   r|   r   r   r   r   ru   r`   r^   rR   rR      s         
          $ $ $ $ \$ $ $ $ \$ $ $r`   rR   c                      e Zd ZU dZej        Zded<   ej        Z	ded<   ej
        Zded<   d#d
Zd$dZeed%d                        Zeed&d'd                        Zed&d(d            Zed)d            Zd*dZd+d!Zd"S ),rS   zf
    Performs signing and verification operations using HMAC
    and the specified hash function.
    zClassVar[HashlibHash]rT   rU   rV   rf   r   rK   r   c                    || _         d S r   rf   rq   rf   s     r^   __init__zHMACAlgorithm.__init__  s     r`   rs   str | bytesrd   c                ~    t          |          }t          |          st          |          rt          d          |S )NzdThe specified key is an asymmetric key or x509 certificate and should not be used as an HMAC secret.)r   r   r   r   rq   rs   	key_bytess      r^   rw   zHMACAlgorithm.prepare_key  sM    $$	## 	z)'<'< 	!9  
 r`   r   r   r   r   c                    d S r   ru   r   s     r^   r   zHMACAlgorithm.to_jwk  	     	r`   Fr   r   c                    d S r   ru   r   s     r^   r   zHMACAlgorithm.to_jwk  r   r`   r~   r   c                    t          t          |                                                     dd}|r|S t          j        |          S )Noct)kkty)r   r   decodejsondumps)r   r   r   s      r^   r   zHMACAlgorithm.to_jwk  sO     "+g"6"677>>@@
 

  	#J:c??"r`   r   r   c                L   	 t          | t                    rt          j        |           }nt          | t                    r| }nt
          n# t
          $ r t          d          w xY w|                    d          dk    rt          d          t          |d                   S )NKey is not valid JSONr   r   zNot an HMAC keyr   )	rj   r   r   loadsdict
ValueErrorr   getr   )r   objs     r^   r   zHMACAlgorithm.from_jwk)  s    	;#s## !#z#C&& !   	; 	; 	;!"9:::	; 775>>U""!"3444C)))   A	A A&ry   c                \    t          j        ||| j                                                  S r   )hmacnewrf   rp   r{   s      r^   r|   zHMACAlgorithm.sign:  s$    xS$-0077999r`   r}   c                T    t          j        ||                     ||                    S r   )r   compare_digestr|   r   s       r^   r   zHMACAlgorithm.verify=  s#    "3		#s(;(;<<<r`   N)rf   r   rK   r   )rs   r   rK   rd   )r   r   r   r   rK   r   r   )r   r   r   r   rK   r   )r   r   r   r~   rK   r   )r   r   rK   rd   )ry   rd   rs   rd   rK   rd   )ry   rd   rs   rd   r}   rd   rK   r~   )r   r   r   r   hashlibsha256rT   __annotations__sha384rU   sha512rV   r   rw   r   r   r   r   r|   r   ru   r`   r^   rS   rS      sI         
 %,NF2222$+NF2222$+NF2222! ! ! !	 	 	 	    \ X     \ X 	# 	# 	# 	# \	# * * * \* : : : := = = = = =r`   rS   c                     e Zd ZU dZej        Zded<   ej        Zded<   ej        Zded<   d&d
Z	d'dZ
eed(d                        Zeed)d*d                        Ze	 d)d+d            Zed,d            Zd-d!Zd.d$Zd%S )/rY   z~
        Performs signing and verification operations using
        RSASSA-PKCS-v1_5 and the specified hash function.
        $ClassVar[type[hashes.HashAlgorithm]]rT   rU   rV   rf   type[hashes.HashAlgorithm]rK   r   c                    || _         d S r   r   r   s     r^   r   zRSAAlgorithm.__init__M      $DMMMr`   rs   AllowedRSAKeys | str | bytesAllowedRSAKeysc                   t          |t          t          f          r|S t          |t          t          f          st          d          t          |          }	 |                    d          r"t          t          t          |                    S t          t          t          |d                     S # t          $ r% t          t          t          |                    cY S w xY w)NExpecting a PEM-formatted key.s   ssh-rsapassword)rj   r0   r2   rd   r   	TypeErrorr   
startswithr   r>   r<   r   r=   r   s      r^   rw   zRSAAlgorithm.prepare_keyP  s    #|<== 
cE3<00 B @AAA#C((IJ''
33 .A).L.LMMM%';IPT'U'U'U    J J JL*=i*H*HIIIIIJs   6B5 #B5 5,C$#C$r   r   r   r   c                    d S r   ru   r   s     r^   r   zRSAAlgorithm.to_jwkc  	     Cr`   Fr   r   c                    d S r   ru   r   s     r^   r   zRSAAlgorithm.to_jwkh  r   r`   r~   r   c                   d }t          | d          rM|                                 }ddgt          |j        j                                                  t          |j        j                                                  t          |j                                                  t          |j                                                  t          |j	                                                  t          |j
                                                  t          |j                                                  t          |j                                                  d
}nt          | d          re|                                 }ddgt          |j                                                  t          |j                                                  d}nt          d          |r|S t          j        |          S )Nprivate_numbersRSAr|   )
r   key_opsnedpqdpdqqir   )r   r   r   r   Not a public or private key)hasattrr   r   public_numbersr   r   r   r   r   r   dmp1dmq1iqmpr   r   r   )r   r   r   numberss       r^   r   zRSAAlgorithm.to_jwkm  s    *.Cw 122 E!1133 ! &x*7+A+CDDKKMM*7+A+CDDKKMM*7955<<>>*7955<<>>*7955<<>>+GL99@@BB+GL99@@BB+GL99@@BB  (++ E!0022 ! (z*7955<<>>*7955<<>>	  &&CDDD '
z#&r`   r   r   c                8  	 	 t          | t                    rt          j        |           	nt          | t                    r| 	nt
          n# t
          $ r t          d          w xY w	                    d          dk    rt          d          d	v rd	v rd	v rd	v rt          d	          g d
}	fd|D             }t          |          }|rt          |          st          d          t          t          	d                   t          	d                             }|rt          t          	d                   t          	d                   t          	d                   t          	d                   t          	d                   t          	d                   |          }nst          	d                   }t          |j        ||j                  \  }}t          |||t!          ||          t#          ||          t%          ||          |          }|                                S d	v rLd	v rHt          t          	d                   t          	d                                                             S t          d          )Nr   r   r   zNot an RSA keyr   r   r   othz5Unsupported RSA private key: > 2 primes not supported)r   r   r   r   r   c                    g | ]}|v S ru   ru   ).0propr   s     r^   
<listcomp>z)RSAAlgorithm.from_jwk.<locals>.<listcomp>  s    CCCtts{CCCr`   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   )rj   r   r   r   r   r   r   r   anyallr3   r   r1   r7   r   r   r4   r5   r6   private_key
public_key)
r   other_propsprops_foundany_props_foundr   r   r   r   r   r   s
            @r^   r   zRSAAlgorithm.from_jwk  s   ?c3'' %*S//CCT** %CC$$ ? ? ?%&=>>>? wwu~~&&%&6777czzcSjjSCZZC<<)O   ;::CCCC{CCC"%k"2"2" 3{+;+; )Z   "2'C11'C11" "
 # /-c#h77-c#h77-c#h770T;;0T;;0T;;'5  GG ,CH55A4&(!^-= DAq 0)!Q//)!Q//)!Q//'5  G **,,,s

''C11'C11  *,,
 &&CDDDs   A	A A'ry   rd   r0   c                v    |                     |t          j                    |                                           S r   )r|   r!   PKCS1v15rf   r{   s      r^   r|   zRSAAlgorithm.sign  s)    88C!1!3!3T]]__EEEr`   r2   r}   c                    	 |                     ||t          j                    |                                            dS # t          $ r Y dS w xY w)NTF)r   r!   r   rf   r   r   s       r^   r   zRSAAlgorithm.verify  sW    

3W%5%7%7IIIt#   uus   ;? 
AANrf   r   rK   r   )rs   r   rK   r   )r   r   r   r   rK   r   r   )r   r   r   r   rK   r   )r   r   r   r~   rK   r   )r   r   rK   r   ry   rd   rs   r0   rK   rd   ry   rd   rs   r2   r}   rd   rK   r~   )r   r   r   r   r    rT   r   rU   rV   r   rw   r   r   r   r   r|   r   ru   r`   r^   rY   rY   C  s^        	 	
 8>}DDDD7=}DDDD7=}DDDD	% 	% 	% 	%	J 	J 	J 	J& 
		 	 	 
 
	 
		 	 	 	 
 
	 
5:&	' &	' &	' &	' 
&	'P 
E	E E	E E	E 
E	EN	F 	F 	F 	F	 	 	 	 	 	r`   rY   c                     e Zd ZU dZej        Zded<   ej        Zded<   ej        Zded<   d&d
Z	d'dZ
d(dZd)dZeed*d                        Zeed+d,d                        Ze	 d+d-d!            Zed.d$            Zd%S )/rZ   zr
        Performs signing and verification operations using
        ECDSA and the specified hash function
        r   rT   rU   rV   rf   r   rK   r   c                    || _         d S r   r   r   s     r^   r   zECAlgorithm.__init__  r   r`   rs   AllowedECKeys | str | bytesAllowedECKeysc                   t          |t          t          f          r|S t          |t          t          f          st          d          t          |          }	 |                    d          rt          |          }nt          |          }n!# t          $ r t          |d           }Y nw xY wt          |t          t          f          st          d          |S )Nr   s   ecdsa-sha2-r   zcExpecting a EllipticCurvePrivateKey/EllipticCurvePublicKey. Wrong key provided for ECDSA algorithms)rj   r(   r*   rd   r   r   r   r   r>   r=   r   r<   r   )rq   rs   r   
crypto_keys       r^   rw   zECAlgorithm.prepare_key  s   # 79OPQQ 
cE3<00 B @AAA#C((I
L''77 @!4Y!?!?JJ!4Y!?!?J L L L1)dKKK


L 46LM   &y   s   4B B-,B-ry   rd   r(   c                    |                     |t          |                                                     }t          ||j                  S r   )r|   r"   rf   r   curve)rq   ry   rs   der_sigs       r^   r|   zECAlgorithm.sign  s7    hhsE$--//$:$:;;G';;;r`   'AllowedECKeys'r}   r~   c                <   	 t          ||j                  }n# t          $ r Y dS w xY w	 t          |t                    r|                                n|}|                    ||t          |                                                      dS # t          $ r Y dS w xY w)NFT)
r   r  r   rj   r(   r   r   r"   rf   r   )rq   ry   rs   r}   r  r   s         r^   r   zECAlgorithm.verify  s    .sCI>>   uu	 "#'>??CNN$$$ 
 !!'3dmmoo0F0FGGGt#   uus    
&&A!B 
BBr   r   r   r   c                    d S r   ru   r   s     r^   r   zECAlgorithm.to_jwk)  r   r`   Fr   r   c                    d S r   ru   r   s     r^   r   zECAlgorithm.to_jwk.  r   r`   r   c                p   t          | t                    r'|                                                                 }n9t          | t                    r|                                 }nt          d          t          | j        t                    rd}nnt          | j        t                    rd}nQt          | j        t                    rd}n4t          | j        t                    rd}nt          d| j                   d|t          |j                                                  t          |j                                                  d}t          | t                    r;t          |                                 j                                                  |d	<   |r|S t#          j        |          S )
Nr   P-256P-384P-521	secp256k1Invalid curve: EC)r   crvxyr   )rj   r(   r   r   r*   r   r  r$   r%   r&   r#   r   r  r   r  r   private_valuer   r   )r   r   r   r  r   s        r^   r   zECAlgorithm.to_jwk3  s    '#:;; E!(!3!3!5!5!D!D!F!FG%;<< E!(!7!7!9!9%&CDDD'-33 	IGM955 IGM955 IGM955 I!%&G&G&GHHH &~'788??AA&~'788??AA	# #C '#:;; ,++--; &(( C  '
z#&r`   r   r   c                   	 t          | t                    rt          j        |           }nt          | t                    r| }nt
          n# t
          $ r t          d          w xY w|                    d          dk    rt          d          d|vsd|vrt          d          t          |                    d                    }t          |                    d                    }|                    d          }|dk    rIt          |          t          |          cxk    rd	k    rn nt                      }nt          d
          |dk    rHt          |          t          |          cxk    rdk    rn nt                      }nt          d          |dk    rHt          |          t          |          cxk    rdk    rn nt                      }not          d          |dk    rHt          |          t          |          cxk    rd	k    rn nt                      }n!t          d          t          d|           t          t                              |d          t                              |d          |          }d|vr|                                S t          |                    d                    }t          |          t          |          k    rt          dt          |          |          t%          t                              |d          |                                          S )Nr   r   r  zNot an Elliptic curve keyr  r  r  r      z)Coords should be 32 bytes for curve P-256r  0   z)Coords should be 48 bytes for curve P-384r  B   z)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 {})rj   r   r   r   r   r   r   r   r   lenr$   r%   r&   r#   r+   int
from_bytesr   r)   r   )r   r   r  r  r  	curve_objr   r   s           r^   r   zECAlgorithm.from_jwkZ  s;   ?c3'' %*S//CCT** %CC$$ ? ? ?%&=>>>? wwu~~%%%&ABBB#~~C%&ABBB ..A ..AGGENNE q66SVV))))r))))) )II)*UVVV'!!q66SVV))))r))))) )II)*UVVV'!!q66SVV))))r))))) )II)*UVVV+%%q66SVV))))r))))) )II)G   &&?&?&?@@@7..e.44..e.44  N #~~%00222 ..A1vvQ%7Q   /qE22N kmmr   Nr   )rs   r  rK   r  )ry   rd   rs   r(   rK   rd   )ry   rd   rs   r	  r}   rd   rK   r~   )r   r  r   r   rK   r   r   )r   r  r   r   rK   r   )r   r  r   r~   rK   r   )r   r   rK   r  )r   r   r   r   r    rT   r   rU   rV   r   rw   r|   r   r   r   r   r   ru   r`   r^   rZ   rZ     sS        	 	
 8>}DDDD7=}DDDD7=}DDDD	% 	% 	% 	%	 	 	 	<	< 	< 	< 	<
	 	 	 	" 
		 	 	 
 
	 
		 	 	 	 
 
	 
49$	' $	' $	' $	' 
$	'L 
A	 A	 A	 
A	 A	 A	r`   rZ   c                  "    e Zd ZdZddZddZdS )r[   zA
        Performs a signature using RSASSA-PSS with MGF1
        ry   rd   rs   r0   rK   c           	         |                     |t          j        t          j        |                                           |                                 j                  |                                           S )Nmgfsalt_length)r|   r!   PSSMGF1rf   digest_sizer{   s      r^   r|   zRSAPSSAlgorithm.sign  s_    88T]]__55 $ ;     r`   r2   r}   r~   c           
        	 |                     ||t          j        t          j        |                                           |                                 j                  |                                            dS # t          $ r Y dS w xY w)Nr$  TF)r   r!   r'  r(  rf   r)  r   r   s       r^   r   zRSAPSSAlgorithm.verify  s    

K#L99$(MMOO$?   MMOO   t#   uus   A9A= =
B
BNr   r   )r   r   r   r   r|   r   ru   r`   r^   r[   r[     sF        	 		 	 	 		 	 	 	 	 	r`   r[   c                      e Zd ZdZd!dZd"d
Zd#dZd$dZee	d%d                        Z
ee	d&d'd                        Z
e	d&d(d            Z
e	d)d            Zd S )*r\   z
        Performs signing and verification operations using EdDSA

        This class requires ``cryptography>=2.6`` to be installed.
        kwargsr   rK   r   c                    d S r   ru   )rq   r,  s     r^   r   zOKPAlgorithm.__init__  s    Dr`   rs   AllowedOKPKeys | str | bytesAllowedOKPKeysc                   t          |t          t          f          rt          |t                    r|                    d          n|}t          |t                    r|                    d          n|}d|v rt          |          }n3d|v rt          |d           }n|dd         dk    rt          |          }t          |t          t          t          t          f          st          d          |S )	Nutf-8z-----BEGIN PUBLICz-----BEGIN PRIVATEr   r      zssh-zcExpecting a EllipticCurvePrivateKey/EllipticCurvePublicKey. Wrong key provided for EdDSA algorithms)rj   rd   r   r   encoder=   r<   r>   r.   r/   r,   r-   r   )rq   rs   key_strr   s       r^   rw   zOKPAlgorithm.prepare_key  s    #s|,, 	91;C1G1GP#**W---S3=c33G3GPCJJw///S	&'11-i88CC)W44.y4HHHCCQqS\V++-i88C "$4o~V   &y   Jr`   ry   r   #Ed25519PrivateKey | Ed448PrivateKeyrd   c                    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
            r1  )rj   r   r3  r|   )rq   ry   rs   	msg_bytess       r^   r|   zOKPAlgorithm.sign  s;     0:#s/C/CL

7+++I88I&&&r`   r}   r~   c                j   	 t          |t                    r|                    d          n|}t          |t                    r|                    d          n|}t          |t          t          f          r|                                n|}|                    ||           dS # t          $ r Y dS w xY w)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.
            r1  TF)rj   r   r3  r.   r,   r   r   r   )rq   ry   rs   r}   r7  	sig_bytesr   s          r^   r   zOKPAlgorithm.verify  s    3=c33G3GPCJJw///S	3=c33G3GPCJJw///S	 "#(9?'KLLCNN$$$ 
 !!)Y777t#   uus   B B$ $
B21B2r   r   r   c                    d S r   ru   rs   r   s     r^   r   zOKPAlgorithm.to_jwk  r   r`   Fr   r   c                    d S r   ru   r;  s     r^   r   zOKPAlgorithm.to_jwk	  r   r`   r   c                   t          | t          t          f          r|                     t          j        t          j                  }t          | t                    rdnd}t          t          |                    	                                d|d}|r|S t          j        |          S t          | t          t          f          r|                     t          j        t          j        t!                                }|                                                     t          j        t          j                  }t          | t                    rdnd}t          t          |                    	                                t          t          |                    	                                d|d}|r|S t          j        |          S t%          d          )	N)encodingformatEd25519Ed448OKP)r  r   r  )r>  r?  encryption_algorithm)r  r   r   r  r   )rj   r/   r-   public_bytesr8   Rawr;   r   r   r   r   r   r.   r,   private_bytesr:   r9   r   r   )rs   r   r  r  r   r   s         r^   r   zOKPAlgorithm.to_jwk  s   # 0.ABB +$$%\'+ %   $.c3C#D#DQii' *+a..99@@BB    +J:c??*# 1?CDD +%%%\(,)5 &   NN$$11%\'+ 2  
 $.c3D#E#ERii7)+a..99@@BB)+a..99@@BB 	   +J:c??*!"?@@@r`   r   r   c                <   	 t          | t                    rt          j        |           }nt          | t                    r| }nt
          n# t
          $ r t          d          w xY w|                    d          dk    rt          d          |                    d          }|dk    r|dk    rt          d|           d	|vrt          d
          t          |                    d	                    }	 d|vr.|dk    rt          j
        |          S t          j
        |          S t          |                    d                    }|dk    rt          j        |          S t          j        |          S # t
          $ r}t          d          |d }~ww xY w)Nr   r   rB  zNot an Octet Key Pairr  r@  rA  r  r  zOKP should have "x" parameterr   zInvalid key parameter)rj   r   r   r   r   r   r   r   r   r/   from_public_bytesr-   r.   from_private_bytesr,   )r   r   r  r  r   errs         r^   r   zOKPAlgorithm.from_jwk=  s   ?c3'' %*S//CCT** %CC$$ ? ? ?%&=>>>? wwu~~&&%&=>>>GGENNE	!!ew&6&6%&?&?&?@@@#~~%&EFFF ..A
Hc>>	))/A!DDD);A>>>$SWWS\\22I%%,?BBB&9!<<< H H H%&=>>CGHs6   A	A A&:E< E< ,;E< (E< <
FFFN)r,  r   rK   r   )rs   r.  rK   r/  )ry   r   rs   r5  rK   rd   )ry   r   rs   r/  r}   r   rK   r~   )rs   r/  r   r   rK   r   r   )rs   r/  r   r   rK   r   )rs   r/  r   r~   rK   r   )r   r   rK   r/  )r   r   r   r   r   rw   r|   r   r   r   r   r   ru   r`   r^   r\   r\     s       	 		 	 	 		 	 	 	.	' 	' 	' 	'	 	 	 	4 
		 	 	 
 
	 
		 	 	 	 
 
	 
,	A ,	A ,	A ,	A 
,	A\ 
 	H  	H  	H 
 	H  	H  	Hr`   r\   )rK   rL   )^
__future__r   r   r   r   sysabcr   r   typingr   r   r   r	   r
   r   r   
exceptionsr   typesr   r   utilsr   r   r   r   r   r   r   r   r   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.rsar0   r1   r2   r3   r4   r5   r6   r7   ,cryptography.hazmat.primitives.serializationr8   r9   r:   r;   r<   r=   r>   rW   ModuleNotFoundErrorr   r  r/  AllowedKeysAllowedPrivateKeysAllowedPublicKeysrequires_cryptographyr_   rb   rR   rS   rY   rZ   r[   r\   ru   r`   r^   <module>rb     s~   " " " " " "    



 # # # # # # # # P P P P P P P P P P P P P P P P P P ' ' ' ' ' ' ' ' ' ' ' ' ' '
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 v))))))/888888<<<<<<555555AAAAAA                                     	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                  JJ   JJJ  "\1N+.DDM,,>O  !=0>AK//2CCoU  	--0@@>Q 
       DH H H H H H H HV$ $ $ $ $I $ $ $<C= C= C= C= C=I C= C= C=L  ]Hc c c c cy c c cJt t t t ti t t tl    ,   <bH bH bH bH bHy bH bH bH bH bHw]H ]Hs   .A(C C! C!