U
    ¸~Hj  ã                   @  sú   d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	m
Z
 G dd„ dejd�ZG d	d
„ d
eejd�ZG dd„ deejd�ZG dd„ deejd�ZG dd„ deejd�Zddddœdd„Zd
dddœdd„Zdddddœdd„Zd
dddœdd„ZdS ) é    )ÚannotationsN)Úutils)ÚUnsupportedAlgorithmÚ_Reasons)ÚBlockCipherAlgorithmÚCipherAlgorithmc                   @  s:   e Zd Zeejddœdd„ƒƒZejdddœdd	„ƒZd
S )ÚModeÚstr©Úreturnc                 C  s   dS )z@
        A string naming this mode (e.g. "ECB", "CBC").
        N© ©Úselfr   r   úI/tmp/pip-unpacked-wheel-5jtya3dl/cryptography/hazmat/primitives/_modes.pyÚname   s    z	Mode.namer   ÚNone)Ú	algorithmr   c                 C  s   dS )zq
        Checks that all the necessary invariants of this (mode, algorithm)
        combination are met.
        Nr   ©r   r   r   r   r   Úvalidate_for_algorithm   s    zMode.validate_for_algorithmN)Ú__name__Ú
__module__Ú__qualname__ÚpropertyÚabcÚabstractmethodr   r   r   r   r   r   r      s
   r   )Ú	metaclassc                   @  s$   e Zd Zeejddœdd„ƒƒZdS )ÚModeWithInitializationVectorúutils.Bufferr
   c                 C  s   dS )zP
        The value of the initialization vector for this mode as bytes.
        Nr   r   r   r   r   Úinitialization_vector"   s    z2ModeWithInitializationVector.initialization_vectorN)r   r   r   r   r   r   r   r   r   r   r   r   !   s   r   c                   @  s$   e Zd Zeejddœdd„ƒƒZdS )ÚModeWithTweakr   r
   c                 C  s   dS )z@
        The value of the tweak for this mode as bytes.
        Nr   r   r   r   r   Útweak+   s    zModeWithTweak.tweakN)r   r   r   r   r   r   r    r   r   r   r   r   *   s   r   c                   @  s$   e Zd Zeejddœdd„ƒƒZdS )ÚModeWithNoncer   r
   c                 C  s   dS )z@
        The value of the nonce for this mode as bytes.
        Nr   r   r   r   r   Únonce4   s    zModeWithNonce.nonceN)r   r   r   r   r   r   r"   r   r   r   r   r!   3   s   r!   c                   @  s$   e Zd Zeejddœdd„ƒƒZdS )ÚModeWithAuthenticationTagzbytes | Noner
   c                 C  s   dS )zP
        The value of the tag supplied to the constructor of this mode.
        Nr   r   r   r   r   Útag=   s    zModeWithAuthenticationTag.tagN)r   r   r   r   r   r   r$   r   r   r   r   r#   <   s   r#   r   r   )r   r   r   c                 C  s    |j dkr|jdkrtdƒ‚d S )Né   ZAESz=Only 128, 192, and 256 bit keys are allowed for this AES mode)Zkey_sizer   Ú
ValueErrorr   r   r   r   Ú_check_aes_key_lengthE   s    ÿr'   r   c                 C  s4   t | jƒ}|d |jkr0td|› d| j› d�ƒ‚d S )Né   zInvalid IV size (ú) for Ú.)Úlenr   Ú
block_sizer&   r   )r   r   Ziv_lenr   r   r   Ú_check_iv_lengthL   s    
r-   r   r	   )r"   r   r   r   c                 C  sL   t |tƒst|› d�tjƒ‚t| ƒd |jkrHtdt| ƒ› d|› d�ƒ‚d S )Nú" requires a block cipher algorithmr(   zInvalid nonce size (r)   r*   )Ú
isinstancer   r   r   ÚUNSUPPORTED_CIPHERr+   r,   r&   )r"   r   r   r   r   r   Ú_check_nonce_lengthT   s    
þr1   c                 C  s4   t |tƒst| › d�tjƒ‚t| |ƒ t| |ƒ d S )Nr.   )r/   r   r   r   r0   r'   r-   r   r   r   r   Ú_check_iv_and_key_length`   s    
þ
r2   )Ú
__future__r   r   Zcryptographyr   Zcryptography.exceptionsr   r   Z/cryptography.hazmat.primitives._cipheralgorithmr   r   ÚABCMetar   r   r   r!   r#   r'   r-   r1   r2   r   r   r   r   Ú<module>   s   				