
    ~h                         d dl Z d dlmZ  G d de      Z G d dee      Z G d d	ee      Z G d
 d      Z G d d      Z G d de      Z	 G d de      Z
y)    N)ABCMetac                   0    e Zd ZdZdZdZdZdZdZd Z	d Z
y)JWEAlgorithmBasez&Base interface for all JWE algorithms.NJWEalgc                     t         NNotImplementedError)selfraw_datas     W/opt/mcp/mcp-sentiment/venv/lib/python3.12/site-packages/authlib/jose/rfc7516/models.pyprepare_keyzJWEAlgorithmBase.prepare_key       !!    c                     t         r	   r
   )r   enc_algkeys      r   generate_presetz JWEAlgorithmBase.generate_preset   r   r   )__name__
__module____qualname____doc__EXTRA_HEADERSnamedescriptionalgorithm_typealgorithm_locationr   r    r   r   r   r      s)    0MDKN""r   r   )	metaclassc                       e Zd ZdZddZd Zy)JWEAlgorithmzInterface for JWE algorithm conforming to RFC7518.
    JWA specification (RFC7518) SHOULD implement the algorithms for JWE
    with this base implementation.
    Nc                     t         r	   r
   )r   r   headersr   presets        r   wrapzJWEAlgorithm.wrap   r   r   c                     t         r	   r
   )r   r   ekr$   r   s        r   unwrapzJWEAlgorithm.unwrap   r   r   r	   )r   r   r   r   r&   r)   r   r   r   r"   r"      s    
""r   r"   c                   .    e Zd ZdZddZd ZddZddZy)$JWEAlgorithmWithTagAwareKeyAgreementzInterface for JWE algorithm with tag-aware key agreement (in key agreement
    with key wrapping mode).
    ECDH-1PU is an example of such an algorithm.
    Nc                     t         r	   r
   )r   r   r   
sender_keyr%   s        r   !generate_keys_and_prepare_headerszFJWEAlgorithmWithTagAwareKeyAgreement.generate_keys_and_prepare_headers)   r   r   c                     t         r	   r
   )r   r   r$   r   r-   epkcektags           r   agree_upon_key_and_wrap_cekz@JWEAlgorithmWithTagAwareKeyAgreement.agree_upon_key_and_wrap_cek,   s
     "!r   c                     t         r	   r
   )r   r   r$   r   r-   r%   s         r   r&   z)JWEAlgorithmWithTagAwareKeyAgreement.wrap1   r   r   c                     t         r	   r
   )r   r   r(   r$   r   r-   r2   s          r   r)   z+JWEAlgorithmWithTagAwareKeyAgreement.unwrap4   r   r   r	   )r   r   r   r   r.   r3   r&   r)   r   r   r   r+   r+   #   s    
""
""r   r+   c                   B    e Zd ZdZdZdZdZdZdZd Z	d Z
d Zd Zd Zy)	JWEEncAlgorithmNr   encc                 F    t        j                  | j                  dz        S N   )osurandomCEK_SIZEr   s    r   generate_cekzJWEEncAlgorithm.generate_cekA   s    zz$--1,--r   c                 F    t        j                  | j                  dz        S r:   )r<   r=   IV_SIZEr?   s    r   generate_ivzJWEEncAlgorithm.generate_ivD   s    zz$,,!+,,r   c                 P    t        |      dz  | j                  k7  rt        d      y )Nr;   zInvalid "iv" size)lenrB   
ValueError)r   ivs     r   check_ivzJWEEncAlgorithm.check_ivG   s'    r7Q;$,,&011 'r   c                     t         )a  Encrypt the given "msg" text.

        :param msg: text to be encrypt in bytes
        :param aad: additional authenticated data in bytes
        :param iv: initialization vector in bytes
        :param key: encrypted key in bytes
        :return: (ciphertext, tag)
        r
   )r   msgaadrG   r   s        r   encryptzJWEEncAlgorithm.encryptK   s
     "!r   c                     t         )a8  Decrypt the given cipher text.

        :param ciphertext: ciphertext in bytes
        :param aad: additional authenticated data in bytes
        :param iv: initialization vector in bytes
        :param tag: authentication tag in bytes
        :param key: encrypted key in bytes
        :return: message
        r
   )r   
ciphertextrK   rG   r2   r   s         r   decryptzJWEEncAlgorithm.decryptV   s
     "!r   )r   r   r   r   r   r   r   rB   r>   r@   rC   rH   rL   rO   r   r   r   r7   r7   8   s:    DKNGH.-2	"
"r   r7   c                   (    e Zd ZdZdZdZdZd Zd Zy)JWEZipAlgorithmNr   zipc                     t         r	   r
   r   ss     r   compresszJWEZipAlgorithm.compressi   r   r   c                     t         r	   r
   rT   s     r   
decompresszJWEZipAlgorithm.decompressl   r   r   )	r   r   r   r   r   r   r   rV   rX   r   r   r   rQ   rQ   c   s!    DKN""r   rQ   c                   8     e Zd ZdZ fdZd Zed        Z xZS )JWESharedHeaderziShared header object for JWE.

    Combines protected header and shared unprotected header together.
    c                     i }|r|j                  |       |r|j                  |       t        | 	  |       |r|ni | _        |r|| _        y i | _        y r	   )updatesuper__init__	protectedunprotected)r   r_   r`   obj	__class__s       r   r^   zJWESharedHeader.__init__v   sO    JJy!JJ{#&/R*5;2r   c                 \    | j                  |       | j                  j                  |       y r	   )r\   r_   )r   additions     r   update_protectedz JWESharedHeader.update_protected   s     Hh'r   c                 l    t        ||       r|S  | |j                  d      |j                  d            S )Nr_   r`   )
isinstanceget)clsra   s     r   	from_dictzJWESharedHeader.from_dict   s0    c3J377;')?@@r   )	r   r   r   r   r^   re   classmethodrj   __classcell__rb   s   @r   rZ   rZ   p   s(    
>( A Ar   rZ   c                   "     e Zd ZdZ fdZ xZS )	JWEHeaderzHeader object for JWE.

    Combines protected header, shared unprotected header
    and specific recipient's unprotected header together.
    c                     i }|r|j                  |       |r|j                  |       |r|j                  |       t        | 	  |       |r|ni | _        |r|ni | _        |r|| _        y i | _        y r	   )r\   r]   r^   r_   r`   header)r   r_   r`   rq   ra   rb   s        r   r^   zJWEHeader.__init__   sh    JJy!JJ{#JJv&/R*5;2 &fBr   )r   r   r   r   r^   rl   rm   s   @r   ro   ro      s    / /r   ro   )r<   abcr   r   r"   r+   r7   rQ   dictrZ   ro   r   r   r   <module>rt      sd    	 " ""
"#w 
""+;w "*(" ("V
" 
"Ad A6/ /r   