o
    ÿÑÐb  ã                   @   s<   d Z ddlmZ ddlmZmZ G dd„ deƒZdd„ ZdS )	zµ
    authlib.jose.draft
    ~~~~~~~~~~~~~~~~~~~~

    Content Encryption per `Section 4`_.

    .. _`Section 4`: https://tools.ietf.org/html/draft-amringer-jose-chacha-02#section-4
é    )ÚChaCha20Poly1305)ÚJWEEncAlgorithmÚJsonWebEncryptionc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚC20PEncAlgorithmé`   c                 C   s   d| _ d| _|| _|| _d S )NZC20PzChaCha20-Poly1305)ÚnameÚdescriptionÚkey_sizeZCEK_SIZE)Úselfr	   © r   úh/var/www/secure340b-portal/env/lib/python3.10/site-packages/authlib/jose/drafts/_jwe_enc_cryptography.pyÚ__init__   s   
zC20PEncAlgorithm.__init__c                 C   s8   |   |¡ t|ƒ}| |||¡}|dd… |dd… fS )a  Key Encryption with AES GCM

        :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Ú
ciphertextr   r   r   r      s   
	zC20PEncAlgorithm.encryptc                 C   s$   |   |¡ t|ƒ}| ||| |¡S )a5  Key Decryption with AES GCM

        :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   r   r   r   r   &   s   

zC20PEncAlgorithm.decryptN)Ú__name__Ú
__module__Ú__qualname__ZIV_SIZEr   r   r   r   r   r   r   r      s
    r   c                   C   s   t  tdƒ¡ d S )Né   )r   Zregister_algorithmr   r   r   r   r   Úregister_jwe_draft5   s   r   N)Ú__doc__Z+cryptography.hazmat.primitives.ciphers.aeadr   Zauthlib.jose.rfc7516r   r   r   r   r   r   r   r   Ú<module>   s
    (