File: //proc/self/root/lib/python3/dist-packages/nacl/bindings/__pycache__/crypto_box.cpython-38.pyc
U
�֫[�% � @ s� d dl mZmZmZ d dlmZ d dlmZm Z d dl
mZ ddgZe �
� Ze �� Ze �� Ze �� Ze �� Ze �� Ze �� Ze �� Zdd� Zdd � Zd
d� Zdd� Z d
d� Z!dd� Z"dd� Z#dd� Z$dd� Z%dS )� )�absolute_import�division�print_function)�
exceptions)�ffi�lib)�ensure�crypto_box_keypair�
crypto_boxc C s` t �dt�} t �dt�}t�| |�}t|dkdtjd� t � | t�dd� t � |t�dd� fS )zq
Returns a randomly generated public and secret key.
:rtype: (bytes(public_key), bytes(secret_key))
�unsigned char[]r �Unexpected library error�ZraisingN)
r �new�crypto_box_PUBLICKEYBYTES�crypto_box_SECRETKEYBYTESr r r �exc�RuntimeError�buffer)�pk�sk�rc� r �:/usr/lib/python3/dist-packages/nacl/bindings/crypto_box.pyr # s ��c C s� t t| t�dtd� t| �tkr*t�d��t� dt
�}t� dt�}t�
||| �}t |dkdtjd� t�|t
�dd� t�|t�dd� fS )a
Returns a (public, secret) keypair deterministically generated
from an input ``seed``.
.. warning:: The seed **must** be high-entropy; therefore,
its generator **must** be a cryptographic quality
random function like, for example, :func:`~nacl.utils.random`.
.. warning:: The seed **must** be protected and remain secret.
Anyone who knows the seed is really in possession of
the corresponding PrivateKey.
:param seed: bytes
:rtype: (bytes(public_key), bytes(secret_key))
zseed must be bytesr
zInvalid seedr r r N)r �
isinstance�bytes� TypeError�len�crypto_box_SEEDBYTESr �
ValueErrorr r r r r �crypto_box_seed_keypairr r )Zseedr r r r r r r 7 s
�
��r c C s� t |�tkrt�d��t |�tkr,t�d��t |�tkrBt�d��dt | }t�dt |��}t �
||t |�|||�}t|dkdtjd� t�
|t |��td � S )
z�
Encrypts and returns a message ``message`` using the secret key ``sk``,
public key ``pk``, and the nonce ``nonce``.
:param message: bytes
:param nonce: bytes
:param pk: bytes
:param sk: bytes
:rtype: bytes
�Invalid nonce size�Invalid public key�Invalid secret key� r r r r
N)r �crypto_box_NONCEBYTESr r r r �crypto_box_ZEROBYTESr r r r
r r r �crypto_box_BOXZEROBYTES)�message�noncer r �padded�
ciphertextr r r r r
] s
�c C s� t |�tkrt�d��t |�tkr,t�d��t |�tkrBt�d��dt | }t�dt |��}t �
||t |�|||�}t|dkdtjd� t�
|t |��td � S )
a
Decrypts and returns an encrypted message ``ciphertext``, using the secret
key ``sk``, public key ``pk``, and the nonce ``nonce``.
:param ciphertext: bytes
:param nonce: bytes
:param pk: bytes
:param sk: bytes
:rtype: bytes
r r! r"