U
    ÎZj0  ã                
   @   s¸   d dl Z d dlmZ d dlZd dlmZ ejjZ	ejj
ZejjZejjZejjZejjZejjZejjZejjZejjZejjZejjZG dd„ dƒZ de!e!e"e"e"e"e"e!dœdd„Z#dS )é    N)ÚNoReturn)Úbytes_as_stringc                   @   sÀ   e Zd ZdZeZeZeZ	e
Zdedddfeeeeedœdd„Zeedœdd„ƒZeedœd	d
„ƒZeedœdd„ƒZeddœdd„Zedœdd„Zedœdd„Zd dœdd„Zedœdd„ZdS )Úblake2bzK
    :py:mod:`hashlib` API compatible blake2b algorithm implementation
    ó    )ÚdataÚdigest_sizeÚkeyÚsaltÚpersonc                 C   s*   t ||||d�| _|| _|r&|  |¡ dS )ab  
        :py:class:`.blake2b` algorithm initializer

        :param data:
        :type data: bytes
        :param int digest_size: the requested digest size; must be
                                at most :py:attr:`.MAX_DIGEST_SIZE`;
                                the default digest size is :py:data:`.BYTES`
        :param key: the key to be set for keyed MAC/PRF usage; if set,
                    the key must be at most :py:data:`.KEYBYTES_MAX` long
        :type key: bytes
        :param salt: a initialization salt at most
                     :py:attr:`.SALT_SIZE` long; it will be zero-padded
                     if needed
        :type salt: bytes
        :param person: a personalization string at most
                       :py:attr:`.PERSONAL_SIZE` long; it will be zero-padded
                       if needed
        :type person: bytes
        )r   r	   r
   r   N)Ú	_b2b_initÚ_stateÚ_digest_sizeÚupdate)Úselfr   r   r   r	   r
   © r   úO/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/nacl/hashlib.pyÚ__init__0   s       ÿzblake2b.__init__)Úreturnc                 C   s   | j S ©N)r   ©r   r   r   r   r   U   s    zblake2b.digest_sizec                 C   s   dS )Né€   r   r   r   r   r   Ú
block_sizeY   s    zblake2b.block_sizec                 C   s   dS )Nr   r   r   r   r   r   Úname]   s    zblake2b.nameN)r   r   c                 C   s   t | j|ƒ d S r   )Ú_b2b_updater   )r   r   r   r   r   r   a   s    zblake2b.updatec                 C   s   | j  ¡ }t|ƒS r   )r   ÚcopyÚ
_b2b_final)r   Ú_str   r   r   Údigestd   s    
zblake2b.digestc                 C   s   t t |  ¡ ¡ƒS r   )r   ÚbinasciiÚhexlifyr   r   r   r   r   Ú	hexdigesth   s    zblake2b.hexdigestc                 C   s$   t | ƒ| jd�}| j ¡ }||_|S )N)r   )Útyper   r   r   )r   Z_cpr   r   r   r   r   k   s    
zblake2b.copyc                 C   s   t d | jj¡ƒ‚dS )zc
        Raise the same exception as hashlib's blake implementation
        on copy.copy()
        zcan't pickle {} objectsN)Ú	TypeErrorÚformatÚ	__class__Ú__name__r   r   r   r   Ú
__reduce__q   s    ÿzblake2b.__reduce__)r%   Ú
__module__Ú__qualname__Ú__doc__ÚBYTESÚMAX_DIGEST_SIZEÚKEYBYTES_MAXÚMAX_KEY_SIZEÚPERSONALBYTESÚPERSON_SIZEÚ	SALTBYTESÚ	SALT_SIZEÚbytesÚintr   Úpropertyr   r   Ústrr   r   r   r    r   r   r&   r   r   r   r   r   &   s8   úú%r   r   é   é   é   é   é@   )Úpasswordr	   ÚnÚrÚpÚmaxmemÚdklenr   c              	   C   s   t jj| ||||||d�S )a  
    Derive a cryptographic key using the scrypt KDF.

    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.

    Implements the same signature as the ``hashlib.scrypt`` implemented
    in cpython version 3.6
    )r?   r@   )ÚnaclÚbindingsZ%crypto_pwhash_scryptsalsa208sha256_ll)r;   r	   r<   r=   r>   r?   r@   r   r   r   Úscrypt{   s          ÿrC   )r   r6   r7   r8   r9   r:   )$r   Útypingr   Znacl.bindingsrA   Z
nacl.utilsr   rB   Zcrypto_generichash_BYTESr*   Zcrypto_generichash_BYTES_MINZ	BYTES_MINZcrypto_generichash_BYTES_MAXZ	BYTES_MAXZcrypto_generichash_KEYBYTESZKEYBYTESZcrypto_generichash_KEYBYTES_MINZKEYBYTES_MINZcrypto_generichash_KEYBYTES_MAXr,   Zcrypto_generichash_SALTBYTESr0   Z crypto_generichash_PERSONALBYTESr.   Z&has_crypto_pwhash_scryptsalsa208sha256ZSCRYPT_AVAILABLEZcrypto_generichash_blake2b_initr   Z crypto_generichash_blake2b_finalr   Z!crypto_generichash_blake2b_updater   r   r2   r3   rC   r   r   r   r   Ú<module>   s@   W      ùø