%PDF- %PDF-
| Direktori : /proc/thread-self/root/proc/3522530/root/lib/python2.7/site-packages/salt/utils/ |
| Current File : //proc/thread-self/root/proc/3522530/root/lib/python2.7/site-packages/salt/utils/hashutils.pyc |
�
���^c @@ s� d Z d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l
m Z d d l Z
d d l Z
d d l Z
d d l m Z e d � d � � Z e d � d � � Z d
� Z d � Z e d � d
� � Z d � Z e d � d � � Z e d � d � � Z e d � d � � Z e d � e d � d d d � � � Z e d � d d d � � Z d e f d � � YZ d S( u-
A collection of hashing and encoding utils.
i ( t absolute_importt unicode_literalst print_functionN( t six( t jinja_filteru
base64_encodec C@ sI t j j j t j t j j j | � � d t j j j � rB d n d �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.
t encodingu utf8N(
t saltt utilst stringutilst
to_unicodet base64t b64encodet to_bytest platformt
is_windowst None( t instr( ( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt base64_b64encode s u
base64_decodec C@ sl t j t j j j | � � } y5 t j j j | d t j j j � rK d n d �SWn t
k
rg | SXd S( uM
Decode a base64-encoded string using the "modern" Python interface.
R u utf8N( R
t b64decodeR R R R R R
R R t UnicodeDecodeError( R t decoded( ( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt base64_b64decode% s #
c C@ sI t j j j t j t j j j | � � d t j j j � rB d n d �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.
R u utf8N(
R R R R R
t encodestringR R
R R ( R ( ( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt base64_encodestring4 s c C@ s� t j j j | � } y t j | � } Wn t k
rJ t j | � } n Xy5 t j j j | d t j j j
� rx d n d �SWn t k
r� | SXd S( uM
Decode a base64-encoded string using the "legacy" Python interface.
R u utf8N(
R R R R R
t decodebytest AttributeErrort decodestringR R
R R R ( R t bR ( ( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt base64_decodestringB s
#
u md5c C@ s1 t j j j t j t j j j | � � j � � S( u1
Generate an md5 hash of a given string.
( R R R R t hashlibt md5R t hexdigest( R ( ( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt
md5_digestV s c C@ sD t j r1 t j j j | � } t j | � j � St j | � j � S( u2
Generate an sha1 hash of a given string.
( R t PY3R R R R R t sha1R ( R R ( ( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt sha1_digest` s u sha256c C@ s1 t j j j t j t j j j | � � j � � S( u3
Generate a sha256 hash of a given string.
( R R R R R t sha256R R ( R ( ( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt
sha256_digestj s u sha512c C@ s1 t j j j t j t j j j | � � j � � S( u2
Generate a sha512 hash of a given string
( R R R R R t sha512R R ( R ( ( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt
sha512_digestt s u hmacc C@ sv t j j j | � } t j j j | � } t j j j | � } t j | | t j � } t j | j
� � } | | k S( u�
Verify a challenging hmac signature against a string / shared-secret
Returns a boolean if the verification succeeded or failed.
( R R R R t hmact newR R$ R
R t digest( t stringt
shared_secrett challenge_hmact msgt keyt challenget hmac_hasht
valid_hmac( ( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt hmac_signature~ s u rand_stru random_hashI��T c C@ sX | s d } n t t | � } | t j j j t j t j � j
d | � � � � j � S( uG
Return a hash of a randomized data from random.SystemRandom()
u md5i ( t getattrR R R R R R t text_typet randomt SystemRandomt randintR ( t sizet hash_typet hasher( ( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt random_hash� s u file_hashsumi c @ s� t t | � r t t | � p! d } | d k rH t d j | � � � n t j j j | d � �M � | � } x0 t
� � f d � d � D] } | j | � q� W| j � SWd QXd S( 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'``
u Invalid hash type: {0}u rbc @ s
� j � � S( N( t read( ( t
chunk_sizet ifile( s8 /usr/lib/python2.7/site-packages/salt/utils/hashutils.pyt <lambda>� s t N(
t hasattrR R4 R t
ValueErrort formatR R t filest fopent itert updateR ( t patht formR>