U
    ÈZjš  ã                   @   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 )ÚSHAKE256_XOFz˜A SHAKE256 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.12Nc                 C   s`   t ƒ }t | ¡ tdƒtdƒ¡}|r0td| ƒ‚t| ¡ tj	ƒ| _
d| _d| _|r\|  |¡ d S )Né@   é   z%Error %d while instantiating SHAKE256Fé   )r   r   Zkeccak_initZ
address_ofr   r
   Ú
ValueErrorr   ÚgetZkeccak_destroyÚ_stateÚ_is_squeezingÚ_paddingÚupdate)ÚselfÚdataÚstateÚresult© r   úW/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/Crypto/Hash/SHAKE256.pyÚ__init__5   s     
þÿÿzSHAKE256_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 SHAKE256 state)
r   Ú	TypeErrorr   Zkeccak_absorbr   r   r	   r   Úlenr   )r   r   r   r   r   r   r   E   s    
þÿzSHAKE256_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 SHAKE256)r   r   r   Zkeccak_squeezer   r   r   r
   r   r   r   )r   ÚlengthZbfrr   r   r   r   ÚreadW   s    ýÿzSHAKE256_XOF.readc                 C   s   t | ƒ|d�S )N©r   )Útype)r   r   r   r   r   Únewr   s    zSHAKE256_XOF.new)N)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 SHAKE256 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:`SHAKE256_XOF` object
    r!   )r   r!   r   r   r   r#   v   s    r#   )N)ZCrypto.Util.py3compatr   ZCrypto.Util._raw_apir   r   r   r   r   r   r	   r
   ZCrypto.Hash.keccakr   Úobjectr   r#   r   r   r   r   Ú<module>   s   (M