o
    e0                     @   sZ   d dl mZ d dl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)_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   sZ   t  }t| tdd}|rtd| t| tj| _	d| _
|r+| | d S d S )N       z%Error %d while instantiating SHAKE128F)r   r
   keccak_init
address_ofr   
ValueErrorr   getkeccak_destroy_state_is_squeezingupdate)selfdatastateresult r   :/usr/lib/python3/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
   keccak_absorbr   r   r	   r   lenr   )r   r   r   r   r   r   r   C   s   
zSHAKE128_XOF.updatec                 C   s>   d| _ t|}t| j |t|}|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   lengthbfrr   r   r   r   readU   s   zSHAKE128_XOF.readc                 C   s   t | |dS )Nr   )type)r   r   r   r   r   newo   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&   s   s   
r&   r'   )Cryptodome.Util.py3compatr   Cryptodome.Util._raw_apir   r   r   r   r   r   r	   Cryptodome.Hash.keccakr
   objectr   r&   r   r   r   r   <module>   s
   $J