U ��.e��@s�ddlmZddlZddlmZmZmZddlmZm Z m Z ddl m Z ddl mZer�ddlmZmZmZmZmZddlmZer�dd lmZn dd lmZd Zd d d gZGdd�de�ZGdd�de�ZdS)�)�absolute_importN)� iteritems�iterkeys� itervalues)� HashMismatch� HashMissing�InstallationError)� read_chunks)�MYPY_CHECK_RUNNING)�Dict�List�BinaryIO�NoReturn�Iterator)�PY3)�_Hash)�_hashZsha256Zsha384Zsha512c@s^eZdZdZddd�Zedd��Zdd�Zd d �Zd d �Z d d�Z dd�Z dd�Z dd�Z dS)�HasheszaA wrapper that builds multiple hashes at once and checks them against known-good values NcCs|dkr in||_dS)zo :param hashes: A dict of algorithm names pointing to lists of allowed hex digests N)�_allowed)�self�hashes�r�>/usr/lib/python3.8/site-packages/pip/_internal/utils/hashes.py�__init__,szHashes.__init__cCstdd�|j��D��S)Ncss|]}t|�VqdS�N)�len)�.0Zdigestsrrr� 7sz&Hashes.digest_count..)�sumr�values�rrrr� digest_count4szHashes.digest_countcCs||j�|g�kS)z/Return whether the given hex digest is allowed.)r�get)r� hash_nameZ hex_digestrrr�is_hash_allowed9szHashes.is_hash_allowedc Cs�i}t|j�D]<}zt�|�||<Wqttfk rHtd|��YqXq|D]}t|�D]}|�|�q\qPt |�D] \}}|� �|j|krvdSqv|� |�dS)z�Check good hashes against ones built from iterable of chunks of data. Raise HashMismatch if none match. zUnknown hash name: %sN) rr�hashlib�new� ValueError� TypeErrorrr�updater� hexdigest�_raise)rZchunks�gotsr#�chunk�hashZgotrrr�check_against_chunksAs zHashes.check_against_chunkscCst|j|��dSr)rr�rr,rrrr+Ysz Hashes._raisecCs|�t|��S)zaCheck good hashes against a file-like object Raise HashMismatch if none match. )r/r )r�filerrr�check_against_file]szHashes.check_against_filec Cs,t|d��}|�|�W5QR�SQRXdS)N�rb)�openr2)r�pathr1rrr�check_against_pathfs zHashes.check_against_pathcCs t|j�S)z,Return whether I know any known-good hashes.)�boolrr rrr� __nonzero__kszHashes.__nonzero__cCs|��Sr)r8r rrr�__bool__pszHashes.__bool__)N)�__name__� __module__� __qualname__�__doc__r�propertyr!r$r/r+r2r6r8r9rrrrr's   rcs(eZdZdZ�fdd�Zdd�Z�ZS)� MissingHashesz�A workalike for Hashes used when we're missing a hash for a requirement It computes the actual hash of the requirement and raises a HashMissing exception showing it to the user. cstt|�jtgid�dS)z!Don't offer the ``hashes`` kwarg.)rN)�superr?r� FAVORITE_HASHr �� __class__rrr|szMissingHashes.__init__cCst|t����dSr)rrAr*r0rrrr+�szMissingHashes._raise)r:r;r<r=rr+� __classcell__rrrBrr?us r?)Z __future__rr%Zpip._vendor.sixrrrZpip._internal.exceptionsrrrZpip._internal.utils.miscr Zpip._internal.utils.typingr �typingr r r rrrrrrAZ STRONG_HASHES�objectrr?rrrr�s      N