o
    ‰¡e‹  ã                   @   sb   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„ 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)Ú_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_512_HashzúA SHA3-512 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.10éH   c                 C   sf   || _ d| _tƒ }t | ¡ t| jd ƒd¡}|rtd| ƒ‚t	| 
¡ tjƒ| _|r1|  |¡ d S d S )NFé   é   ú&Error %d while instantiating SHA-3/512)Ú_update_after_digestÚ_digest_doner   r   Úkeccak_initÚ
address_ofr	   Údigest_sizeÚ
ValueErrorr   ÚgetÚkeccak_destroyÚ_stateÚupdate)ÚselfÚdataÚupdate_after_digestÚstateÚresult© r!   ú:/usr/lib/python3/dist-packages/Cryptodome/Hash/SHA3_512.pyÚ__init__4   s"   
þÿÿÿzSHA3_512_Hash.__init__c                 C   sH   | j r
| js
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.
        z8You can only call 'digest' or 'hexdigest' on this objectz!Error %d while updating SHA-3/512)r   r   Ú	TypeErrorr   Úkeccak_absorbr   r   r
   r	   Úlenr   )r   r   r    r!   r!   r"   r   D   s   
þÿzSHA3_512_Hash.updatec                 C   sJ   d| _ t| jƒ}t | j ¡ |t| jƒ¡}|rtd| ƒ‚t	|ƒ| _
| j
S )zçReturn 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   Úkeccak_digestr   r   r	   r   r   Ú_digest_value)r   Úbfrr    r!   r!   r"   ÚdigestV   s   	
þÿ
zSHA3_512_Hash.digestc                 C   s   d  dd„ |  ¡ D ƒ¡S )zÝReturn 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>t   s    z+SHA3_512_Hash.hexdigest.<locals>.<listcomp>)Újoinr*   )r   r!   r!   r"   Ú	hexdigestl   s   zSHA3_512_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-512)Únewr   Úkeccak_copyr   r   r   )r   Úcloner    r!   r!   r"   Úcopyv   s   ÿzSHA3_512_Hash.copyNc                 C   s   t | ƒ|| jƒS )z$Create a fresh SHA3-521 hash object.)Útyper   )r   r   r!   r!   r"   r1   ˆ   s   zSHA3_512_Hash.new)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚoidÚ
block_sizer#   r   r*   r0   r4   r1   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_512_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"   r1   Ž   s   
r1   r   N)ÚCryptodome.Util.py3compatr   ÚCryptodome.Util._raw_apir   r   r   r   r   r	   r
   ÚCryptodome.Hash.keccakr   Úobjectr   r1   r   r;   r!   r!   r!   r"   Ú<module>   s   $o