o
    n~b                     @   sZ   d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 eddZG dd deZ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_ubytezCryptodome.Hash._keccaka  
                        int keccak_init(void **state,
                                        size_t capacity_bytes,
                                        uint8_t rounds);
                        int keccak_destroy(void *state);
                        int keccak_absorb(void *state,
                                          const uint8_t *in,
                                          size_t len);
                        int keccak_squeeze(const void *state,
                                           uint8_t *out,
                                           size_t len,
                                           uint8_t padding);
                        int keccak_digest(void *state,
                                          uint8_t *digest,
                                          size_t len,
                                          uint8_t padding);
                        int keccak_copy(const void *src, void *dst);
                        int keccak_reset(void *state);
                        c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )Keccak_HashzA Keccak hash object.
    Do not instantiate directly.
    Use the :func:`new` function.

    :ivar digest_size: the size in bytes of the resulting hash
    :vartype digest_size: integer
    c                 C   sv   || _ || _d| _d| _t }t| t| j d t	d}|r't
d| t| tj| _|r9| | d S d S )NF         z#Error %d while instantiating keccak)digest_size_update_after_digest_digest_done_paddingr   _raw_keccak_libZkeccak_initZ
address_ofr	   r   
ValueErrorr   getZkeccak_destroy_stateupdate)selfdatadigest_bytesupdate_after_digeststateresult r   A/usr/local/lib/python3.10/dist-packages/Cryptodome/Hash/keccak.py__init__E   s"   
zKeccak_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 keccak)r   r   	TypeErrorr   Zkeccak_absorbr   r   r
   r	   lenr   )r   r   r   r   r   r    r   X   s   
zKeccak_Hash.updatec                 C   sJ   d| _ t| j}t| j |t| jt| j	}|r!t
d| t|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
        TzError %d while squeezing keccak)r   r   r   r   Zkeccak_digestr   r   r	   r   r   r   r   )r   Zbfrr   r   r   r    digesti   s   
zKeccak_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>   s    z)Keccak_Hash.hexdigest.<locals>.<listcomp>)joinr$   )r   r   r   r    	hexdigest|   s   zKeccak_Hash.hexdigestc                 K   s(   d|vrd|vr| j |d< tdi |S )z"Create a fresh Keccak hash object.r   digest_bitsNr   )r   new)r   kwargsr   r   r    r,      s   
zKeccak_Hash.newN)	__name__
__module____qualname____doc__r!   r   r$   r*   r,   r   r   r   r    r   <   s    
r   c                  K   s   |  dd}|  dd}|  dd}|  dd}d||fvr"tdd||fkr,td	|dur9|d
vr8tdn|dvrAtd|d }| rOtdt|  t|||S )ao  Create a new hash object.

    Args:
        data (bytes/bytearray/memoryview):
            The very first chunk of the message to hash.
            It is equivalent to an early call to :meth:`Keccak_Hash.update`.
        digest_bytes (integer):
            The size of the digest, in bytes (28, 32, 48, 64).
        digest_bits (integer):
            The size of the digest, in bits (224, 256, 384, 512).
        update_after_digest (boolean):
            Whether :meth:`Keccak.digest` can be followed by another
            :meth:`Keccak.update` (default: ``False``).

    :Return: A :class:`Keccak_Hash` hash object
    r   Nr   Fr   r+   z*Only one digest parameter must be provided)NNz&Digest size (bits, bytes) not provided)       0   @   z('digest_bytes' must be: 28, 32, 48 or 64)      i  i   z,'digest_bytes' must be: 224, 256, 384 or 512   zUnknown parameters: )popr"   r   strr   )r-   r   r   r   r+   r   r   r    r,      s$   r,   N)ZCryptodome.Util.py3compatr   ZCryptodome.Util._raw_apir   r   r   r   r   r	   r
   r   r   objectr   r,   r   r   r   r    <module>   s   (S