o
    Þý°j•  ã                   @   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                   @   s@   e Zd ZdZdZddd„Zdd„ Zdd	„ Zd
d„ Zddd„Z	dS )ÚSHAKE128_XOFz˜A 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   Úkeccak_initÚ
address_ofr   r
   Ú
ValueErrorr   ÚgetÚkeccak_destroyÚ_stateÚ_is_squeezingÚ_paddingÚupdate)ÚselfÚdataÚstateÚresult© r   ú‹/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-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 )z¼Continue 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   Ú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   Úkeccak_squeezer   r   r   r
   r   r   r   )r   ÚlengthÚbfrr   r   r   r   ÚreadV   s   ýÿzSHAKE128_XOF.readc                 C   s4   |   ¡ }t | j ¡ |j ¡ ¡}|rtd| ƒ‚|S )z¾Return a copy ("clone") of the hash object.

        The copy will have the same internal state as the original hash
        object.

        :return: A hash object of the same type
        zError %d while copying SHAKE128)Únewr   Úkeccak_copyr   r   r   )r   Úcloner   r   r   r   Úcopyq   s   	ÿzSHAKE128_XOF.copyc                 C   s   t | ƒ|d�S )N©r   )Útype)r   r   r   r   r   r'   �   s   zSHAKE128_XOF.new©N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úoidr   r   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'   …   s   
r'   r-   )ÚCryptodome.Util.py3compatr   ÚCryptodome.Util._raw_apir   r   r   r   r   r   r	   r
   ÚCryptodome.Hash.keccakr   Úobjectr   r'   r   r   r   r   Ú<module>   s
   (\