3 y_a @s\ddlmZmZmZddlmZddlmZmZddl m Z ej e j Gddde ZdS))absolute_importdivisionprint_function)utils)UnsupportedAlgorithm_Reasons)hashesc@s@eZdZd ddZejdZddZddZd 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_libCryptography_EVP_MD_CTX_new_ffigcCryptography_EVP_MD_CTX_freeZ_evp_md_from_algorithmZNULLrformatnamerZUNSUPPORTED_HASHZEVP_DigestInit_exopenssl_assert_ctx)selfZbackend algorithmctxZevp_mdresr/usr/lib64/python3.6/hashes.py__init__s   z_HashContext.__init__r cCsV|jjj}|jjj||jjj}|jjj||j}|jj|dkt |j|j |dS)Nr)r) r r r rrrZEVP_MD_CTX_copy_exrrr r)rZ copied_ctxrrrrcopy*s  z_HashContext.copycCs:|jjj|}|jjj|j|t|}|jj|dkdS)Nr)r rZ from_bufferr ZEVP_DigestUpdaterlenr)rdataZdata_ptrrrrrupdate3sz_HashContext.updatecCst|jtjr|jS|jjjd|jjj }|jjjd}|jjj |j ||}|jj |dk|jj |d|jj k|jjj|d|dSdS)Nzunsigned char[]zunsigned int *r) isinstancerrZExtendableOutputFunction _finalize_xofr rnewr ZEVP_MAX_MD_SIZEZEVP_DigestFinal_exrr digest_sizebuffer)rbufZoutlenrrrrfinalize:sz_HashContext.finalizecCsV|jjjd|jj}|jjj|j||jj}|jj|dk|jjj |d|jjS)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 HashContextobjectr rrrrs