o
    "“i~   ã                   @  sf  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
 d dl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d4dd„Zd5dd„Zd6d d!„Zd7d"d#„ZG d$d%„ d%eƒZG d&d'„ d'eƒZG d(d)„ d)eƒZG d*d+„ d+eƒZG d,d-„ d-eƒZG d.d/„ d/eƒZG d0d1„ d1eƒZG d2d3„ d3eeƒZdS )8é    )ÚannotationsN)Úutils)ÚUnsupportedAlgorithmÚ_Reasons)ÚBlockCipherAlgorithmÚCipherAlgorithm)Ú
algorithmsc                   @  s0   e Zd Zeejddd„ƒƒZejddd	„ƒZd
S )ÚModeÚreturnÚstrc                 C  ó   dS )z@
        A string naming this mode (e.g. "ECB", "CBC").
        N© ©Úselfr   r   úl/var/www/html/premium_crap/venv/lib/python3.10/site-packages/cryptography/hazmat/primitives/ciphers/modes.pyÚname   ó    z	Mode.nameÚ	algorithmr   ÚNonec                 C  r   )zq
        Checks that all the necessary invariants of this (mode, algorithm)
        combination are met.
        Nr   ©r   r   r   r   r   Úvalidate_for_algorithm   r   zMode.validate_for_algorithmN)r
   r   ©r   r   r
   r   )Ú__name__Ú
__module__Ú__qualname__ÚpropertyÚabcÚabstractmethodr   r   r   r   r   r   r	      s    r	   )Ú	metaclassc                   @  ó    e Zd Zeejddd„ƒƒZdS )ÚModeWithInitializationVectorr
   úutils.Bufferc                 C  r   )zP
        The value of the initialization vector for this mode as bytes.
        Nr   r   r   r   r   Úinitialization_vector#   r   z2ModeWithInitializationVector.initialization_vectorN©r
   r!   )r   r   r   r   r   r   r"   r   r   r   r   r    "   ó    r    c                   @  r   )ÚModeWithTweakr
   r!   c                 C  r   )z@
        The value of the tweak for this mode as bytes.
        Nr   r   r   r   r   Útweak,   r   zModeWithTweak.tweakNr#   )r   r   r   r   r   r   r&   r   r   r   r   r%   +   r$   r%   c                   @  r   )ÚModeWithNoncer
   r!   c                 C  r   )z@
        The value of the nonce for this mode as bytes.
        Nr   r   r   r   r   Únonce5   r   zModeWithNonce.nonceNr#   )r   r   r   r   r   r   r(   r   r   r   r   r'   4   r$   r'   c                   @  r   )ÚModeWithAuthenticationTagr
   úbytes | Nonec                 C  r   )zP
        The value of the tag supplied to the constructor of this mode.
        Nr   r   r   r   r   Útag>   r   zModeWithAuthenticationTag.tagN©r
   r*   )r   r   r   r   r   r   r+   r   r   r   r   r)   =   r$   r)   r   r   r   r
   r   c                 C  s$   |j dkr|jdkrtdƒ‚d S d S )Né   ÚAESz=Only 128, 192, and 256 bit keys are allowed for this AES mode)Úkey_sizer   Ú
ValueErrorr   r   r   r   Ú_check_aes_key_lengthF   s
   ÿÿr1   r   c                 C  s4   t | jƒ}|d |jkrtd|› d| j› d�ƒ‚d S )Né   zInvalid IV size (ú) for Ú.)Úlenr"   Ú
block_sizer0   r   )r   r   Úiv_lenr   r   r   Ú_check_iv_lengthM   s   
ÿr8   r(   r!   r   r   c                 C  sL   t |tƒst|› d�tjƒ‚t| ƒd |jkr$tdt| ƒ› d|› d�ƒ‚d S )Nú" requires a block cipher algorithmr2   zInvalid nonce size (r3   r4   )Ú
isinstancer   r   r   ÚUNSUPPORTED_CIPHERr5   r6   r0   )r(   r   r   r   r   r   Ú_check_nonce_lengthU   s   
þÿr<   c                 C  s4   t |tƒst| › d�tjƒ‚t| |ƒ t| |ƒ d S )Nr9   )r:   r   r   r   r;   r1   r8   r   r   r   r   Ú_check_iv_and_key_lengtha   s   
þ
r=   c                   @  ó,   e Zd Zd Zd	dd„Zed
dd„ƒZeZdS )ÚCBCr"   r!   c                 C  ó   t  d|¡ || _d S ©Nr"   ©r   Ú_check_byteslikeÚ_initialization_vector©r   r"   r   r   r   Ú__init__p   ó   
zCBC.__init__r
   c                 C  ó   | j S ©N©rD   r   r   r   r   r"   t   ó   zCBC.initialization_vectorN©r"   r!   r#   ©	r   r   r   r   rF   r   r"   r=   r   r   r   r   r   r?   m   ó    
r?   c                   @  ó2   e Zd Zd Zddd„Zeddd„ƒZddd„ZdS )ÚXTSr&   r!   c                 C  s*   t  d|¡ t|ƒdkrtdƒ‚|| _d S )Nr&   é   z!tweak must be 128-bits (16 bytes))r   rC   r5   r0   Ú_tweak)r   r&   r   r   r   rF   ~   s   
zXTS.__init__r
   c                 C  rH   rI   )rR   r   r   r   r   r&   †   rK   z	XTS.tweakr   r   r   c                 C  s0   t |tjtjfƒrtdƒ‚|jdvrtdƒ‚d S )Nz\The AES128 and AES256 classes do not support XTS, please use the standard AES class instead.)r-   i   z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)r:   r   ÚAES128ÚAES256Ú	TypeErrorr/   r0   r   r   r   r   r   Š   s   ÿ
ÿÿzXTS.validate_for_algorithmN)r&   r!   r#   r   )r   r   r   r   rF   r   r&   r   r   r   r   r   rP   {   s    
rP   c                   @  s   e Zd Zd ZeZdS )ÚECBN)r   r   r   r   r1   r   r   r   r   r   rV   ˜   s    rV   c                   @  r>   )ÚOFBr"   r!   c                 C  r@   rA   rB   rE   r   r   r   rF   ¡   rG   zOFB.__init__r
   c                 C  rH   rI   rJ   r   r   r   r   r"   ¥   rK   zOFB.initialization_vectorNrL   r#   rM   r   r   r   r   rW   ž   rN   rW   c                   @  r>   )ÚCFBr"   r!   c                 C  r@   rA   rB   rE   r   r   r   rF   ¯   rG   zCFB.__init__r
   c                 C  rH   rI   rJ   r   r   r   r   r"   ³   rK   zCFB.initialization_vectorNrL   r#   rM   r   r   r   r   rX   ¬   rN   rX   c                   @  r>   )ÚCFB8r"   r!   c                 C  r@   rA   rB   rE   r   r   r   rF   ½   rG   zCFB8.__init__r
   c                 C  rH   rI   rJ   r   r   r   r   r"   Á   rK   zCFB8.initialization_vectorNrL   r#   rM   r   r   r   r   rY   º   rN   rY   c                   @  rO   )ÚCTRr(   r!   c                 C  r@   )Nr(   )r   rC   Ú_nonce)r   r(   r   r   r   rF   Ë   rG   zCTR.__init__r
   c                 C  rH   rI   )r[   r   r   r   r   r(   Ï   rK   z	CTR.noncer   r   r   c                 C  s   t | |ƒ t| j| j|ƒ d S rI   )r1   r<   r(   r   r   r   r   r   r   Ó   s   
zCTR.validate_for_algorithmN)r(   r!   r#   r   )r   r   r   r   rF   r   r(   r   r   r   r   r   rZ   È   s    
rZ   c                   @  sN   e Zd Zd ZdZdZ		dddd„Zeddd„ƒZeddd„ƒZ	ddd„Z
dS )ÚGCMl   àÿ? l            NrQ   r"   r!   r+   r*   Úmin_tag_lengthÚintc                 C  s‚   t  d|¡ t|ƒdk st|ƒdkrtdƒ‚|| _|d ur9t  d|¡ |dk r+tdƒ‚t|ƒ|k r9td|› d	�ƒ‚|| _|| _d S )
Nr"   r2   é€   zIinitialization_vector must be between 8 and 128 bytes (64 and 1024 bits).r+   é   zmin_tag_length must be >= 4zAuthentication tag must be z bytes or longer.)r   rC   r5   r0   rD   Ú_check_bytesÚ_tagÚ_min_tag_length)r   r"   r+   r]   r   r   r   rF   Ý   s    ÿ
ÿ
zGCM.__init__r
   c                 C  rH   rI   )rb   r   r   r   r   r+   ø   rK   zGCM.tagc                 C  rH   rI   rJ   r   r   r   r   r"   ü   rK   zGCM.initialization_vectorr   r   r   c                 C  sZ   t | |ƒ t|tƒstdtjƒ‚|jd }| jd ur)t| jƒ|kr+t	d|› d�ƒ‚d S d S )Nz%GCM requires a block cipher algorithmr2   z'Authentication tag cannot be more than z bytes.)
r1   r:   r   r   r   r;   r6   rb   r5   r0   )r   r   Úblock_size_bytesr   r   r   r      s   

þ

ÿÿzGCM.validate_for_algorithm)NrQ   )r"   r!   r+   r*   r]   r^   r,   r#   r   )r   r   r   r   Ú_MAX_ENCRYPTED_BYTESÚ_MAX_AAD_BYTESrF   r   r+   r"   r   r   r   r   r   r\   Ø   s    ür\   )r   r	   r   r   r
   r   )r   r    r   r   r
   r   )r(   r!   r   r   r   r   r
   r   )r   r    r   r   r
   r   )Ú
__future__r   r   Úcryptographyr   Úcryptography.exceptionsr   r   Ú/cryptography.hazmat.primitives._cipheralgorithmr   r   Ú&cryptography.hazmat.primitives.ciphersr   ÚABCMetar	   r    r%   r'   r)   r1   r8   r<   r=   r?   rP   rV   rW   rX   rY   rZ   r\   r   r   r   r   Ú<module>   s.   			
	


