Your IP : 3.147.84.123


Current Path : /lib64/python3.6/__pycache__/
Upload File :
Current File : //lib64/python3.6/__pycache__/hmac.cpython-36.pyc

3

�me��@s�dZddlZddlmZddlZddlZddl	Z	e
dd�ed�D��Ze
dd�ed�D��Z
dZGdd	�d	�Zd
d�ZGdd
�d
e	j�Zej�r�eZddd�ZdS)zxHMAC (Keyed-Hashing for Message Authentication) Python module.

Implements the HMAC algorithm as described by RFC 2104.
�N)�_compare_digestccs|]}|dAVqdS)�\N�)�.0�xrr�/usr/lib64/python3.6/hmac.py�	<genexpr>sr�ccs|]}|dAVqdS)�6Nr)rrrrrr
sc@sReZdZdZdZddd�Zedd��Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�ZdS)�HMACz~RFC 2104 HMAC class.  Also complies with RFC 4231.

    This supports the API for Cryptographic Hash Functions (PEP 247).
    �@Ncsftj�rtd��t|ttf�s0tdt|�j���dkrLt	j
dtd�tj
�t��r\�|_n,t�t�rxd�fdd	�	|_nd�fd
d	�	|_|j�|_|j�|_|jj|_t|jd�r�|jj}|dkr�t	j
d
||jftd�|j}nt	j
d|jtd�|j}||_t|�|k�r|j|�j�}|j|d�}|jj|jt��|jj|jt��|dk	�rb|j|�dS)a1Create a new HMAC object.

        key:       key for the keyed hash object.
        msg:       Initial input for the hash, if provided.
        digestmod: A module supporting PEP 247.  *OR*
                   A hashlib constructor returning a new hash object. *OR*
                   A hash name suitable for hashlib.new().
                   Defaults to hashlib.md5.
                   Implicit default to hashlib.md5 is deprecated and will be
                   removed in Python 3.6.

        Note: key and msg must be a bytes or bytearray objects.
        z*This class is not available in FIPS mode. zUse hmac.new().z,key: expected bytes or bytearray, but got %rNz<HMAC() without an explicit digestmod argument is deprecated.��cstj�|�S)N)�_hashlib�new)�d)�	digestmodrr�<lambda>;szHMAC.__init__.<locals>.<lambda>cs
�j|�S)N)r)r)rrrr=s�
block_size�z:block_size of %d seems too small; using our default of %d.z<No block_size attribute on given digest object; Assuming %d.�z9This class is not available in FIPS mode. Use hmac.new().)r)r)�_hashlibopenssl�
get_fips_mode�
ValueError�
isinstance�bytes�	bytearray�	TypeError�type�__name__�	_warnings�warn�PendingDeprecationWarningrZmd5�callable�digest_cons�str�outer�inner�digest_size�hasattrr�	blocksize�RuntimeWarning�len�digest�ljust�update�	translate�trans_5C�trans_36)�self�key�msgrr*r)rr�__init__sJ





z
HMAC.__init__cCsd|jjS)Nzhmac-)r'�name)r3rrrr7]sz	HMAC.namecCs tj�rtd��|jj|�dS)z8Update this hashing object with the string msg.
        z'hmac.HMAC is not available in FIPS modeN)rrrr'r/)r3r5rrrr/aszHMAC.updatecCs:|jj|j�}|j|_|j|_|jj�|_|jj�|_|S)zyReturn a separate copy of this hashing object.

        An update to this copy won't affect the original object.
        )�	__class__�__new__r$r(r'�copyr&)r3�otherrrrr:hsz	HMAC.copycCs|jj�}|j|jj��|S)zwReturn a hash object for the current state.

        To be used only internally with digest() and hexdigest().
        )r&r:r/r'r-)r3�hrrr�_currentus
z
HMAC._currentcCs|j�}|j�S)z�Return the hash value of this hashing object.

        This returns a string containing 8-bit data.  The object is
        not altered in any way by this function; you can continue
        updating the object after calling this function.
        )r=r-)r3r<rrrr-~szHMAC.digestcCs|j�}|j�S)zKLike digest(), but returns a string of hexadecimal digits instead.
        )r=�	hexdigest)r3r<rrrr>�szHMAC.hexdigest)NN)
r�
__module__�__qualname__�__doc__r*r6�propertyr7r/r:r=r-r>rrrrrs
A
	
rcCsX|dkrtd��t|t�r"|j�St|�r2|d�}t|tj�sFtd��|jj�j	dd�S)Nz.'digestmod' argument is mandatory in FIPS moderz6Only OpenSSL hashlib hashes are accepted in FIPS mode.�_�-)
rrr%�lowerr#rZHASHrr7�replace)rrrr�_get_openssl_name�s
rGc@seZdZddd�ZdS)�HMAC_opensslNcCsLt|ttf�s tdt|�j��t|�}tjj	|||d�}|rH|j
|�|S)Nz,key: expected bytes or bytearray, but got %r)r)rrrrrrrG�_hmacopensslrr9r/)�clsr4r5rr7�resultrrrr9�s
zHMAC_openssl.__new__)NN)rr?r@r9rrrrrH�srHcCst|||�S)aVCreate a new hashing object and return it.

    key: The starting key for the hash.
    msg: if available, will immediately be hashed into the object's starting
    state.

    You can now feed arbitrary strings into the object using its update()
    method, and can ask for the hash value at any time by calling its digest()
    method.
    )r)r4r5rrrrr�sr)NN)rA�warningsr �	_operatorrZcompare_digestZhashlibrrrIr�ranger1r2r(rrGrHrrrrrr�<module>sz