3 y�_a �@s\ddlmZmZmZddlmZddlmZmZddl m Z ej e j �Gdd�de ��ZdS)�)�absolute_import�division�print_function)�utils)�UnsupportedAlgorithm�_Reasons)�hashesc@s@eZdZd dd�Zejd�Zdd�Zdd�Zd d �Z d d �Z dS)� _HashContextNcCs�||_||_|dkr�|jjj�}|jjj||jjj�}|jj|�}||jjjkrdt dj |j �t j ��|jjj|||jjj�}|jj|dk�||_dS)Nz+{} is not a supported hash on this backend.r)� _algorithm�_backend�_lib�Cryptography_EVP_MD_CTX_new�_ffi�gc�Cryptography_EVP_MD_CTX_freeZ_evp_md_from_algorithmZNULLr�format�namerZUNSUPPORTED_HASHZEVP_DigestInit_ex�openssl_assert�_ctx)�selfZbackend� algorithm�ctxZevp_md�res�r�/usr/lib64/python3.6/hashes.py�__init__s   z_HashContext.__init__r cCsV|jjj�}|jjj||jjj�}|jjj||j�}|jj|dk�t |j|j |d�S)Nr)r) r r r rrrZEVP_MD_CTX_copy_exrrr r)rZ copied_ctxrrrr�copy*s  z_HashContext.copycCs:|jjj|�}|jjj|j|t|��}|jj|dk�dS)Nr)r rZ from_bufferr ZEVP_DigestUpdater�lenr)r�dataZdata_ptrrrrr�update3sz_HashContext.updatecCs�t|jtj�r|j�S|jjjd|jjj �}|jjjd�}|jjj |j ||�}|jj |dk�|jj |d|jj k�|jjj|�d|d�SdS)Nzunsigned char[]zunsigned int *r)� isinstancerrZExtendableOutputFunction� _finalize_xofr r�newr ZEVP_MAX_MD_SIZEZEVP_DigestFinal_exrr� digest_size�buffer)r�bufZoutlenrrrr�finalize:sz_HashContext.finalizecCsV|jjjd|jj�}|jjj|j||jj�}|jj|dk�|jjj |�d|jj�S)Nzunsigned char[]r) r rr"rr#r ZEVP_DigestFinalXOFrrr$)rr%rrrrr!Js  z_HashContext._finalize_xof)N) �__name__� __module__� __qualname__rrZread_only_propertyrrrr&r!rrrrr s    r N)Z __future__rrrZ cryptographyrZcryptography.exceptionsrrZcryptography.hazmat.primitivesrZregister_interfaceZ HashContext�objectr rrrr�s