o
    �)%a	  ã                   @   sZ   d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ G dd„ dejƒZdS )	é    )Úutils)ÚAlreadyFinalizedÚUnsupportedAlgorithmÚ_Reasons)Ú_get_backend)ÚHMACBackend)Úhashesc                   @   sl   e Zd Z		ddedejfdd„Ze d¡Z	deddfd	d
„Z
ddd„Zdefdd„Zdeddfdd„ZdS )ÚHMACNÚkeyÚ	algorithmc                 C   sl   t |ƒ}t|tƒstdtjƒ‚t|tjƒstdƒ‚|| _	|| _
|| _|d u r1| j
 || j¡| _d S || _d S )Nz.Backend object does not implement HMACBackend.z*Expected instance of hashes.HashAlgorithm.)r   Ú
isinstancer   r   r   ÚBACKEND_MISSING_INTERFACEr   ÚHashAlgorithmÚ	TypeErrorÚ
_algorithmÚ_backendÚ_keyÚcreate_hmac_ctxr   Ú_ctx)Úselfr
   r   ÚbackendÚctx© r   úE/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/hmac.pyÚ__init__   s   
þ
zHMAC.__init__r   ÚdataÚreturnc                 C   s.   | j d u r	tdƒ‚t d|¡ | j  |¡ d S )NúContext was already finalized.r   )r   r   r   Ú_check_byteslikeÚupdate)r   r   r   r   r   r   -   s   
zHMAC.updatec                 C   s.   | j d u r	tdƒ‚t| j| j| j| j  ¡ d�S )Nr   )r   r   )r   r   r	   r   r   r   Úcopy)r   r   r   r   r    3   s   
üz	HMAC.copyc                 C   s&   | j d u r	tdƒ‚| j  ¡ }d | _ |S )Nr   )r   r   Úfinalize)r   Údigestr   r   r   r!   =   s
   

zHMAC.finalizeÚ	signaturec                 C   s:   t  d|¡ | jd u rtdƒ‚| jd }| _| |¡ d S )Nr#   r   )r   Ú_check_bytesr   r   Úverify)r   r#   r   r   r   r   r%   D   s
   
zHMAC.verify)NN)r   r	   )Ú__name__Ú
__module__Ú__qualname__Úbytesr   r   r   r   Úread_only_propertyr   r   r    r!   r%   r   r   r   r   r	      s    ûþ
ý


r	   N)Úcryptographyr   Úcryptography.exceptionsr   r   r   Úcryptography.hazmat.backendsr   Ú'cryptography.hazmat.backends.interfacesr   Úcryptography.hazmat.primitivesr   ÚHashContextr	   r   r   r   r   Ú<module>   s   