o
    Ìn~b.  ã                   @   sh   d dl T d dl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d	„ZejZejZd
d„ ZdS )é    )Ú*)Úload_pycryptodome_raw_libÚVoidPointerÚSmartPointerÚcreate_string_bufferÚget_raw_bufferÚc_size_tÚc_uint8_ptrzCryptodome.Hash._SHA1aª  
                        #define SHA1_DIGEST_SIZE 20

                        int SHA1_init(void **shaState);
                        int SHA1_destroy(void *shaState);
                        int SHA1_update(void *hs,
                                          const uint8_t *buf,
                                          size_t len);
                        int SHA1_digest(const void *shaState,
                                          uint8_t digest[SHA1_DIGEST_SIZE]);
                        int SHA1_copy(const void *src, void *dst);

                        int SHA1_pbkdf2_hmac_assist(const void *inner,
                                            const void *outer,
                                            const uint8_t first_digest[SHA1_DIGEST_SIZE],
                                            uint8_t final_digest[SHA1_DIGEST_SIZE],
                                            size_t iterations);
                        c                   @   sP   e Zd ZdZdZdZdZddd„Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zddd„ZdS )ÚSHA1Hasha˜  A SHA-1 hash object.
    Do not instantiate directly.
    Use the :func:`new` function.

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

    :ivar block_size: the size in bytes of the internal message block,
                      input to the compression function
    :vartype block_size: integer

    :ivar digest_size: the size in bytes of the resulting hash
    :vartype digest_size: integer
    é   é@   z1.3.14.3.2.26Nc                 C   sL   t ƒ }t | ¡ ¡}|rtd| ƒ‚t| ¡ tjƒ| _|r$|  	|¡ d S d S )Nú!Error %d while instantiating SHA1)
r   Ú_raw_sha1_libZ	SHA1_initZ
address_ofÚ
ValueErrorr   ÚgetZSHA1_destroyÚ_stateÚupdate)ÚselfÚdataÚstateÚresult© r   ú?/usr/local/lib/python3.10/dist-packages/Cryptodome/Hash/SHA1.pyÚ__init__H   s   ÿÿÿzSHA1Hash.__init__c                 C   s4   t  | j ¡ t|ƒtt|ƒƒ¡}|rtd| ƒ‚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.
        r   N)r   ZSHA1_updater   r   r	   r   Úlenr   )r   r   r   r   r   r   r   S   s   
þÿÿzSHA1Hash.updatec                 C   s4   t | jƒ}t | j ¡ |¡}|rtd| ƒ‚t|ƒ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
        r   )r   Údigest_sizer   ZSHA1_digestr   r   r   r   )r   Úbfrr   r   r   r   Údigesta   s   
ÿÿzSHA1Hash.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%02x)Zbord)Ú.0Úxr   r   r   Ú
<listcomp>z   s    z&SHA1Hash.hexdigest.<locals>.<listcomp>)Újoinr   )r   r   r   r   Ú	hexdigestr   s   zSHA1Hash.hexdigestc                 C   s2   t ƒ }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 SHA1)r
   r   Z	SHA1_copyr   r   r   )r   Úcloner   r   r   r   Úcopy|   s   ÿzSHA1Hash.copyc                 C   s   t |ƒS )z!Create a fresh SHA-1 hash object.)r
   )r   r   r   r   r   ÚnewŽ   s   zSHA1Hash.new©N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú
block_sizeÚoidr   r   r   r#   r%   r&   r   r   r   r   r
   1   s    

r
   Nc                 C   s   t ƒ  | ¡S )a  Create a new hash object.

    :parameter data:
        Optional. The very first chunk of the message to hash.
        It is equivalent to an early call to :meth:`SHA1Hash.update`.
    :type data: byte string/byte array/memoryview

    :Return: A :class:`SHA1Hash` hash object
    )r
   r&   )r   r   r   r   r&   ”   s   
r&   c                 C   s^   t |ƒtksJ ‚|dksJ ‚ttƒ}t | j ¡ |j ¡ ||t|ƒ¡}|r+td| ƒ‚t	|ƒS )z/Compute the expensive inner loop in PBKDF-HMAC.r   z(Error %d with PBKDF2-HMAC assis for SHA1)
r   r   r   r   ZSHA1_pbkdf2_hmac_assistr   r   r   r   r   )ÚinnerÚouterZfirst_digestZ
iterationsr   r   r   r   r   Ú_pbkdf2_hmac_assist¨   s   ûr0   r'   )ZCryptodome.Util.py3compatZCryptodome.Util._raw_apir   r   r   r   r   r   r	   r   Úobjectr
   r&   r   r,   r0   r   r   r   r   Ú<module>   s   $ÿ
c