
    i[fD                     >    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
    )JWEEncAlgorithm)ChaCha20_Poly1305c                   $    e Zd ZdZd Zd Zd ZdS )XC20PEncAlgorithm   c                 >    d| _         d| _        || _        || _        d S )NXC20PzXChaCha20-Poly1305)namedescriptionkey_sizeCEK_SIZE)selfr   s     [/var/www/piapp/venv/lib/python3.11/site-packages/authlib/jose/drafts/_jwe_enc_cryptodome.py__init__zXC20PEncAlgorithm.__init__   s#    	/      c                     |                      |           t          j        ||          }|                    |           |                    |          \  }}||fS )a$  Content Encryption with AEAD_XCHACHA20_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)
        keynonce)check_ivCryptodome_ChaCha20_Poly1305newupdateencrypt_and_digest)r   msgaadivr   chacha
ciphertexttags           r   encryptzXC20PEncAlgorithm.encrypt   s^     	b-1cDDDc 33C88
C3r   c                     |                      |           t          j        ||          }|                    |           |                    ||          S )aI  Content Decryption with AEAD_XCHACHA20_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   r   r   r   decrypt_and_verify)r   r   r   r   r    r   r   s          r   decryptzXC20PEncAlgorithm.decrypt'   sS     	b-1cDDDc((S999r   N)__name__
__module____qualname__IV_SIZEr   r!   r$    r   r   r   r      sH         G! ! !  : : : : :r   r   N)__doc__authlib.jose.rfc7516r   Cryptodome.Cipherr   r   r   r)   r   r   <module>r-      si     1 0 0 0 0 0 O O O O O O': ': ': ': ': ': ': ': ': ':r   