o
    n~b                     @   s^   d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZ G dd deZd	ddZdS )
    )bord)load_pycryptodome_raw_libVoidPointerSmartPointercreate_string_bufferget_raw_bufferc_size_tc_uint8_ptrc_ubyte)_raw_keccak_libc                   @   s8   e Zd ZdZdZdddZdd Zdd	 Zdd
dZdS )SHAKE128_XOFzA SHAKE128 hash object.
    Do not instantiate directly.
    Use the :func:`new` function.

    :ivar oid: ASN.1 Object ID
    :vartype oid: string
    z2.16.840.1.101.3.4.2.11Nc                 C   sd   t  }t| tdtd}|rtd| t| tj	| _
d| _d| _|r0| | d S d S )N       z%Error %d while instantiating SHAKE128F   )r   r   Zkeccak_initZ
address_ofr   r
   
ValueErrorr   getZkeccak_destroy_state_is_squeezing_paddingupdate)selfdatastateresult r   C/usr/local/lib/python3.10/dist-packages/Cryptodome/Hash/SHAKE128.py__init__5   s"   
zSHAKE128_XOF.__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 SHAKE128 state)
r   	TypeErrorr   Zkeccak_absorbr   r   r	   r   lenr   )r   r   r   r   r   r   r   D   s   
zSHAKE128_XOF.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 SHAKE128)r   r   r   Zkeccak_squeezer   r   r   r
   r   r   r   )r   lengthZbfrr   r   r   r   readV   s   zSHAKE128_XOF.readc                 C   s   t | |dS )Nr   )type)r   r   r   r   r   newq   s   zSHAKE128_XOF.newN)	__name__
__module____qualname____doc__oidr   r   r    r#   r   r   r   r   r   )   s    	
r   Nc                 C   s
   t | dS )a  Return a fresh instance of a SHAKE128 object.

    Args:
       data (bytes/bytearray/memoryview):
        The very first chunk of the message to hash.
        It is equivalent to an early call to :meth:`update`.
        Optional.

    :Return: A :class:`SHAKE128_XOF` object
    r!   )r   r!   r   r   r   r#   u   s   
r#   r$   )ZCryptodome.Util.py3compatr   ZCryptodome.Util._raw_apir   r   r   r   r   r   r	   r
   ZCryptodome.Hash.keccakr   objectr   r#   r   r   r   r   <module>   s
   (L