o
    ÿÑÐbç  ã                   @   s<   d dl Z G dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    Nc                   @   s<   e Zd ZdZdZdZdZdZdZdd„ Z	dd„ Z
d	d
„ ZdS )ÚJWEAlgorithmzˆInterface for JWE algorithm. JWA specification (RFC7518) SHOULD
    implement the algorithms for JWE with this base implementation.
    NÚJWEÚalgc                 C   ó   t ‚©N©ÚNotImplementedError)ÚselfÚraw_data© r   úZ/var/www/secure340b-portal/env/lib/python3.10/site-packages/authlib/jose/rfc7516/models.pyÚprepare_key   ó   zJWEAlgorithm.prepare_keyc                 C   r   r   r   )r	   Úenc_algÚheadersÚkeyr   r   r   Úwrap   r   zJWEAlgorithm.wrapc                 C   r   r   r   )r	   r   Zekr   r   r   r   r   Úunwrap   r   zJWEAlgorithm.unwrap)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZEXTRA_HEADERSÚnameÚdescriptionÚalgorithm_typeÚalgorithm_locationr   r   r   r   r   r   r   r      s    r   c                   @   sL   e Zd ZdZdZdZdZdZdZdd„ Z	dd„ Z
dd	„ Zd
d„ Zdd„ ZdS )ÚJWEEncAlgorithmNr   Úencc                 C   ó   t  | jd ¡S ©Né   )ÚosÚurandomÚCEK_SIZE©r	   r   r   r   Úgenerate_cek"   ó   zJWEEncAlgorithm.generate_cekc                 C   r   r   )r!   r"   ÚIV_SIZEr$   r   r   r   Úgenerate_iv%   r&   zJWEEncAlgorithm.generate_ivc                 C   s   t |ƒd | jkrtdƒ‚d S )Nr    zInvalid "iv" size)Úlenr'   Ú
ValueError)r	   Úivr   r   r   Úcheck_iv(   s   ÿzJWEEncAlgorithm.check_ivc                 C   r   )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, iv, tag)
        r   )r	   ÚmsgÚaadr+   r   r   r   r   Úencrypt,   s   	zJWEEncAlgorithm.encryptc                 C   r   )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	   Z
ciphertextr.   r+   Útagr   r   r   r   Údecrypt7   s   
zJWEEncAlgorithm.decrypt)r   r   r   r   r   r   r   r'   r#   r%   r(   r,   r/   r1   r   r   r   r   r      s    r   c                   @   s,   e Zd ZdZdZdZdZdd„ Zdd„ ZdS )ÚJWEZipAlgorithmNr   Úzipc                 C   r   r   r   ©r	   Úsr   r   r   ÚcompressJ   r   zJWEZipAlgorithm.compressc                 C   r   r   r   r4   r   r   r   Ú
decompressM   r   zJWEZipAlgorithm.decompress)	r   r   r   r   r   r   r   r6   r7   r   r   r   r   r2   D   s    r2   )r!   Úobjectr   r   r2   r   r   r   r   Ú<module>   s    +