o
    5h                     @   sd   d dl mZmZmZmZmZmZmZ d dlm	Z	 d dl
mZ ddlmZ G dd deZdd	 Zd
S )    )VoidPointerSmartPointercreate_string_bufferget_raw_bufferc_size_tc_uint8_ptrc_ubyte)long_to_bytes)bchr   )_raw_keccak_libc                   @   s:   e Zd ZdZdd Zdd Zdd Zdd	d
Zdd ZdS )
TurboSHAKEzaA TurboSHAKE hash object.
    Do not instantiate directly.
    Use the :func:`new` function.
    c                 C   sj   t  }t| t|td}|rtd| t| tj	| _
d| _|| _|| _|r3| | d S d S )N   z'Error %d while instantiating TurboSHAKEF)r   r   keccak_init
address_ofr   r   
ValueErrorr   getkeccak_destroy_state_is_squeezing	_capacity_domainupdate)selfcapacitydomain_separationdatastateresult r   m/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/Crypto/Hash/TurboSHAKE128.py__init__   s    
zTurboSHAKE.__init__c                 C   sB   | j rtdt| j t|tt|}|rt	d| | S )zContinue hashing of a message by consuming the next chunk of data.

        Args:
            data (byte string/byte array/memoryview): The next chunk of the message being hashed.
        z/You cannot call 'update' after the first 'read'z(Error %d while updating TurboSHAKE state)
r   	TypeErrorr   keccak_absorbr   r   r   r   lenr   )r   r   r   r   r   r    r   %   s   
zTurboSHAKE.updatec                 C   sF   d| _ t|}t| j |t|t| j}|rt	d| t
|S )ah  
        Compute the next piece of XOF output.

        .. note::
            You cannot use :meth:`update` anymore after the first call to
            :meth:`read`.

        Args:
            length (integer): the amount of bytes this method must return

        :return: the next piece of XOF output (of the given length)
        :rtype: byte string
        Tz)Error %d while extracting from TurboSHAKE)r   r   r   keccak_squeezer   r   r   r   r   r   r   )r   lengthbfrr   r   r   r    read7   s   zTurboSHAKE.readNc                 C   s   t | | j| j|S N)typer   r   )r   r   r   r   r    newR   s   zTurboSHAKE.newc                 C   s*   t | j }|rtd| d| _d S )Nz)Error %d while resetting TurboSHAKE stateF)r   keccak_resetr   r   r   r   )r   r   r   r   r    _resetU   s   
zTurboSHAKE._resetr)   )	__name__
__module____qualname____doc__r!   r   r(   r+   r-   r   r   r   r    r      s    
r   c                  K   sF   |  dd}d|  krdksn td| |  d}td||dS )	a  Create a new TurboSHAKE128 object.

    Args:
       domain (integer):
         Optional - A domain separation byte, between 0x01 and 0x7F.
         The default value is 0x1F.
       data (bytes/bytearray/memoryview):
        Optional - The very first chunk of the message to hash.
        It is equivalent to an early call to :meth:`update`.

    :Return: A :class:`TurboSHAKE` object
    domain   r      z&Incorrect domain separation value (%d)r       )r   )r   r   r   )kwargsr   r   r   r   r    r+   ]   s   
r+   N)Crypto.Util._raw_apir   r   r   r   r   r   r   Crypto.Util.numberr	   Crypto.Util.py3compatr
   keccakr   objectr   r+   r   r   r   r    <module>   s   $ Q