%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/hashutils.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
mZddlZ
ddlZ
ddlZ
ddlmZed�d��Zed�d	��Zd
�Zd�Zed�d
��Zd�Zed�d��Zed�d��Zed�d��Zed�ed�ddd���Zed�ddd��Zdefd��YZdS(u-
A collection of hashing and encoding utils.
i(tabsolute_importtunicode_literalstprint_functionN(tsix(tjinja_filteru
base64_encodecC@sItjjjtjtjjj|��dtjjj�rBdnd�S(u�
    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.
    tencodinguutf8N(
tsalttutilststringutilst
to_unicodetbase64t	b64encodetto_bytestplatformt
is_windowstNone(tinstr((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pytbase64_b64encodesu
base64_decodecC@sltjtjjj|��}y5tjjj|dtjjj�rKdnd�SWnt
k
rg|SXdS(uM
    Decode a base64-encoded string using the "modern" Python interface.
    Ruutf8N(R
t	b64decodeRRRRR	R
RRtUnicodeDecodeError(Rtdecoded((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pytbase64_b64decode%s#
cC@sItjjjtjtjjj|��dtjjj�rBdnd�S(u�
    Encode a string as base64 using the "legacy" Python interface.

    Among other possible differences, the "legacy" encoder includes
    a newline ('\n') character after every 76 characters and always
    at the end of the encoded string.
    Ruutf8N(
RRRR	R
tencodestringRR
RR(R((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pytbase64_encodestring4scC@s�tjjj|�}ytj|�}Wn tk
rJtj|�}nXy5tjjj|dtjj	j
�rxdnd�SWntk
r�|SXdS(uM
    Decode a base64-encoded string using the "legacy" Python interface.
    Ruutf8N(
RRRRR
tdecodebytestAttributeErrortdecodestringR	R
RRR(RtbR((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pytbase64_decodestringBs
#
umd5cC@s1tjjjtjtjjj|��j��S(u1
    Generate an md5 hash of a given string.
    (RRRR	thashlibtmd5Rt	hexdigest(R((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt
md5_digestVscC@sDtjr1tjjj|�}tj|�j�Stj|�j�S(u2
    Generate an sha1 hash of a given string.
    (	RtPY3RRRRRtsha1R(RR((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pytsha1_digest`s	usha256cC@s1tjjjtjtjjj|��j��S(u3
    Generate a sha256 hash of a given string.
    (RRRR	Rtsha256RR(R((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt
sha256_digestjsusha512cC@s1tjjjtjtjjj|��j��S(u2
    Generate a sha512 hash of a given string
    (RRRR	Rtsha512RR(R((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt
sha512_digesttsuhmaccC@svtjjj|�}tjjj|�}tjjj|�}tj||tj�}tj	|j
��}||kS(u�
    Verify a challenging hmac signature against a string / shared-secret
    Returns a boolean if the verification succeeded or failed.
    (RRRRthmactnewRR$R
Rtdigest(tstringt
shared_secrettchallenge_hmactmsgtkeyt	challenget	hmac_hasht
valid_hmac((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pythmac_signature~surand_strurandom_hashI��TcC@sX|sd}ntt|�}|tjjjtjtj	�j
d|����j�S(uG
    Return a hash of a randomized data from random.SystemRandom()
    umd5i(tgetattrRRRRRRt	text_typetrandomtSystemRandomtrandintR(tsizet	hash_typethasher((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pytrandom_hash�s	ufile_hashsumic	@s�tt|�rtt|�p!d}|dkrHtdj|���ntjjj	|d��M�|�}x0t
��fd�d�D]}|j|�q�W|j�SWdQXdS(uy
    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'``
    uInvalid hash type: {0}urbc@s
�j��S(N(tread((t
chunk_sizetifile(s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt<lambda>�stN(
thasattrRR4Rt
ValueErrortformatRRtfilestfopentitertupdateR(tpathtformR>R:thash_objtchunk((R>R?s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pytget_hash�s$	"tDigestCollectorcB@s/eZdZddd�Zd�Zd�ZRS(u3
    Class to collect digest of the file tree.
    usha256icC@s^tt|�r!tt|��p$d|_|jdkrQtdj|���n||_dS(u@
        Constructor of the class.
        :param form:
        uInvalid hash type: {0}N(RBRR4Rt_DigestCollector__digestRCRDt_DigestCollector__buff(tselfRJtbuff((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt__init__�s*c@s[tjjj|d��=�x3t��fd�d�D]}�jj|�q7WWdQXdS(ue
        Update digest with the file content by path.

        :param path:
        :return:
        urbc@s�j�j�S(N(R=RP((R?RQ(s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pyR@�sRAN(RRRERFRGRORH(RQRIRL((R?RQs8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pytadd�s"cC@s#tjjj|jj�tj�S(u/
        Get digest.

        :return:
        (RRRtto_strRORtostlinesep(RQ((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pyR*�s(t__name__t
__module__t__doc__RSRTR*(((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pyRN�s
	( RZt
__future__RRRR
RR(R6RVtsalt.extRtsalt.utils.filesRtsalt.utils.platformtsalt.utils.stringutilstsalt.utils.decorators.jinjaRRRRRR R#R%R'R3RR<RMtobjectRN(((s8/usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt<module>s4		
	


		
	

Zerion Mini Shell 1.0