a
   3h                   @   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                   @   s   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d ZdS )blake2bzK
    :py:mod:`hashlib` API compatible blake2b algorithm implementation
        c                 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
        )keysaltpersondigest_sizeN)	_b2b_init_state_digest_sizeupdate)selfdatar   r   r	   r
    r   0/usr/lib/python3.9/site-packages/nacl/hashlib.py__init__/   s    zblake2b.__init__c                 C   s   | j S N)r   r   r   r   r   r   M   s    zblake2b.digest_sizec                 C   s   dS )N   r   r   r   r   r   
block_sizeQ   s    zblake2b.block_sizec                 C   s   dS )Nr   r   r   r   r   r   nameU   s    zblake2b.namec                 C   s   t | j| d S r   )_b2b_updater   )r   r   r   r   r   r   Y   s    zblake2b.updatec                 C   s   | j  }t|S r   )r   copy
_b2b_final)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}| j }||_|S )N)r   )typer   r   r   )r   Z_cpr   r   r   r   r   c   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__i   s    zblake2b.__reduce__N)r%   
__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   r   &   s&   



r                @   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
    )maxmemdklen)naclbindingsZ%crypto_pwhash_scryptsalsa208sha256_ll)passwordr	   nrpr5   r6   r   r   r   scryptr   s    r=   )r/   r0   r1   r2   r3   r4   )%Z
__future__r   r   r   r   Znacl.bindingsr7   Z
nacl.utilsr   r8   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&has_crypto_pwhash_scryptsalsa208sha256ZSCRYPT_AVAILABLEZcrypto_generichash_blake2b_initr   Z crypto_generichash_blake2b_finalr   Z!crypto_generichash_blake2b_updater   objectr   r=   r   r   r   r   <module>   s&   L  