o
    ™¨Êhl  ã                   @   st   d dl mZmZmZ d dlmZ d dlmZmZm	Z	 d dl
mZmZmZ e ej¡e ej¡G dd„ deƒƒƒZdS )é    )Úabsolute_importÚdivisionÚprint_function)Úutils)ÚInvalidSignatureÚUnsupportedAlgorithmÚ_Reasons)Úconstant_timeÚhashesÚmacc                   @   s@   e Zd Zddd„Ze d¡Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dS )Ú_HMACContextNc                 C   sº   || _ || _|d u rU| jj ¡ }| j || jjjk¡ | jj || jjj¡}| j 	|¡}|| jjjkr=t
d |j¡tjƒ‚| jj ||t|ƒ|| jjj¡}| j |dk¡ || _|| _d S )Nz+{0} is not a supported hash on this backendr   )Ú
_algorithmÚ_backendÚ_libÚCryptography_HMAC_CTX_newÚopenssl_assertÚ_ffiÚNULLÚgcÚCryptography_HMAC_CTX_freeÚ_evp_md_from_algorithmr   ÚformatÚnamer   ÚUNSUPPORTED_HASHÚHMAC_Init_exÚlenÚ_ctxÚ_key)ÚselfÚbackendÚkeyÚ	algorithmÚctxÚevp_mdÚres© r%   ú[/var/www/html/env/lib/python3.10/site-packages/cryptography/hazmat/backends/openssl/hmac.pyÚ__init__   s,   
ÿÿýÿ
z_HMACContext.__init__r   c                 C   sp   | j j ¡ }| j  || j jjk¡ | j j || j jj¡}| j j || j	¡}| j  |dk¡ t
| j | j| j|d�S )Nr   )r"   )r   r   r   r   r   r   r   r   ÚHMAC_CTX_copyr   r   r   r!   )r   Ú
copied_ctxr$   r%   r%   r&   Úcopy-   s   
ÿÿz_HMACContext.copyc                 C   s,   | j j | j|t|ƒ¡}| j  |dk¡ d S )Nr   )r   r   ÚHMAC_Updater   r   r   )r   Údatar$   r%   r%   r&   Úupdate9   s   z_HMACContext.updatec                 C   sz   | j j d| j jj¡}| j j d¡}| j j | j||¡}| j  |dk¡ | j  |d | jj	k¡ | j j 
|¡d |d … S )Nzunsigned char[]zunsigned int *r   )r   r   Únewr   ÚEVP_MAX_MD_SIZEÚ
HMAC_Finalr   r   r!   Údigest_sizeÚbuffer)r   ÚbufÚoutlenr$   r%   r%   r&   Úfinalize=   s   
ÿz_HMACContext.finalizec                 C   s    |   ¡ }t ||¡stdƒ‚d S )NzSignature did not match digest.)r5   r	   Úbytes_eqr   )r   Ú	signatureÚdigestr%   r%   r&   ÚverifyF   s   ÿz_HMACContext.verify)N)Ú__name__Ú
__module__Ú__qualname__r'   r   Úread_only_propertyr!   r*   r-   r5   r9   r%   r%   r%   r&   r      s    

	r   N)Ú
__future__r   r   r   Úcryptographyr   Úcryptography.exceptionsr   r   r   Úcryptography.hazmat.primitivesr	   r
   r   Úregister_interfaceÚ
MACContextÚHashContextÚobjectr   r%   r%   r%   r&   Ú<module>   s   

