U
    ÎZjí<  ã                   @   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,e-ee- e-e-e-dœdd„Z.e-ee- e-e-e-dœdd„Z/e-ee- e-e-e-dœdd„Z0e-ee- e-e-e-dœdd„Z1e-ee- e-e-e-dœdd„Z2e-ee- e-e-e-dœ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ƒpJ|dkdtjd� t t|tƒolt|ƒt	kd t	¡tjd� t t|tƒo”t|ƒ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©Z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© r8   ú\/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/nacl/bindings/crypto_aead.pyr-   W   sn    ýÿûý

ÿú	

ÿú	

        ÿr-   )r6   r   r   r   r   c                 C   s(  t t| tƒdtjd� t| ƒ}t |tkd t¡tjd� t t|tƒpJ|dkdtjd� t t|tƒolt|ƒt	kd t	¡tjd� t t|tƒo”t|ƒt
kd t
¡tjd� |t }t d¡}t d	|¡}|rÖ|}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.   r/   ©r6   r   r   r   r5   r4   r1   r   r2   r3   r7   r8   r8   r9   r>   ¦   sn    ýÿûý

ÿú	

ÿú	

        ÿr>   c                 C   s0  t t| tƒdtjd� t| ƒ}t |tkd t¡tjd� t t|tƒpJ|dkdtjd� t t|tƒolt|ƒt	kd t	¡tjd� t t|tƒo”t|ƒ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.   r/   r0   r8   r8   r9   r@   õ   sp    ýÿûý

ÿú	

ÿú	

        ÿr@   c                 C   s(  t t| tƒdtjd� t| ƒ}t |tkd t¡tjd� t t|tƒpJ|dkdtjd� t t|tƒolt|ƒt	kd t	¡tjd� t t|tƒo”t|ƒt
kd t
¡tjd� |t }t d¡}t d	|¡}|rÖ|}t|ƒ}	n
tj}d
}	t ||tj| |||	||¡	}
t |
d
kdtjd� t ||d
 ¡dd… S )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.   r/   r?   r8   r8   r9   rB   E  sn    ýÿûý

ÿú	

ÿú	

        ÿrB   c                 C   s0  t t| tƒdtjd� t| ƒ}t |tkd t¡tjd� t t|tƒpJ|dkdtjd� t t|tƒolt|ƒt	kd t	¡tjd� t t|tƒo”t|ƒ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 )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.   r/   r0   r8   r8   r9   rC   ”  sp    ýÿûý

ÿú	

ÿú	

        ÿrC   c                 C   s(  t t| tƒdtjd� t| ƒ}t |tkd t¡tjd� t t|tƒpJ|dkdtjd� t t|tƒolt|ƒt	kd t	¡tjd� t t|tƒo”t|ƒt
kd t
¡tjd� |t }t d¡}t d	|¡}|rÖ|}t|ƒ}	n
tj}d
}	t ||tj| |||	||¡	}
t |
d
kdtjd� t ||d
 ¡dd… S )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.   r/   r?   r8   r8   r9   rE   ä  sn    ýÿûý

ÿú	

ÿú	

        ÿrE   N)4Útypingr   Znaclr   r&   Znacl._sodiumr   r   Znacl.exceptionsr   Z*crypto_aead_chacha20poly1305_ietf_keybytesr   ÚintÚ__annotations__Z+crypto_aead_chacha20poly1305_ietf_nsecbytesr   Z+crypto_aead_chacha20poly1305_ietf_npubbytesr	   Z(crypto_aead_chacha20poly1305_ietf_abytesr
   Z2crypto_aead_chacha20poly1305_ietf_messagebytes_maxr   r=   Z%crypto_aead_chacha20poly1305_keybytesr   Z&crypto_aead_chacha20poly1305_nsecbytesr   Z&crypto_aead_chacha20poly1305_npubbytesr   Z#crypto_aead_chacha20poly1305_abytesr   Z-crypto_aead_chacha20poly1305_messagebytes_maxr   rA   Z+crypto_aead_xchacha20poly1305_ietf_keybytesr   Z,crypto_aead_xchacha20poly1305_ietf_nsecbytesr   Z,crypto_aead_xchacha20poly1305_ietf_npubbytesr   Z)crypto_aead_xchacha20poly1305_ietf_abytesr   Z3crypto_aead_xchacha20poly1305_ietf_messagebytes_maxr   rD   r%   r-   r>   r@   rB   rC   rE   r8   r8   r8   r9   Ú<module>   s¤    	ÿ
ÿ
ÿ
ÿ
ÿ
ÿÿÿ
ÿ
ÿ
ÿ
ÿ
ÿÿÿ
ÿ
ÿ
ÿ
ÿ
ÿÿ   þP   þP   þQ   þP   þQ   þ