o
    Ìn~bt  ã                   @   sL   d dl mZmZmZ ddlmZ ddlmZmZ G dd„ deƒZ	dd„ Z
d	S )
é    )ÚbordÚis_bytesÚtobytesé   )Ú	cSHAKE128)Ú_encode_strÚ_right_encodec                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )Ú	TupleHashz\A Tuple hash object.
    Do not instantiate directly.
    Use the :func:`new` function.
    c                 C   s    || _ | d|d¡| _d | _d S )Nó    s	   TupleHash)Údigest_sizeÚ_newÚ_cshakeÚ_digest)ÚselfÚcustomZcshaker   © r   úG/usr/local/lib/python3.10/dist-packages/Cryptodome/Hash/TupleHash128.pyÚ__init__+   s   
zTupleHash.__init__c                 C   s:   | j dur	tdƒ‚t|ƒstdƒ‚| j tt|ƒƒ¡ | S )zŒAuthenticate the next byte string in the tuple.

        Args:
            data (bytes/bytearray/memoryview): The next byte string.
        Nz6You cannot call 'update' after 'digest' or 'hexdigest'z#You can only call 'update' on bytes)r   Ú	TypeErrorr   r   Úupdater   r   )r   Údatar   r   r   r   2   s   
zTupleHash.updatec                 C   s6   | j du r| j t| jd ƒ¡ | j | j¡| _ | j S )zŸReturn the **binary** (non-printable) digest of the tuple of byte strings.

        :return: The hash digest. Binary form.
        :rtype: byte string
        Né   )r   r   r   r   r   Úread©r   r   r   r   ÚdigestC   s   
zTupleHash.digestc                 C   s   d  dd„ t|  ¡ ƒD ƒ¡S )z•Return the **printable** digest of the tuple of byte strings.

        :return: The hash digest. Hexadecimal encoded.
        :rtype: string
        Ú c                 S   s   g | ]}d t |ƒ ‘qS )z%02x)r   )Ú.0Úxr   r   r   Ú
<listcomp>W   s    z'TupleHash.hexdigest.<locals>.<listcomp>)ÚjoinÚtupler   r   r   r   r   Ú	hexdigestP   s   zTupleHash.hexdigestc                 K   s(   d|vrd|vr| j |d< tdi |¤ŽS )zNReturn a new instance of a TupleHash object.
        See :func:`new`.
        Údigest_bytesÚdigest_bitsNr   )r   Únew)r   Úkwargsr   r   r   r$   Y   s   
zTupleHash.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||fvrtdƒ‚d||fkrd}|dur+|dk r*tdƒ‚n|dk s3|d r7td	ƒ‚|d }|   d
d¡}| rKtdt| ƒ ƒ‚t|t|ƒS )aî  Create a new TupleHash128 object.

    Args:
       digest_bytes (integer):
        Optional. The size of the digest, in bytes.
        Default is 64. Minimum is 8.
       digest_bits (integer):
        Optional and alternative to ``digest_bytes``.
        The size of the digest, in bits (and in steps of 8).
        Default is 512. Minimum is 64.
       custom (bytes):
        Optional.
        A customization bytestring (``S`` in SP 800-185).

    :Return: A :class:`TupleHash` object
    r"   Nr#   z*Only one digest parameter must be provided)NNé@   r   z!'digest_bytes' must be at least 8z0'digest_bytes' must be at least 64 in steps of 8r   r
   zUnknown parameters: )Úpopr   Ú
ValueErrorÚstrr	   r   )r%   r"   r#   r   r   r   r   r$   d   s"   ÿr$   N)ZCryptodome.Util.py3compatr   r   r   r   r   r   r   Úobjectr	   r$   r   r   r   r   Ú<module>   s
   ?