HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/hashutils.cpython-310.pyc
o

�N�g��@sdZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
mZed�dd��Zed�dd	��Z
d
d�Zdd
�Zed�dd��Zed�dd��Zed�dd��Zed�dd��Zed�dd��Zed�dd��Zed�ed �d)d"d ���Zed#�d*d%d&��ZGd'd(�d(�ZdS)+z-
A collection of hashing and encoding utils.
�N)�jinja_filterZ
base64_encodecC�6tjjjt�tjj�|��tjj��rdd�Sdd�S)z�
    Encode a string as base64 using the "modern" Python interface.

    Among other possible differences, the "modern" encoder does not include
    newline ('\n') characters in the encoded output.
    �utf8N��encoding)	�salt�utils�stringutils�
to_unicode�base64�	b64encode�to_bytes�platform�
is_windows��instr�r�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/hashutils.py�base64_b64encode���rZ
base64_decodecCsVt�tjj�|��}ztjjj|tjj��rdd�WSdd�WSt	y*|YSw)zM
    Decode a base64-encoded string using the "modern" Python interface.
    rNr)
r�	b64decoderrr	r
r
rr�UnicodeDecodeError)r�decodedrrr�base64_b64decodes���rcCr)a
    Encode a byte-like object as base64 using the "modern" Python interface.

    Among other possible differences, the "modern" encoder includes
    a newline ('\n') character after every 76 characters and always
    at the end of the encoded string.
    rNr)	rrr	r
r�encodebytesr
rrrrrr�base64_encodestring-rrcCsZtjj�|�}t�|�}ztjjj|tjj��rdd�WSdd�WSt	y,|YSw)zW
    Decode a base64-encoded byte-like object using the "modern" Python interface.
    rNr)
rrr	r
r�decodebytesr
rrr)rZbvaluerrrr�base64_decodestring;s
���r�md5cC�"tjj�t�tjj�|�����S)z1
    Generate an md5 hash of a given string.
    )rrr	r
�hashlibrr
�	hexdigestrrrr�
md5_digestI��r"�sha1cCst�tjj�|����S)z2
    Generate an sha1 hash of a given string.
    )r r$rrr	r
r!rrrr�sha1_digestSsr%�sha256cCr)z3
    Generate a sha256 hash of a given string.
    )rrr	r
r r&r
r!rrrr�
sha256_digest[r#r'�sha512cCr)z2
    Generate a sha512 hash of a given string
    )rrr	r
r r(r
r!rrrr�
sha512_digester#r)�hmaccCsPtjj�|�}tjj�|�}tjj�|�}t�||tj�}t�	|�
��}||kS)z�
    Verify a challenging hmac signature against a string / shared-secret
    Returns a boolean if the verification succeeded or failed.
    )rrr	r
r*�newr r&rr�digest)�string�
shared_secretZchallenge_hmac�msg�keyZ	challenge�	hmac_hashZ
valid_hmacrrr�hmac_signatureosr2�hmac_computecCs4tjj�|�}tjj�|�}t�||tj���}|S)z 
    Create an hmac digest.
    )	rrr	r
r*r+r r&r!)r-r.r/r0r1rrrr3}sZrand_str�random_hash��c(	cCs8|sd}tt|�}|tjj�tt���	d|�����
�S)zG
    Return a hash of a randomized data from random.SystemRandom()
    rr)�getattrr rrr	r
�str�random�SystemRandom�randintr!)�size�	hash_typeZhasherrrrr4�s
��Zfile_hashsum�cs�tt|�r
tt|�pd}|durtd|����tjj�|d��!�|�}t��fdd�d�D]}|�	|�q-|�
�Wd�S1sCwYdS)ay
    Get the hash sum of a file

    This is better than ``get_sum`` for the following reasons:
        - It does not read the entire file into memory.
        - It does not return a string on error. The returned value of
            ``get_sum`` cannot really be trusted since it is vulnerable to
            collisions: ``get_sum(..., 'xyz') == 'Hash xyz not supported'``
    N�Invalid hash type: �rbcs
����S�N)�readr��
chunk_size�ifilerr�<lambda>�s
zget_hash.<locals>.<lambda>�)�hasattrr r6�
ValueErrorrr�files�fopen�iter�updater!)�path�formrCr<Zhash_obj�chunkrrBr�get_hash�s$�rPc@s*eZdZdZddd�Zdd�Zdd	�Zd
S)�DigestCollectorz3
    Class to collect digest of the file tree.
    r&r=cCs>tt|�rtt|��pd|_|jdurtd|����||_dS)z@
        Constructor of the class.
        :param form:
        Nr>)rGr r6�_DigestCollector__digestrH�_DigestCollector__buff)�selfrNZbuffrrr�__init__�s

zDigestCollector.__init__cs\tjj�|d���t��fdd�d�D]}�j�|�qWd�dS1s'wYdS)ze
        Update digest with the file content by path.

        :param path:
        :return:
        r?cs���j�Sr@)rArSr�rDrTrrrE�sz%DigestCollector.add.<locals>.<lambda>rFN)rrrIrJrKrRrL)rTrMrOrrVr�add�s
�"�zDigestCollector.addcCstjj�|j��tj�S)z/
        Get digest.

        :return:
        )rrr	Zto_strrRr!�os�linesep)rTrrrr,�szDigestCollector.digestN�r&r=)�__name__�
__module__�__qualname__�__doc__rUrWr,rrrrrQ�s


rQ)r5NrZ)r^rr r*rXr8Zsalt.utils.filesrZsalt.utils.platformZsalt.utils.stringutilsZsalt.utils.decorators.jinjarrrrrr"r%r'r)r2r3r4rPrQrrrr�<module>sD