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_ABYTES2crypto_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_ABYTES3crypto_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   S/var/www/html/api-tag/env/lib/python3.10/site-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