
    Ki4                         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                   4    e Zd 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.NFJWEalgc                     t         NNotImplementedError)selfraw_datas     g/home/jay/workspace/scripts/.codegraph-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
deprecatedalgorithm_typealgorithm_locationr   r    r   r   r   r      s.    0MDKJ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.wrap2   r   r   c                     t         r	   r
   )r   r   r)   r%   r   r.   r3   s          r   r*   z+JWEAlgorithmWithTagAwareKeyAgreement.unwrap5   r   r   r	   )r   r   r   r   r/   r4   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_cekB   s    zz$--1,--r   c                 F    t        j                  | j                  dz        S r;   )r=   r>   IV_SIZEr@   s    r   generate_ivzJWEEncAlgorithm.generate_ivE   s    zz$,,!+,,r   c                 P    t        |      dz  | j                  k7  rt        d      y )Nr<   zInvalid "iv" size)lenrC   
ValueError)r   ivs     r   check_ivzJWEEncAlgorithm.check_ivH   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aadrH   r   s        r   encryptzJWEEncAlgorithm.encryptL   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   
ciphertextrL   rH   r3   r   s         r   decryptzJWEEncAlgorithm.decryptW   s
     "!r   )r   r   r   r   r   r   r   rC   r?   rA   rD   rI   rM   rP   r    r   r   r8   r8   9   s:    DKNGH.-2	"
"r   r8   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.compressj   r   r   c                     t         r	   r
   rU   s     r   
decompresszJWEZipAlgorithm.decompressm   r   r   )	r   r   r   r   r   r   r   rW   rY   r    r   r   rR   rR   d   s!    DKN""r   rR   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`   ra   obj	__class__s       r   r_   zJWESharedHeader.__init__w   sO    JJ{#JJy!&/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`   ra   )
isinstanceget)clsrb   s     r   	from_dictzJWESharedHeader.from_dict   s0    c3J377;')?@@r   )	r   r   r   r   r_   rf   classmethodrk   __classcell__rc   s   @r   r[   r[   q   s(    
>( A Ar   r[   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`   ra   header)r   r`   ra   rr   rb   rc   s        r   r_   zJWEHeader.__init__   sh    JJ{#JJvJJy!&/R*5;2 &fBr   )r   r   r   r   r_   rm   rn   s   @r   rp   rp      s    / /r   rp   )r=   abcr   r   r#   r,   r8   rR   dictr[   rp   r    r   r   <module>ru      sd    	 " "$
"#w 
""+;w "*(" ("V
" 
"Ad A6/ /r   