o
    �)%an  ã                   @   sX   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ƒZdS )	é    )Úutils)ÚAlreadyFinalizedÚUnsupportedAlgorithmÚ_Reasons)Ú_get_backend)ÚCMACBackend)Úciphersc                   @   s\   e Zd Z	ddejfdd„Zdeddfdd„Zdefd	d
„Zdeddfdd„Z	ddd„Z
dS )ÚCMACNÚ	algorithmc                 C   sd   t |ƒ}t|tƒstdtjƒ‚t|tjƒstdƒ‚|| _	|| _
|d u r-| j
 | j	¡| _d S || _d S )Nz.Backend object does not implement CMACBackend.z*Expected instance of BlockCipherAlgorithm.)r   Ú
isinstancer   r   r   ÚBACKEND_MISSING_INTERFACEr   ÚBlockCipherAlgorithmÚ	TypeErrorÚ
_algorithmÚ_backendÚcreate_cmac_ctxÚ_ctx)Úselfr
   ÚbackendÚctx© r   úE/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/cmac.pyÚ__init__   s   
þ
zCMAC.__init__Ú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_bytesÚupdate)r   r   r   r   r   r   &   s   
zCMAC.updatec                 C   s&   | j d u r	tdƒ‚| j  ¡ }d | _ |S )Nr   )r   r   Úfinalize)r   Údigestr   r   r   r   -   s
   

zCMAC.finalizeÚ	signaturec                 C   s:   t  d|¡ | jd u rtdƒ‚| jd }| _| |¡ d S )Nr    r   )r   r   r   r   Úverify)r   r    r   r   r   r   r!   4   s
   
zCMAC.verifyc                 C   s*   | j d u r	tdƒ‚t| j| j| j  ¡ d�S )Nr   )r   r   )r   r   r	   r   r   Úcopy)r   r   r   r   r"   <   s
   
ÿz	CMAC.copy)NN)r   r	   )Ú__name__Ú
__module__Ú__qualname__r   r   r   Úbytesr   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   Úobjectr	   r   r   r   r   Ú<module>   s   