
    2iw                       d dl mZ d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZ  G d de      Z G d de      Z G d de      Z G d de      Z G d dee      Z ej<                  e
edej@                  d        ej<                  eedej@                  d        ej<                  e	edej@                  d       y )!    )annotations)utils)UnsupportedAlgorithm_Reasons)CFB)CFB8)OFB)BlockCipherAlgorithmCipherAlgorithm)Mode)ModeWithAuthenticationTag)ModeWithInitializationVector)ModeWithNonce)ModeWithTweak)_check_aes_key_length_check_iv_and_key_length_check_nonce_length)
algorithmsc                  .    e Zd Zd ZddZedd       ZeZy)CBCc                >    t        j                  d|       || _        y )Ninitialization_vector)r   _check_byteslike_initialization_vector)selfr   s     b/var/www/html/qr/venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/modes.py__init__zCBC.__init__*   s    68MN&;#    c                    | j                   S Nr   r   s    r   r   zCBC.initialization_vector.       ***r   N)r   utils.Bufferreturnr$   )	__name__
__module____qualname__namer   propertyr   r   validate_for_algorithm r   r   r   r   '   s(    D< + + 6r   r   c                  2    e Zd Zd ZddZedd       ZddZy)XTSc                p    t        j                  d|       t        |      dk7  rt        d      || _        y )Ntweak   z!tweak must be 128-bits (16 bytes))r   r   len
ValueError_tweak)r   r1   s     r   r   zXTS.__init__8   s1    w.u:@AAr   c                    | j                   S r    )r5   r"   s    r   r1   z	XTS.tweak@       {{r   c                    t        |t        j                  t        j                  f      rt	        d      |j
                  dvrt        d      y )Nz\The AES128 and AES256 classes do not support XTS, please use the standard AES class instead.)   i   z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)
isinstancer   AES128AES256	TypeErrorkey_sizer4   r   	algorithms     r   r,   zXTS.validate_for_algorithmD   sV    i*"3"3Z5F5F!GH2 
 Z/3  0r   N)r1   r$   r%   r@   r   r&   None)r'   r(   r)   r*   r   r+   r1   r,   r-   r   r   r/   r/   5   s%    D  r   r/   c                      e Zd Zd ZeZy)ECBN)r'   r(   r)   r*   r   r,   r-   r   r   rD   rD   R   s    D2r   rD   c                  2    e Zd Zd ZddZedd       ZddZy)CTRc                >    t        j                  d|       || _        y )Nnonce)r   r   _nonce)r   rH   s     r   r   zCTR.__init__[   s    w.r   c                    | j                   S r    )rI   r"   s    r   rH   z	CTR.nonce_   r7   r   c                ^    t        | |       t        | j                  | j                  |       y r    )r   r   rH   r*   r?   s     r   r,   zCTR.validate_for_algorithmc   s     dI.DJJ		9=r   N)rH   r$   r%   rA   )r'   r(   r)   r*   r   r+   rH   r,   r-   r   r   rF   rF   X   s%    D  >r   rF   c                  \    e Zd Zd ZdZdZ	 	 d	 	 	 	 	 d	dZed
d       Zedd       Z	ddZ
y)GCMl   ? l            Nc                2   t        j                  d|       t        |      dk  st        |      dkD  rt        d      || _        |Ct        j
                  d|       |dk  rt        d      t        |      |k  rt        d| d	      || _        || _        y )
Nr         zIinitialization_vector must be between 8 and 128 bytes (64 and 1024 bits).tag   zmin_tag_length must be >= 4zAuthentication tag must be z bytes or longer.)r   r   r3   r4   r   _check_bytes_tag_min_tag_length)r   r   rQ   min_tag_lengths       r   r   zGCM.__init__m   s     	68MN$%)S1F-G#-M"  '<#?uc*! !>??3x.( 1.1A B   	-r   c                    | j                   S r    )rT   r"   s    r   rQ   zGCM.tag   s    yyr   c                    | j                   S r    r!   r"   s    r   r   zGCM.initialization_vector   r#   r   c                    t        | |       t        |t              st        dt        j
                        |j                  dz  }| j                  (t        | j                        |kD  rt        d| d      y y )Nz%GCM requires a block cipher algorithmrO   z'Authentication tag cannot be more than z bytes.)
r   r:   r
   r   r   UNSUPPORTED_CIPHER
block_sizerT   r3   r4   )r   r@   block_size_bytess      r   r,   zGCM.validate_for_algorithm   s    dI.)%9:&7++  %//1499 S^6F%F9:J9K L   &G r   )Nr2   )r   r$   rQ   bytes | NonerV   int)r&   r]   r%   rA   )r'   r(   r)   r*   _MAX_ENCRYPTED_BYTES_MAX_AAD_BYTESr   r+   rQ   r   r,   r-   r   r   rM   rM   h   sh    D-!N
 ! 	.+. . 	.6   + +r   rM   zOFB has been moved to cryptography.hazmat.decrepit.ciphers.modes.OFB and will be removed from cryptography.hazmat.primitives.ciphers.modes in 49.0.0.r	   )r*   zCFB has been moved to cryptography.hazmat.decrepit.ciphers.modes.CFB and will be removed from cryptography.hazmat.primitives.ciphers.modes in 49.0.0.r   zCFB8 has been moved to cryptography.hazmat.decrepit.ciphers.modes.CFB8 and will be removed from cryptography.hazmat.primitives.ciphers.modes in 49.0.0.r   N)!
__future__r   cryptographyr   cryptography.exceptionsr   r   *cryptography.hazmat.decrepit.ciphers.modesr   r   r	   /cryptography.hazmat.primitives._cipheralgorithmr
   r   %cryptography.hazmat.primitives._modesr   r   r   r   r   r   r   r   &cryptography.hazmat.primitives.ciphersr   r   r/   rD   rF   rM   
deprecatedr'   DeprecatedIn47r-   r   r   <module>rj      s	  
 #  B A C A 
 >6
& 6- :3$ 3>- > 4
&(A 4n   > 
		   > 
		   > 
		r   