
    i[f                     >    d Z ddlmZ ddlmZ  G d de          ZdS )z
    authlib.jose.draft
    ~~~~~~~~~~~~~~~~~~~~

    Content Encryption per `Section 4`_.

    .. _`Section 4`: https://datatracker.ietf.org/doc/html/draft-amringer-jose-chacha-02#section-4
    )ChaCha20Poly1305)JWEEncAlgorithmc                   $    e Zd ZdZd Zd Zd ZdS )C20PEncAlgorithm`   c                 >    d| _         d| _        || _        || _        d S )NC20PzChaCha20-Poly1305)namedescriptionkey_sizeCEK_SIZE)selfr   s     ]/var/www/piapp/venv/lib/python3.11/site-packages/authlib/jose/drafts/_jwe_enc_cryptography.py__init__zC20PEncAlgorithm.__init__   s#    	.      c                     |                      |           t          |          }|                    |||          }|dd         |dd         fS )a#  Content Encryption with AEAD_CHACHA20_POLY1305

        :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)
        Ni)check_ivr   encrypt)r   msgaadivkeychacha
ciphertexts          r   r   zC20PEncAlgorithm.encrypt   sU     	b!#&&^^BS11
$3$CDD!111r   c                 ~    |                      |           t          |          }|                    |||z   |          S )aH  Content Decryption with AEAD_CHACHA20_POLY1305

        :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   decrypt)r   r   r   r   tagr   r   s          r   r   zC20PEncAlgorithm.decrypt&   s>     	b!#&&~~b*s"2C888r   N)__name__
__module____qualname__IV_SIZEr   r   r    r   r   r   r      sH         G! ! !2 2 29 9 9 9 9r   r   N)__doc__+cryptography.hazmat.primitives.ciphers.aeadr   authlib.jose.rfc7516r   r   r"   r   r   <module>r&      sj     I H H H H H 0 0 0 0 0 0%9 %9 %9 %9 %9 %9 %9 %9 %9 %9r   