o
    n~b/                     @   sf   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 ZejZ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                   @   sN   e Zd ZdZdZdZdZdd Zdd Zd	d
 Z	dd Z
dd ZdddZdS )SHA3_256_HashzA SHA3-256 hash object.
    Do not instantiate directly.
    Use the :func:`new` function.

    :ivar oid: ASN.1 Object ID
    :vartype oid: string

    :ivar digest_size: the size in bytes of the resulting hash
    :vartype digest_size: integer
        z2.16.840.1.101.3.4.2.8   c                 C   sp   || _ d| _d| _t }t| t| jd t	d}|r$t
d| t| tj| _|r6| | d S d S )NF         &Error %d while instantiating SHA-3/256)_update_after_digest_digest_done_paddingr   r   Zkeccak_initZ
address_ofr	   digest_sizer   
ValueErrorr   getZkeccak_destroy_stateupdate)selfdataupdate_after_digeststateresult r!   C/usr/local/lib/python3.10/dist-packages/Cryptodome/Hash/SHA3_256.py__init__4   s$   
zSHA3_256_Hash.__init__c                 C   sH   | j r
| js
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.
        z8You can only call 'digest' or 'hexdigest' on this objectz!Error %d while updating SHA-3/256)r   r   	TypeErrorr   Zkeccak_absorbr   r   r
   r	   lenr   )r   r   r    r!   r!   r"   r   E   s   
zSHA3_256_Hash.updatec                 C   sR   d| _ t| j}t| j |t| jt| j	}|r!t
d| t|| _| jS )zReturn the **binary** (non-printable) digest of the message that has been hashed so far.

        :return: The hash digest, computed over the data processed so far.
                 Binary form.
        :rtype: byte string
        Tr   )r   r   r   r   Zkeccak_digestr   r   r	   r   r   r   r   Z_digest_value)r   Zbfrr    r!   r!   r"   digestX   s   

zSHA3_256_Hash.digestc                 C   s   d dd |  D S )zReturn the **printable** digest of the message that has been hashed so far.

        :return: The hash digest, computed over the data processed so far.
                 Hexadecimal encoded.
        :rtype: string
         c                 S   s   g | ]}d t | qS )z%02xr   ).0xr!   r!   r"   
<listcomp>v   s    z+SHA3_256_Hash.hexdigest.<locals>.<listcomp>)joinr&   )r   r!   r!   r"   	hexdigestn   s   zSHA3_256_Hash.hexdigestc                 C   s4   |   }t| j |j }|rtd| |S )a4  Return a copy ("clone") of the hash object.

        The copy will have the same internal state as the original hash
        object.
        This can be used to efficiently compute the digests of strings that
        share a common initial substring.

        :return: A hash object of the same type
        zError %d while copying SHA3-256)newr   Zkeccak_copyr   r   r   )r   cloner    r!   r!   r"   copyx   s   zSHA3_256_Hash.copyNc                 C   s   t | || jS )z$Create a fresh SHA3-256 hash object.)typer   )r   r   r!   r!   r"   r-      s   zSHA3_256_Hash.new)N)__name__
__module____qualname____doc__r   oid
block_sizer#   r   r&   r,   r/   r-   r!   r!   r!   r"   r      s    
r   c                  O   sV   | dd}| dd}t| dkr|rtd| d }|r&tdt| t||S )	a  Create a new hash object.

    Args:
        data (byte string/byte array/memoryview):
            The very first chunk of the message to hash.
            It is equivalent to an early call to :meth:`update`.
        update_after_digest (boolean):
            Whether :meth:`digest` can be followed by another :meth:`update`
            (default: ``False``).

    :Return: A :class:`SHA3_256_Hash` hash object
    r   Nr   F   z%Initial data for hash specified twicer   zUnknown parameters: )popr%   r   r$   strr   )argskwargsr   r   r!   r!   r"   r-      s   
r-   r   N)ZCryptodome.Util.py3compatr   ZCryptodome.Util._raw_apir   r   r   r   r   r	   r
   r   ZCryptodome.Hash.keccakr   objectr   r-   r   r6   r!   r!   r!   r"   <module>   s   (q