3
¬ �e�  ã               @   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    || _ |jd|dƒ| _d | _d S )Nó    s	   TupleHash)Údigest_sizeZ_newÚ_cshakeÚ_digest)ÚselfÚcustomZcshaker   © r   ú_/var/www/html/wholesaler-api-python-env/lib/python3.6/site-packages/Crypto/Hash/TupleHash128.pyÚ__init__+   s    zTupleHash.__init__c             G   sD   | j dk	rtdƒ‚x,|D ]$}t|ƒs,tdƒ‚| jjt|ƒƒ qW | S )zÜAuthenticate the next tuple of byte strings.
        TupleHash guarantees the logical separation between each byte string.

        Args:
            data (bytes/bytearray/memoryview): One or more items to hash.
        Nz6You cannot call 'update' after 'digest' or 'hexdigest'z#You can only call 'update' on bytes)r   Ú	TypeErrorr   r   Úupdater   )r   ÚdataÚitemr   r   r   r   2   s    

zTupleHash.updatec             C   s6   | j dkr0| jjt| jd ƒƒ | j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   ÚdigestD   s    
zTupleHash.digestc             C   s   dj dd„ t| jƒ ƒ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>X   s    z'TupleHash.hexdigest.<locals>.<listcomp>)ÚjoinÚtupler   )r   r   r   r   Ú	hexdigestQ   s    zTupleHash.hexdigestc             K   s$   d|krd|kr| j |d< tf |ŽS )zNReturn a new instance of a TupleHash object.
        See :func:`new`.
        Údigest_bytesÚdigest_bits)r   Únew)r   Úkwargsr   r   r   r#   Z   s    
zTupleHash.newN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r#   r   r   r   r   r	   %   s   	r	   c              K   sŽ   | j ddƒ}| j ddƒ}d||fkr,tdƒ‚d||fkr<d}|dk	rV|dk rvtdƒ‚n |dk sf|d rntdƒ‚|d }| j d	d
ƒ}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é@   r   z!'digest_bytes' must be at least 8z0'digest_bytes' must be at least 64 in steps of 8r   r
   )NN)Úpopr   Ú
ValueErrorr	   r   )r$   r!   r"   r   r   r   r   r#   e   s    
r#   N)ZCrypto.Util.py3compatr   r   r   r   r   r   r   Úobjectr	   r#   r   r   r   r   Ú<module>   s   @