o
    Ìn~bý  ã                   @   sl   d dl mZ 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 )é    ©Úbord)Úload_pycryptodome_raw_libÚVoidPointerÚSmartPointerÚcreate_string_bufferÚget_raw_bufferÚc_size_tÚc_uint8_ptrzCryptodome.Hash._SHA256aÌ  
                        int SHA256_init(void **shaState);
                        int SHA256_destroy(void *shaState);
                        int SHA256_update(void *hs,
                                          const uint8_t *buf,
                                          size_t len);
                        int SHA256_digest(const void *shaState,
                                          uint8_t *digest,
                                          size_t digest_size);
                        int SHA256_copy(const void *src, void *dst);

                        int SHA256_pbkdf2_hmac_assist(const void *inner,
                                            const void *outer,
                                            const uint8_t *first_digest,
                                            uint8_t *final_digest,
                                            size_t iterations,
                                            size_t digest_size);
                        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 )Ú
SHA256Hasha–  A SHA-256 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2.16.840.1.101.3.4.2.1Nc                 C   sL   t ƒ }t | ¡ ¡}|rtd| ƒ‚t| ¡ tjƒ| _|r$|  	|¡ d S d S )Nz#Error %d while instantiating SHA256)
r   Ú_raw_sha256_libZSHA256_initZ
address_ofÚ
ValueErrorr   ÚgetZSHA256_destroyÚ_stateÚupdate)ÚselfÚdataÚstateÚresult© r   úA/usr/local/lib/python3.10/dist-packages/Cryptodome/Hash/SHA256.pyÚ__init__G   s   ÿÿÿzSHA256Hash.__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.
        z'Error %d while hashing data with SHA256N)r   ZSHA256_updater   r   r
   r	   Úlenr   )r   r   r   r   r   r   r   R   s   
þÿÿzSHA256Hash.updatec                 C   s<   t | jƒ}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
        z#Error %d while making SHA256 digest)	r   Údigest_sizer   ZSHA256_digestr   r   r	   r   r   )r   Úbfrr   r   r   r   Údigest`   s   
þÿzSHA256Hash.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>z   s    z(SHA256Hash.hexdigest.<locals>.<listcomp>)Újoinr   )r   r   r   r   Ú	hexdigestr   s   zSHA256Hash.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 SHA256)r   r   ZSHA256_copyr   r   r   )r   Úcloner   r   r   r   Úcopy|   s   ÿzSHA256Hash.copyc                 C   s   t |ƒS )z#Create a fresh SHA-256 hash object.)r   )r   r   r   r   r   ÚnewŽ   s   zSHA256Hash.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:`SHA256Hash.update`.
    :type data: byte string/byte array/memoryview

    :Return: A :class:`SHA256Hash` hash object
    )r   r&   )r   r   r   r   r&   “   s   r&   c              
   C   s\   |dksJ ‚t t|ƒƒ}t | j ¡ |j ¡ ||t|ƒtt|ƒƒ¡}|r*td| ƒ‚t|ƒS )z/Compute the expensive inner loop in PBKDF-HMAC.r   z+Error %d with PBKDF2-HMAC assist for SHA256)	r   r   r   ZSHA256_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.py3compatr   ZCryptodome.Util._raw_apir   r   r   r   r   r	   r
   r   Úobjectr   r&   r   r,   r0   r   r   r   r   Ú<module>   s   $ÿ
b