
    Aahv                       d dl m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 	 d d	lm Z 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,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA d dlBmCZCmDZDmEZEmFZFmGZGmHZHmIZI dZJn# eK$ r dZJY nw xY we	r3e:e<z  ZLe/e1z  ZMe7e8z  e4z  e5z  ZNeLeMz  eNz  ZOe:e/z  e7z  e4z  ZPe<e1z  e8z  e5z  ZQh dZRd&dZS G d de          ZT G d deT          ZU G d deT          ZVeJr: G d deT          ZW G d  d!eT          ZX G d" d#eW          ZY G d$ d%eT          ZZdS dS )'    )annotationsN)ABCabstractmethod)TYPE_CHECKINGAnyClassVarLiteralNoReturn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)InvalidSignatureUnsupportedAlgorithm)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)rE   rF   rG   r=   rH   r>   r@   r?   rB   rC   rD   rA   )NoneAlgorithmHMACAlgorithmSHA256SHA384SHA512
has_cryptoupdateRSAAlgorithmECAlgorithmRSAPSSAlgorithmOKPAlgorithm)default_algorithmss    @/var/www/lms/venv/lib/python3.11/site-packages/jwt/algorithms.pyget_default_algorithmsr]   i   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bytesrI   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NotImplementedErrorrU   
isinstancetype
issubclassr   HashAlgorithmHashr   rV   rb   finalizedigest)selfra   rd   rn   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 ro   rq   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.
        Nrs   ro   rw   rq   s      r\   signzAlgorithm.sign   rv   r^   sigboolc                    dS )zz
        Verifies that the specified digital signature is valid
        for the specified message and key values.
        Nrs   ro   rw   rq   r{   s       r\   verifyzAlgorithm.verify   rv   r^   as_dictLiteral[True]r   c                    d S Nrs   key_objr   s     r\   to_jwkzAlgorithm.to_jwk   s
     =@Cr^   FLiteral[False]strc                    d S r   rs   r   s     r\   r   zAlgorithm.to_jwk   s     BEr^   JWKDict | strc                    dS )z3
        Serializes a given key into a JWK
        Nrs   r   s     r\   r   zAlgorithm.to_jwk   rv   r^   jwkstr | JWKDictc                    dS )zJ
        Deserializes a given key from JWK back into a key object
        Nrs   r   s    r\   from_jwkzAlgorithm.from_jwk   rv   r^   N)ra   rb   rI   rb   )rq   r   rI   r   )rw   rb   rq   r   rI   rb   )rw   rb   rq   r   r{   rb   rI   r|   )r   r   rI   r   F)r   r   rI   r   )r   r|   rI   r   )r   r   rI   r   )__name__
__module____qualname____doc__rp   r   ru   rz   r   r   staticmethodr   r   rs   r^   r\   r`   r`      sH        5 5 5 5,    ^    ^    ^ ??? ^ \ X @DDDD ^ \ X E    ^ \
    ^ \  r^   r`   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 )rP   zZ
    Placeholder for use when no signing or verification
    operations are required.
    rq   
str | NonerI   Nonec                8    |dk    rd }|t          d          |S )N z*When alg = "none", key value must be None.r   rt   s     r\   ru   zNoneAlgorithm.prepare_key   s)    "99C?!"NOOO
r^   rw   rb   c                    dS )Nr^   rs   ry   s      r\   rz   zNoneAlgorithm.sign   s    sr^   r{   r|   c                    dS )NFrs   r~   s       r\   r   zNoneAlgorithm.verify   s    ur^   Fr   r   r   r
   c                    t                      r   rg   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)rq   r   rI   r   )rw   rb   rq   r   rI   rb   )rw   rb   rq   r   r{   rb   rI   r|   r   )r   r   r   r|   rI   r
   )r   r   rI   r
   )
r   r   r   r   ru   rz   r   r   r   r   rs   r^   r\   rP   rP      s         
          $ $ $ $ \$ $ $ $ \$ $ $r^   rP   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 ),rQ   zf
    Performs signing and verification operations using HMAC
    and the specified hash function.
    zClassVar[HashlibHash]rR   rS   rT   rd   r   rI   r   c                    || _         d S r   rd   ro   rd   s     r\   __init__zHMACAlgorithm.__init__   s     r^   rq   str | bytesrb   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   ro   rq   	key_bytess      r\   ru   zHMACAlgorithm.prepare_key   sM    $$	## 	z)'<'< 	!9  
 r^   r   r   r   r   c                    d S r   rs   r   s     r\   r   zHMACAlgorithm.to_jwk
  	     #r^   Fr   r   c                    d S r   rs   r   s     r\   r   zHMACAlgorithm.to_jwk  s	     cr^   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                N   	 t          | t                    rt          j        |           }nt          | t                    r| }nt
          n# t
          $ r t          d          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   )	rh   r   r   loadsdict
ValueErrorr   getr   )r   objs     r\   r   zHMACAlgorithm.from_jwk"  s    	E#s## !#z#C&& !   	E 	E 	E!"9::D	E 775>>U""!"3444C)))   A	A A'rw   c                \    t          j        ||| j                                                  S r   )hmacnewrd   rn   ry   s      r\   rz   zHMACAlgorithm.sign3  s$    xS$-0077999r^   r{   c                T    t          j        ||                     ||                    S r   )r   compare_digestrz   r~   s       r\   r   zHMACAlgorithm.verify6  s#    "3		#s(;(;<<<r^   N)rd   r   rI   r   )rq   r   rI   rb   )r   r   r   r   rI   r   r   )r   r   r   r   rI   r   )r   r   r   r|   rI   r   )r   r   rI   rb   )rw   rb   rq   rb   rI   rb   )rw   rb   rq   rb   r{   rb   rI   r|   )r   r   r   r   hashlibsha256rR   __annotations__sha384rS   sha512rT   r   ru   r   r   r   r   rz   r   rs   r^   r\   rQ   rQ      sL         
 %,NF2222$+NF2222$+NF2222! ! ! !	 	 	 	    \ X 8=    \ X 	# 	# 	# 	# \	# * * * \* : : : := = = = = =r^   rQ   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 )/rW   z~
        Performs signing and verification operations using
        RSASSA-PKCS-v1_5 and the specified hash function.
        $ClassVar[type[hashes.HashAlgorithm]]rR   rS   rT   rd   type[hashes.HashAlgorithm]rI   r   c                    || _         d S r   r   r   s     r\   r   zRSAAlgorithm.__init__F      $DMMMr^   rq   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          $ rK 	 t          t          t          |                    cY S # t          t          f$ r t          d          d w xY ww xY w)NExpecting a PEM-formatted key.s   ssh-rsapasswordz(Could not parse the provided public key.)rh   r.   r0   rb   r   	TypeErrorr   
startswithr   r<   r:   r   r;   r   r   r   s      r\   ru   zRSAAlgorithm.prepare_keyI  s%   #|<== 
cE3<00 B @AAA#C((I ''
33 .A).L.LMMM%';IPT'U'U'U          .A).L.LMMMMM"$89      )B    s*   6B5 #B5 5
D
 !C$!D
$"DD
r   r   r   r   c                    d S r   rs   r   s     r\   r   zRSAAlgorithm.to_jwka  	     cr^   Fr   r   c                    d S r   rs   r   s     r\   r   zRSAAlgorithm.to_jwkg  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RSArz   )
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                >  	 	 t          | t                    rt          j        |           	nt          | t                    r| 	nt
          n# t
          $ r t          d          d w xY w	                    d          dk    rt          d          d d	v rd	v rd	v rd	v rt          d	          g d
}	fd|D             }t          |          }|rt          |          st          d          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 rs   rs   ).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   )rh   r   r   r   r   r   r   r   anyallr1   r   r/   r5   r   r   r2   r3   r4   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   Ic3'' %*S//CCT** %CC$$ I I I%&=>>DHI wwu~~&&%&677TA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(rw   rb   r.   c                v    |                     |t          j                    |                                           S r   )rz   r   PKCS1v15rd   ry   s      r\   rz   zRSAAlgorithm.sign  s)    88C!1!3!3T]]__EEEr^   r0   r{   c                    	 |                     ||t          j                    |                                            dS # t          $ r Y dS w xY w)NTF)r   r   r   rd   r   r~   s       r\   r   zRSAAlgorithm.verify  sW    

3W%5%7%7IIIt#   uus   ;? 
AANrd   r   rI   r   )rq   r   rI   r   )r   r   r   r   rI   r   r   )r   r   r   r   rI   r   )r   r   r   r|   rI   r   )r   r   rI   r   rw   rb   rq   r.   rI   rb   rw   rb   rq   r0   r{   rb   rI   r|   )r   r   r   r   r   rR   r   rS   rT   r   ru   r   r   r   r   rz   r   rs   r^   r\   rW   rW   <  sZ        	 	
 8>}DDDD7=}DDDD7=}DDDD	% 	% 	% 	%	  	  	  	 0 
		 	 	 
 
	 
	?D	 	 	 	 
 
	 
$	' $	' $	' $	' 
$	'L 
E	E E	E E	E 
E	EN	F 	F 	F 	F	 	 	 	 	 	r^   rW   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 ).rX   zr
        Performs signing and verification operations using
        ECDSA and the specified hash function
        r   rR   rS   rT   rd   r   rI   r   c                    || _         d S r   r   r   s     r\   r   zECAlgorithm.__init__  r   r^   rq   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          d |S )Nr   s   ecdsa-sha2-r   zcExpecting a EllipticCurvePrivateKey/EllipticCurvePublicKey. Wrong key provided for ECDSA algorithms)rh   r&   r(   rb   r   r   r   r   r<   r;   r   r:   r   )ro   rq   r   
crypto_keys       r\   ru   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-rw   rb   r&   c                    |                     |t          |                                                     }t          ||j                  S r   )rz   r    rd   r   curve)ro   rw   rq   der_sigs       r\   rz   zECAlgorithm.sign  s7    hhsE$--//$:$:;;G';;;r^   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   rh   r&   r   r   r    rd   r   )ro   rw   rq   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   rs   r   s     r\   r   zECAlgorithm.to_jwk'  r   r^   Fr   r   c                    d S r   rs   r   s     r\   r   zECAlgorithm.to_jwk-  r   r^   r   c                   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        | j        j                                                  t          |j        | j        j                                                  d	}t          | t                    rGt          |                                 j        | j        j                                                  |d
<   |r|S t%          j        |          S )Nr   P-256P-384P-521	secp256k1Invalid curve: EC)
bit_length)r   crvxyr   )rh   r&   r   r   r(   r   r  r"   r#   r$   r!   r   r  key_sizer   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 &"$&}5   &((&"$&}5   &((# #C '#:;; ,++--;&}5   &(( C
  '
z#&r^   r   r   c                   	 t          | t                    rt          j        |           }nt          | t                    r| }nt
          n# t
          $ r t          d          d w xY w|                    d          dk    rt          d          d d|vsd|vrt          d          d t          |                    d                    }t          |                    d                    }|                    d          }|dk    rJt          |          t          |          cxk    rd	k    rn nt                      }nt          d
          d |dk    rIt          |          t          |          cxk    rdk    rn nt                      }nt          d          d |dk    rIt          |          t          |          cxk    rdk    rn nt                      }npt          d          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 {})rh   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_jwk_  sg   Ic3'' %*S//CCT** %CC$$ I I I%&=>>DHI wwu~~%%%&ABBL#~~C%&ABBL ..A ..AGGENNE q66SVV))))r))))) )II)C   '!!q66SVV))))r))))) )II)C   '!!q66SVV))))r))))) )II)C   +%%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   )rq   r   rI   r   )rw   rb   rq   r&   rI   rb   )rw   rb   rq   r   r{   rb   rI   r|   )r   r   r   r   rI   r   r   )r   r   r   r   rI   r   )r   r   r   r|   rI   r   )r   r   rI   r   )r   r   r   r   r   rR   r   rS   rT   r   ru   rz   r   r   r   r   r   rs   r^   r\   rX   rX     sS        	 	
 8>}DDDD7=}DDDD7=}DDDD	% 	% 	% 	%	 	 	 	<	< 	< 	< 	<
	 	 	 	" 
		 	 	 
 
	 
	>C	 	 	 	 
 
	 
)	' )	' )	' )	' 
)	'V 
G	 G	 G	 
G	 G	 G	r^   rX   c                  "    e Zd ZdZddZddZdS )rY   zA
        Performs a signature using RSASSA-PSS with MGF1
        rw   rb   rq   r.   rI   c           	         |                     |t          j        t          j        |                                           |                                 j                  |                                           S )Nmgfsalt_length)rz   r   PSSMGF1rd   digest_sizery   s      r\   rz   zRSAPSSAlgorithm.sign  s_    88T]]__55 $ ;     r^   r0   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&  rd   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   rz   r   rs   r^   r\   rY   rY     sF        	 		 	 	 		 	 	 	 	 	r^   rY   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 )*rZ   z
        Performs signing and verification operations using EdDSA

        This class requires ``cryptography>=2.6`` to be installed.
        kwargsr   rI   r   c                    d S r   rs   )ro   r*  s     r\   r   zOKPAlgorithm.__init__  s    Dr^   rq   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)rh   rb   r   r   encoder;   r:   r<   r,   r-   r*   r+   r   )ro   rq   key_strr   s       r\   ru   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^   rw   r   #Ed25519PrivateKey | Ed448PrivateKeyrb   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
            r/  )rh   r   r1  rz   )ro   rw   rq   	msg_bytess       r\   rz   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.
            r/  TF)rh   r   r1  r,   r*   r   r   r   )ro   rw   rq   r{   r5  	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   rs   rq   r   s     r\   r   zOKPAlgorithm.to_jwk  r   r^   Fr   r   c                    d S r   rs   r9  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   )rh   r-   r+   public_bytesr6   Rawr9   r   r   r   r   r   r,   r*   private_bytesr8   r7   r   r   )rq   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          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   r@  zNot an Octet Key Pairr  r>  r?  r  r  zOKP should have "x" parameterr   zInvalid key parameter)rh   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_jwkJ  s   Ic3'' %*S//CCT** %CC$$ I I I%&=>>DHI 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   rI   r   )rq   r,  rI   r-  )rw   r   rq   r3  rI   rb   )rw   r   rq   r-  r{   r   rI   r|   )rq   r-  r   r   rI   r   r   )rq   r-  r   r   rI   r   )rq   r-  r   r|   rI   r   )r   r   rI   r-  )r   r   r   r   r   ru   rz   r   r   r   r   r   rs   r^   r\   rZ   rZ     s       	 		 	 	 		 	 	 	.	' 	' 	' 	'	 	 	 	4 
		 	 	 
 
	 
	;@	 	 	 	 
 
	 
,	A ,	A ,	A ,	A 
,	A\ 
 	H  	H  	H 
 	H  	H  	Hr^   rZ   )rI   rJ   )[
__future__r   r   r   r   abcr   r   typingr   r   r   r	   r
   r   r   
exceptionsr   typesr   r   utilsr   r   r   r   r   r   r   r   r   cryptography.exceptionsr   r   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.   r/   r0   r1   r2   r3   r4   r5   ,cryptography.hazmat.primitives.serializationr6   r7   r8   r9   r:   r;   r<   rU   ModuleNotFoundErrorr   r   r-  AllowedKeysAllowedPrivateKeysAllowedPublicKeysrequires_cryptographyr]   r`   rP   rQ   rW   rX   rY   rZ   rs   r^   r\   <module>r]     sD   " " " " " "    # # # # # # # # R R R R R R R R R R R R R R R R R R ' ' ' ' ' ' ' ' ' ' ' ' ' '
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/NNNNNNNN<<<<<<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F F F F F F F FR$ $ $ $ $I $ $ $<E= E= E= E= E=I E= E= E=P  qHh h h h hy h h hTA A A A Ai A A AF    ,   <dH dH dH dH dHy dH dH dH dH dH[qH qHs   A*B= =CC