File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/hashutil.cpython-310.pyc
o
�N�g� � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddl Zd dd�Z
d dd�Zdd � Zd
d� Z
dd
� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� ZdS )!z0
A collection of hashing and encoding functions
� N�md5c C sF t d t d t d d�}|�|�}|du rtj�d|� d���|| �S )a%
Return a checksum digest for a string
instr
A string
checksum : ``md5``
The hashing algorithm to use to generate checksums. Valid options: md5,
sha256, sha512.
CLI Example:
.. code-block:: bash
salt '*' hashutil.digest 'get salted'
zhashutil.md5_digestzhashutil.sha256_digestzhashutil.sha512_digest)r �sha256�sha512NzHash func 'z' is not supported.)�__salt__�get�salt�
exceptions�CommandExecutionError)�instr�checksumZ
hashing_funcsZ hash_func� r �I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/hashutil.py�digest s �
�r c C sh t d | �stj�d| � d���tjj�| d��}t d |�� |�}W d � |S 1 s-w Y |S )ai
Return a checksum digest for a file
infile
A file path
checksum : ``md5``
The hashing algorithm to use to generate checksums. Wraps the
:py:func:`hashutil.digest <salt.modules.hashutil.digest>` execution
function.
CLI Example:
.. code-block:: bash
salt '*' hashutil.digest_file /path/to/file
zfile.file_existszFile path 'z' not found.�rbzhashutil.digestN)r r r r �utils�files�fopen�read)Zinfiler �fZ file_hashr r r
�digest_file/ s
��r c C � t jj�| �S )aO
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.
.. versionadded:: 2016.3.0
CLI Example:
.. code-block:: bash
salt '*' hashutil.base64_b64encode 'get salted'
)r r � hashutils�base64_b64encode�r
r r r
r I s r c C r )z�
Decode a base64-encoded string using the "modern" Python interface
.. versionadded:: 2016.3.0
CLI Example:
.. code-block:: bash
salt '*' hashutil.base64_b64decode 'Z2V0IHNhbHRlZA=='
)r r r �base64_b64decoder r r r
r [ � r c C r )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 byte-like object.
.. versionadded:: 3000
CLI Example:
.. code-block:: bash
salt '*' hashutil.base64_encodestring 'get salted'
)r r r �base64_encodestringr r r r
r j s r c C s` t �� }tjj�| d��}t�||� W d � n1 sw Y |�d� tjj �
|�� �S )a
Read a file from the file system and return as a base64 encoded string
.. versionadded:: 2016.3.0
Pillar example:
.. code-block:: yaml
path:
to:
data: |
{{ salt.hashutil.base64_encodefile('/path/to/binary_file') | indent(6) }}
The :py:func:`file.decode <salt.states.file.decode>` state function can be
used to decode this data and write it to disk.
CLI Example:
.. code-block:: bash
salt '*' hashutil.base64_encodefile /path/to/binary_file
r Nr )�io�BytesIOr r r r �base64�encode�seek�stringutilsZto_strr )�fname� encoded_fr r r r
�base64_encodefile} s �
r% c C r )z�
Decode a base64-encoded byte-like object using the "modern" Python interface
.. versionadded:: 3000
CLI Example:
.. code-block:: bash
salt '*' hashutil.base64_decodestring instr='Z2V0IHNhbHRlZAo='
)r r r �base64_decodestringr r r r
r&