U
    /j                     @  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-qzbw3lpx/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   				