U
    ֫[E                     @   s   d dl mZmZmZ d dl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e"Z#dddZ$dS )    )absolute_importdivisionprint_functionN)bytes_as_stringc                   @   sx   e Zd ZdZeZeZeZ	e
ZdedddfddZedd Zedd Zed	d
 Zdd Zdd Zdd Zdd ZdS )blake2bzK
    :py:mod:`hashlib` API compatible blake2b algorithm implementation
        c                 C   s*   t ||||d| _|| _|r&| | dS )ac  
        :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: an 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
        )keysaltpersondigest_sizeN)	_b2b_init_state_digest_sizeupdate)selfdatar   r   r	   r
    r   ./usr/lib/python3/dist-packages/nacl/hashlib.py__init__.   s    zblake2b.__init__c                 C   s   | j S N)r   r   r   r   r   r   L   s    zblake2b.digest_sizec                 C   s   dS )N   r   r   r   r   r   
block_sizeP   s    zblake2b.block_sizec                 C   s   dS )Nr   r   r   r   r   r   nameT   s    zblake2b.namec                 C   s   t | j| d S r   )_b2b_updater   )r   r   r   r   r   r   X   s    zblake2b.updatec                 C   s   t j| j}t|| jS r   )naclbindings%crypto_generichash_blake2b_state_copyr   
_b2b_finalr   )r   _str   r   r   digest[   s    zblake2b.digestc                 C   s   t t|  S r   )r   binasciiZhexlifyr    r   r   r   r   	hexdigest_   s    zblake2b.hexdigestc                 C   s$   t | | jd}t| j}||_|S )N)r   )typer   	_b2b_copyr   )r   Z_cpr   r   r   r   copyb   s    
zblake2b.copyN)__name__
__module____qualname____doc__BYTESZMAX_DIGEST_SIZEKEYBYTES_MAXZMAX_KEY_SIZEPERSONALBYTESZPERSON_SIZE	SALTBYTESZ	SALT_SIZEr   propertyr   r   r   r   r    r"   r%   r   r   r   r   r   %   s&    



r                @   c              	   C   s   t jj| ||||||dS )z
    Derive a cryptographic key using the scrypt KDF.

    Implements the same signature as the ``hashlib.scrypt`` implemented
    in cpython version 3.6
    )maxmemdklen)r   r   Z%crypto_pwhash_scryptsalsa208sha256_ll)Zpasswordr	   nrpr5   r6   r   r   r   scrypti   s          r:   )r/   r0   r1   r2   r3   r4   )%Z
__future__r   r   r   r!   Znacl.bindingsr   Z
nacl.utilsr   r   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_SALTBYTESr-   Z crypto_generichash_PERSONALBYTESr,   Zcrypto_generichash_blake2b_initr   Z crypto_generichash_blake2b_finalr   r   r$   Z!crypto_generichash_blake2b_updater   objectr   r:   r   r   r   r   <module>   s(   D    