o
    ç÷¡gí<  ã                
   @   s  U d dl mZ d dlmZ d dlmZmZ d dlm	Z	 	 e 
¡ Zeed< e ¡ Zeed< e ¡ Zeed< e ¡ Zeed< e ¡ Zeed	< ee Ze ¡ Zeed
< e ¡ Zeed< e ¡ Zeed< e ¡ Zeed< e ¡ Z eed< e e Z!e "¡ Z#eed< e $¡ Z%eed< e &¡ Z'eed< e (¡ Z)eed< e *¡ Z+eed< e+e) Z,de-dee- de-de-de-f
dd„Z.de-dee- de-de-de-f
dd„Z/de-dee- de-de-de-f
dd„Z0de-dee- de-de-de-f
d d!„Z1de-dee- de-de-de-f
d"d#„Z2de-dee- de-de-de-f
d$d%„Z3d&S )'é    )ÚOptional)Ú
exceptions)ÚffiÚlib)ÚensureÚ*crypto_aead_chacha20poly1305_ietf_KEYBYTESÚ+crypto_aead_chacha20poly1305_ietf_NSECBYTESÚ+crypto_aead_chacha20poly1305_ietf_NPUBBYTESÚ(crypto_aead_chacha20poly1305_ietf_ABYTESÚ2crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAXÚ%crypto_aead_chacha20poly1305_KEYBYTESÚ&crypto_aead_chacha20poly1305_NSECBYTESÚ&crypto_aead_chacha20poly1305_NPUBBYTESÚ#crypto_aead_chacha20poly1305_ABYTESÚ-crypto_aead_chacha20poly1305_MESSAGEBYTES_MAXÚ+crypto_aead_xchacha20poly1305_ietf_KEYBYTESÚ,crypto_aead_xchacha20poly1305_ietf_NSECBYTESÚ,crypto_aead_xchacha20poly1305_ietf_NPUBBYTESÚ)crypto_aead_xchacha20poly1305_ietf_ABYTESÚ3crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAXÚmessageÚaadÚnonceÚkeyÚreturnc                 C   s(  t t| tƒdtjd� t| ƒ}t |tkd t¡tjd� t t|tƒp%|du dtjd� t t|tƒo6t|ƒt	kd t	¡tjd� t t|tƒoJt|ƒt
kd t
¡tjd� |r\|}t|ƒ}ntj}d}|t }t d	¡}t d
|¡}	t |	|| |||tj||¡	}
t |
dkdtjd� t |	|d ¡dd… S )aZ  
    Encrypt the given ``message`` using the IETF ratified chacha20poly1305
    construction described in RFC7539.

    :param message:
    :type message: bytes
    :param aad:
    :type aad: Optional[bytes]
    :param nonce:
    :type nonce: bytes
    :param key:
    :type key: bytes
    :return: authenticated ciphertext
    :rtype: bytes
    ú Input message type must be bytes©Úraisingú%Message must be at most {} bytes longNú%Additional data must be bytes or Noneú,Nonce must be a {} bytes long bytes sequenceú*Key must be a {} bytes long bytes sequencer   úunsigned long long *úunsigned char[]úEncryption failed.)r   Ú
isinstanceÚbytesÚexcÚ	TypeErrorÚlenr   ÚformatÚ
ValueErrorr	   r   r   ÚNULLr
   Únewr   Ú)crypto_aead_chacha20poly1305_ietf_encryptÚCryptoErrorÚbuffer©r   r   r   r   ÚmlenÚ_aadÚaalenÚmxoutÚclenÚ
ciphertextÚres© r9   úD/usr/local/lib/python3.10/dist-packages/nacl/bindings/crypto_aead.pyr.   W   s^   ýÿûý

ÿú	

ÿú	

ÿr.   r7   c                 C   ó(  t t| tƒdtjd� t| ƒ}t |tkd t¡tjd� t t|tƒp%|du dtjd� t t|tƒo6t|ƒt	kd t	¡tjd� t t|tƒoJt|ƒt
kd t
¡tjd� |t }t d¡}t d	|¡}|rk|}t|ƒ}	ntj}d
}	t ||tj| |||	||¡	}
t |
d
kdtjd� t ||d
 ¡dd… S )aR  
    Decrypt the given ``ciphertext`` using the IETF ratified chacha20poly1305
    construction described in RFC7539.

    :param ciphertext:
    :type ciphertext: bytes
    :param aad:
    :type aad: Optional[bytes]
    :param nonce:
    :type nonce: bytes
    :param key:
    :type key: bytes
    :return: message
    :rtype: bytes
    ú#Input ciphertext type must be bytesr   ú(Ciphertext must be at most {} bytes longNr   r    r!   r"   r#   r   úDecryption failed.)r   r%   r&   r'   r(   r)   Ú*_aead_chacha20poly1305_ietf_CRYPTBYTES_MAXr*   r+   r	   r   r
   r   r-   r,   r   Ú)crypto_aead_chacha20poly1305_ietf_decryptr/   r0   ©r7   r   r   r   r6   r5   r2   r   r3   r4   r8   r9   r9   r:   r@   ¦   ó^   ýÿûý

ÿú	

ÿú	

ÿr@   c                 C   ó0  t t| tƒdtjd� t| ƒ}t |tkd t¡tjd� t t|tƒp%|du dtjd� t t|tƒo6t|ƒt	kd t	¡tjd� t t|tƒoJt|ƒt
kd t
¡tjd� |r\|}t|ƒ}ntj}d}t| ƒ}|t }t d	¡}t d
|¡}	t |	|| |||tj||¡	}
t |
dkdtjd� t |	|d ¡dd… S )a[  
    Encrypt the given ``message`` using the "legacy" construction
    described in draft-agl-tls-chacha20poly1305.

    :param message:
    :type message: bytes
    :param aad:
    :type aad: Optional[bytes]
    :param nonce:
    :type nonce: bytes
    :param key:
    :type key: bytes
    :return: authenticated ciphertext
    :rtype: bytes
    r   r   r   Nr   r    r!   r   r"   r#   r$   )r   r%   r&   r'   r(   r)   r   r*   r+   r   r   r   r,   r
   r-   r   Ú$crypto_aead_chacha20poly1305_encryptr/   r0   r1   r9   r9   r:   rD   õ   ó`   ýÿûý

ÿú	

ÿú	

ÿrD   c                 C   r;   )al  
    Decrypt the given ``ciphertext`` using the "legacy" construction
    described in draft-agl-tls-chacha20poly1305.

    :param ciphertext: authenticated ciphertext
    :type ciphertext: bytes
    :param aad:
    :type aad: Optional[bytes]
    :param nonce:
    :type nonce: bytes
    :param key:
    :type key: bytes
    :return: message
    :rtype: bytes
    r<   r   r=   Nr   r    r!   r"   r#   r   r>   )r   r%   r&   r'   r(   r)   Ú%_aead_chacha20poly1305_CRYPTBYTES_MAXr*   r+   r   r   r   r   r-   r,   r   Ú$crypto_aead_chacha20poly1305_decryptr/   r0   rA   r9   r9   r:   rG   E  rB   rG   c                 C   rC   )aD  
    Encrypt the given ``message`` using the long-nonces xchacha20poly1305
    construction.

    :param message:
    :type message: bytes
    :param aad:
    :type aad: Optional[bytes]
    :param nonce:
    :type nonce: bytes
    :param key:
    :type key: bytes
    :return: authenticated ciphertext
    :rtype: bytes
    r   r   r   Nr   r    r!   r   r"   r#   r$   )r   r%   r&   r'   r(   r)   r   r*   r+   r   r   r   r,   r   r-   r   Ú*crypto_aead_xchacha20poly1305_ietf_encryptr/   r0   r1   r9   r9   r:   rH   ”  rE   rH   c                 C   r;   )aU  
    Decrypt the given ``ciphertext`` using the long-nonces xchacha20poly1305
    construction.

    :param ciphertext: authenticated ciphertext
    :type ciphertext: bytes
    :param aad:
    :type aad: Optional[bytes]
    :param nonce:
    :type nonce: bytes
    :param key:
    :type key: bytes
    :return: message
    :rtype: bytes
    r<   r   r=   Nr   r    r!   r"   r#   r   r>   )r   r%   r&   r'   r(   r)   Ú+_aead_xchacha20poly1305_ietf_CRYPTBYTES_MAXr*   r+   r   r   r   r   r-   r,   r   Ú*crypto_aead_xchacha20poly1305_ietf_decryptr/   r0   rA   r9   r9   r:   rJ   ä  s^   ýÿûý

ÿú	

ÿú	

ÿrJ   N)4Útypingr   Únaclr   r'   Únacl._sodiumr   r   Únacl.exceptionsr   Ú*crypto_aead_chacha20poly1305_ietf_keybytesr   ÚintÚ__annotations__Ú+crypto_aead_chacha20poly1305_ietf_nsecbytesr   Ú+crypto_aead_chacha20poly1305_ietf_npubbytesr	   Ú(crypto_aead_chacha20poly1305_ietf_abytesr
   Ú2crypto_aead_chacha20poly1305_ietf_messagebytes_maxr   r?   Ú%crypto_aead_chacha20poly1305_keybytesr   Ú&crypto_aead_chacha20poly1305_nsecbytesr   Ú&crypto_aead_chacha20poly1305_npubbytesr   Ú#crypto_aead_chacha20poly1305_abytesr   Ú-crypto_aead_chacha20poly1305_messagebytes_maxr   rF   Ú+crypto_aead_xchacha20poly1305_ietf_keybytesr   Ú,crypto_aead_xchacha20poly1305_ietf_nsecbytesr   Ú,crypto_aead_xchacha20poly1305_ietf_npubbytesr   Ú)crypto_aead_xchacha20poly1305_ietf_abytesr   Ú3crypto_aead_xchacha20poly1305_ietf_messagebytes_maxr   rI   r&   r.   r@   rD   rG   rH   rJ   r9   r9   r9   r:   Ú<module>   sâ   
ÿ
ÿ
ÿ
ÿ
ÿÿÿ
ÿ
ÿ
ÿ
ÿ
ÿÿÿ
ÿ
ÿ
ÿ
ÿ
ÿÿÿÿÿÿÿ
þOÿÿÿÿ
þOÿÿÿÿ
þPÿÿÿÿ
þOÿÿÿÿ
þPÿÿÿÿþ