
    kKj{/                        d dl Zd dlmZ d dlmZmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ dd	lmZmZmZmZ dd
lmZ ddlmZmZmZmZ  ej6                  d      Z ej6                  d      Z ej6                  dd      Z G d de      Z G d dej@                  eef   e      Z! G d de!e"e"f   e      Z# G d de!eef   e      Z$ G d de$eef         Z%y)    N)KeysView)ABCMetaabstractmethod   )DictKeyAnyKeyKeyParameters   )calculate_thumbprint)concat_thumbprint_uri)KeyParameterRegistryDictJWK_PARAMETER_REGISTRYKeyOperationRegistryDictJWK_OPERATION_REGISTRY)to_bytes)KeyParameterErrorUnsupportedKeyUseErrorUnsupportedKeyAlgorithmErrorUnsupportedKeyOperationErrorNativePrivateKeyNativePublicKey
GenericKeyzBaseKey[t.Any, t.Any])boundc                      e Zd ZU ddgg ddZej
                  eeee   f      e	d<   e
edej                  dedefd	              Ze
ed
edej                  fd              Ze
edd
edej                  dej                  fd              Ze	 	 	 ddedej*                  d   dz  dededz  def
d       Ze
dededdfd       Ze
deddfd       Zy)NativeKeyBindingsignverify)encryptdecryptwrapKey	unwrapKey	deriveKey
deriveBits)sigencuse_key_ops_registryraw_keyprivatereturnc                      y N )clsr'   r(   s      h/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/joserfc/_rfc7517/models.pyconvert_raw_key_to_dictz(NativeKeyBinding.convert_raw_key_to_dict!        	    valuec                      y r+   r,   )r-   r2   s     r.   import_from_dictz!NativeKeyBinding.import_from_dict&   r0   r1   Npasswordc                      y r+   r,   )r-   r2   r5   s      r.   import_from_bytesz"NativeKeyBinding.import_from_bytes+   r0   r1   keyencodingPEMDERc                     t               r+   NotImplementedError)r8   r9   r(   r5   s       r.   as_byteszNativeKeyBinding.as_bytes0   s     "##r1   dict_keyregistryc                     |D ]A  }||   j                   r||vrt        d| d      ||v s*	 ||   j                  ||          C y # t        $ r}t        d| d|       d }~ww xY w)N'z' is requiredz' )requiredr   validate
ValueError)r-   rA   rB   kerrors        r.   validate_dict_key_registryz+NativeKeyBinding.validate_dict_key_registry9   s    A{##(9'!A3m(<==H}>QK((!5  " >+as"UG,<==>s   A	A'A""A'c                 r    d|v r3d|v r.|d   }| j                   |   }|d   D ]  }||vst        d       y y y )Nusekey_opsz"'use' and 'key_ops' does not match)r&   r   )r-   rA   _use
operationsops        r.    validate_dict_key_use_operationsz1NativeKeyBinding.validate_dict_key_use_operationsE   sU    Hh!6 D11$7Jy)Z'+,PQQ * "7r1   r+   NFN)__name__
__module____qualname__r&   tClassVardictstrlist__annotations__classmethodr   Anyboolr   r/   r4   bytesr7   staticmethodr   Literalr@   r   rJ   rQ   r,   r1   r.   r   r      s~   !X>!**T#tCy.%9: 
 aee d w    W     e quu      48#	$$))L)D0$ $ *	$
 
$ $ 	>' 	>E] 	>bf 	> 	> R RD R Rr1   r   )	metaclassc                   >   e Zd ZU ej                  e   ed<   ej                  ee      ed<   ej                  e	   ed<   e
Zej                  e	   ed<   eZej                  e   ed<   dZej                   d   ed<   	 d9d
eez  dej&                  ded	z  fdZdej&                  defdZdee   fdZdedeee   z  fdZd9dedeee   z  d	z  deee   z  d	z  fdZd:dZeded	z  fd       Zeded	z  fd       Z edej&                  fd       Z!edefd       Z"ede#fd       Z$edefd       Z%eded	z  fd       Z&defdZ'defdZ(d;d!ed"ej&                  de#fd#Z)d$edd	fd%Z*d&edd	fd'Z+d(edd	fd)Z,ejZ                  d(ej                   d*   defd+       Z.ejZ                  d(ej                   d,   defd-       Z.d(edeez  fd.Z.e/d/e#dd	fd0       Z0e/	 	 d<d1ee1   d2e2ded	z  d3ej&                  de1f
d4       Z3e/d	d5d d6d1ee1   ded	z  d!ed7ede1f
d8       Z4y	)=BaseKeykey_typebindingvalue_registryparam_registryoperation_registrysha256)rj   sha384sha512thumbprint_digest_methodN	raw_valueoriginal_value
parametersc                     || _         || _        || _        i | _        t	        |t
              rB|i ||d| j                  i}ni |d| j                  i}| j                  |       || _        y y )Nkty)
_raw_valuero   extra_parameters_dict_value
isinstancerX   re   validate_dict_key)selfrn   ro   rp   datas        r.   __init__zBaseKey.__init__W   s}     $, *$&nd+%M.MJMt}}M?.?%?""4(#D ,r1   otherr)   c                 b    t        || j                        sy| j                  |j                  k(  S )NF)rv   	__class__
dict_value)rx   r{   s     r.   __eq__zBaseKey.__eq__i   s(    %0%"2"222r1   c                 6    | j                   j                         S r+   )r~   keysrx   s    r.   r   zBaseKey.keysn   s    ##%%r1   rH   c                      | j                   |   S r+   )r~   )rx   rH   s     r.   __getitem__zBaseKey.__getitem__q   s    q!!r1   defaultc                 :    | j                   j                  ||      S r+   )r~   get)rx   rH   r   s      r.   r   zBaseKey.gett   s    ""1g..r1   c                 \    d| j                   vr| j                         | j                  d<   yy)zEnsure this key has a ``kid``. If ``kid`` is not provided by default,
        it will generate the kid with ``.thumbprint`` method, which is defined
        by RFC7638.kidN)r~   
thumbprintru   r   s    r.   
ensure_kidzBaseKey.ensure_kidw   s,     '&*oo&7DU# (r1   c                 v    t        j                  t         j                  t           | j	                  d            S )z$The "kid" value of the JSON Web Key.r   rV   castOptionalrY   r   r   s    r.   r   zBaseKey.kid~   %     vvajjotxx77r1   c                 v    t        j                  t         j                  t           | j	                  d            S )z$The "alg" value of the JSON Web Key.algr   r   s    r.   r   zBaseKey.alg   r   r1   c                     t               r+   r>   r   s    r.   rn   zBaseKey.raw_value       !##r1   c                     t               r+   r>   r   s    r.   
is_privatezBaseKey.is_private   r   r1   c                 2   | j                   r| j                   S | j                  j                  | j                  | j                        }| j
                  |j                  | j
                         | j                  |d<   | j                  |       || _         |S )z#Property of the Key in Dict (JSON).rr   )	ru   rf   r/   rn   r   rt   updatere   rw   )rx   ry   s     r.   r~   zBaseKey.dict_value   s}     ###||33DNNDOOT  ,KK--.mmUt$r1   c                     t               r+   r>   r   s    r.   
public_keyzBaseKey.public_key   r   r1   c                     t               r+   r>   r   s    r.   private_keyzBaseKey.private_key   r   r1   c                    | j                   D cg c]  }| j                   |   j                  s|  }}|j                  d       |D ci c]  }|| j                  |    }}t	        || j
                        S c c}w c c}w )zXCall this method will generate the thumbprint with algorithm
        defined in RFC7638.rr   )rg   rE   appendr~   r   rm   )rx   rH   fieldsr8   ry   s        r.   r   zBaseKey.thumbprint   s}     "00T0D4G4G4J4S4S!0Te5;<VcT__S))V<#D$*G*GHH U<s   A8A8	A=c                 N    | j                         }t        || j                        S )zMCall this method will generate the thumbprint URI
        defined in RFC9278.)r   r   rm   )rx   r2   s     r.   thumbprint_urizBaseKey.thumbprint_uri   s#     !$UD,I,IJJr1   Fr(   paramsc                 2   |r| j                   st        d      | j                  j                         }|r|j	                  |       |S | j                  D ].  }|| j
                  v s| j
                  |   j                  s,||= 0 |j	                  |       |S )a%  Output this key to a JWK format (in dict). By default, it will return
        the ``dict_value`` of this key.

        :param private: determine whether this method should output private key or not
        :param params: other parameters added into this key
        :raise: ValueError
        zThis key is not a private key.)r   rG   r~   copyr   rg   r(   )rx   r(   r   ry   rH   s        r.   as_dictzBaseKey.as_dict   s     4??=>>##%KKK AD'''D,?,?,B,J,JG ! 	Fr1   rL   c                 T    | j                  d      }|r||k7  rt        d| d      yy)a  Check if this key supports the given "use".

        Values defined by this specification are:

        - "sig" (signature)
        - "enc" (encryption)

        Other values MAY be used.  The "use" value is a case-sensitive
        string. Use of the "use" member is OPTIONAL, unless the application
        requires its presence.

        :param use: this key is used for, e.g. "sig", "enc"
        :raise UnsupportedKeyUseError: if this key is not designed for the given use
        rL   z%This key is designed to be used for 'rD   N)r   r   )rx   rL   designed_uses      r.   	check_usezBaseKey.check_use   s:     xxLC/(+PQ]P^^_)`aa 0<r1   r   c                 T    | j                  d      }|r||k7  rt        d| d      yy)zCheck if this key supports the given "alg".

        :param alg: the algorithm this key is intended to be used, e.g. "HS256", "ECDH-EC"
        :raise UnsupportedKeyAlgorithmError: if this key is not designed for the given algorithm
        r   z$This key is designed for algorithm 'rD   N)r   r   )rx   r   designed_algs      r.   	check_algzBaseKey.check_alg   s:     xxLC/.1UVbUccd/eff 0<r1   	operationc                     | j                  d      }|||vrt        d| d      || j                  v sJ | j                  |   }|j                  r| j                  st        d| d      yy)zCheck if the given key_op is supported by this key.

        :param operation: key operation value, such as "sign", "encrypt".
        :raise UnsupportedKeyOperationError: if the operation is not supported by this key.
        rM   NzUnsupported key_op 'rD   zInvalid key_op 'z' for public key)r   r   ri   r(   r   )rx   r   rM   regs       r.   check_key_opzBaseKey.check_key_op   s     ((9%9G#;.1Ei[PQ/RSSD33333%%i0;;t.1A)L\/]^^  /;r1   )r   r   r    r"   c                      y r+   r,   rx   r   s     r.   
get_op_keyzBaseKey.get_op_key   s    psr1   )r   r   r!   c                      y r+   r,   r   s     r.   r   zBaseKey.get_op_key   s    dgr1   c                     | j                  |       | j                  |   }|j                  r| j                  J | j                  S | j                  S r+   )r   ri   r(   r   r   )rx   r   r   s      r.   r   zBaseKey.get_op_key   sO    )$%%i0;;##///###r1   ry   c                     | j                   j                  || j                         | j                   j                  || j                         | j                   j	                  |       y r+   )rf   rJ   rh   rg   rQ   )r-   ry   s     r.   rw   zBaseKey.validate_dict_key  sH    ..tS5G5GH..tS5G5GH44T:r1   r-   r2   r5   c                     t        |t              r6| j                  |       | j                  j	                  |      } | |||      S | j                  j                  t        |      |      } | |||      S r+   )rv   rX   rw   rf   r4   r7   r   )r-   r2   rp   r5   r'   s        r.   
import_keyzBaseKey.import_key  sh     eT"!!%(kk2259Gwz22++//J7E:..r1   T)rp   r(   auto_kidr   c                    t               r+   r>   )r-   rp   r(   r   s       r.   generate_keyzBaseKey.generate_key  s     "##r1   r+   )r)   N)F)NN)5rS   rT   rU   rV   rW   rY   r[   typer   r   r   rh   r   ri   r   rm   ra   r   r   r]   r	   rz   r^   r   r   r   rZ   r   r   r   propertyr   r   rn   r   r   r~   r   r   r   r   r   r   r   r   overloadr   r\   rw   r   r   r   r   r,   r1   r.   rd   rd   O   s   jjoZZ-.//JJ788;QNAJJ78Q?U

#;<UHPaii(DEP ,0	$#o5$ $ "D(	$$3AEE 3d 3
&hsm &"S "S49_ "/S /3c?T#9 /S4PS9_W[E[ /8 8S4Z 8 8 8S4Z 8 8 $155 $ $ $D $ $ G   $O $ $ $-4 $ $IC IK Kt quu  2bS bT b&gS gT g_c _d _ ZZsAII.Y$Zs_ns sZZgAII.L$MgRbg gC O>N,N  ;W ; ; ;
  ,0	/*// "D(/ %%	/
 
/ /  ,0$*$ "D($ 	$
 $ 
$ $r1   rd   c                   d    e Zd Zedefd       Zedefd       Zedefd       Zedefd       Z	y)SymmetricKeyr)   c                     | j                   S )zThe raw key in bytes.rs   r   s    r.   rn   zSymmetricKey.raw_value(  s     r1   c                      y)z'A symmetric key will always be private.Tr,   r   s    r.   r   zSymmetricKey.is_private-  s     r1   c                     | j                   S )z,Returns the ``raw_value`` as the public key.rn   r   s    r.   r   zSymmetricKey.public_key2       ~~r1   c                     | j                   S )z-Returns the ``raw_value`` as the private key.r   r   s    r.   r   zSymmetricKey.private_key7  r   r1   N)
rS   rT   rU   r   r_   rn   r^   r   r   r   r,   r1   r.   r   r   '  sl    5   D   E   U  r1   r   c            	           e Zd Zedej
                  eef   fd       Z	 	 	 ddej                  d   dz  de
dedz  defdZdde
dedz  defd	Zdde
dedz  defd
Zy)AsymmetricKeyr)   c                     | j                   S r+   r   r   s    r.   rn   zAsymmetricKey.raw_value>  s    r1   Nr9   r:   r(   r5   c                 >    | j                   j                  | |||      S r+   )rf   r@   )rx   r9   r(   r5   s       r.   r@   zAsymmetricKey.as_bytesB  s     ||$$T8WhGGr1   c                 (    | j                  ||      S )N)r(   r5   r@   rx   r(   r5   s      r.   as_pemzAsymmetricKey.as_pemJ  s    }}Wx}@@r1   c                 *    | j                  d||      S )Nr<   )r9   r(   r5   r   r   s      r.   as_derzAsymmetricKey.as_derM  s    }}eWx}PPr1   rR   )FN)rS   rT   rU   r   rV   Unionr   r   rn   ra   r^   rY   r_   r@   r   r   r,   r1   r.   r   r   =  s    177?4D#DE  
 48#	H))L)D0H H *	H
 
HAd AcDj AE AQd QcDj QE Qr1   r   c                   Z    e Zd Zeedefd              Zedej                  de	fd       Z
y)CurveKeyr)   c                      y r+   r,   r   s    r.   
curve_namezCurveKey.curve_nameR  r0   r1   r8   c                      y r+   r,   )rx   r8   s     r.   exchange_derive_keyzCurveKey.exchange_derive_keyW  s    r1   N)rS   rT   rU   r   r   rY   r   rV   r]   r_   r   r,   r1   r.   r   r   Q  sI    C    quu   r1   r   )&typingrV   collections.abcr   abcr   r   typesr   r   r	   _rfc7638r   _rfc9278r   rB   r   r   r   r   utilr   errorsr   r   r   r   TypeVarr   r   r   r   Genericrd   r_   r   r   r   r,   r1   r.   <module>r      s     $ ' 1 1 + ,    199/0 !))-.QYY|+BC
1R 1RhU$aii(/9:g U$p75%<(G ,QG,o=>' Q(}->? r1   