
    +h                     6   d dl mZ d dl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ej                  	      Z G d
 deej                  	      Z G d deej                  	      Z G d deej                  	      Z G d deej                  	      Zd&dZ	 	 	 	 	 	 d'dZ	 	 	 	 	 	 	 	 d(dZ	 	 	 	 	 	 d)d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      Z G d  d!e      Z G d" d#e      Z G d$ d%ee      Zy)*    )annotationsN)utils)UnsupportedAlgorithm_Reasons)BlockCipherAlgorithmCipherAlgorithm)
algorithmsc                  b    e Zd Zeej
                  dd              Zej
                  dd       Zy)Modec                     y)z@
        A string naming this mode (e.g. "ECB", "CBC").
        N selfs    _/var/www/html/venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/modes.pynamez	Mode.name           c                     y)zq
        Checks that all the necessary invariants of this (mode, algorithm)
        combination are met.
        Nr   r   	algorithms     r   validate_for_algorithmzMode.validate_for_algorithm   r   r   N)returnstrr   r   r   None)__name__
__module____qualname__propertyabcabstractmethodr   r   r   r   r   r   r      s<      
 	 r   r   )	metaclassc                  <    e Zd Zeej
                  dd              Zy)ModeWithInitializationVectorc                     y)zP
        The value of the initialization vector for this mode as bytes.
        Nr   r   s    r   initialization_vectorz2ModeWithInitializationVector.initialization_vector$   r   r   Nr   bytes)r   r   r   r   r    r!   r&   r   r   r   r$   r$   #   "      r   r$   c                  <    e Zd Zeej
                  dd              Zy)ModeWithTweakc                     y)z@
        The value of the tweak for this mode as bytes.
        Nr   r   s    r   tweakzModeWithTweak.tweak-   r   r   Nr'   )r   r   r   r   r    r!   r-   r   r   r   r+   r+   ,   r)   r   r+   c                  <    e Zd Zeej
                  dd              Zy)ModeWithNoncec                     y)z@
        The value of the nonce for this mode as bytes.
        Nr   r   s    r   noncezModeWithNonce.nonce6   r   r   Nr'   )r   r   r   r   r    r!   r1   r   r   r   r/   r/   5   r)   r   r/   c                  <    e Zd Zeej
                  dd              Zy)ModeWithAuthenticationTagc                     y)zP
        The value of the tag supplied to the constructor of this mode.
        Nr   r   s    r   tagzModeWithAuthenticationTag.tag?   r   r   Nr   typing.Optional[bytes])r   r   r   r   r    r!   r5   r   r   r   r3   r3   >   r)   r   r3   c                X    |j                   dkD  r|j                  dk(  rt        d      y y )N   AESz=Only 128, 192, and 256 bit keys are allowed for this AES mode)key_sizer   
ValueErrorr   s     r   _check_aes_key_lengthr=   G   s3    CINNe$;K
 	
 %<r   c                    t        | j                        dz  |j                  k7  r8t        dj	                  t        | j                        | j
                              y )N   zInvalid IV size ({}) for {}.)lenr&   
block_sizer<   formatr   r   s     r   _check_iv_lengthrC   N   sW     4%%&*i.B.BB*11D../
 	
 Cr   c                    t        |t              st        | dt        j                        t        |       dz  |j                  k7  rt        dt        |        d| d      y )N" requires a block cipher algorithmr?   zInvalid nonce size (z) for .)
isinstancer   r   r   UNSUPPORTED_CIPHERr@   rA   r<   )r1   r   r   s      r   _check_nonce_lengthrI   Y   sl     i!56"f67''
 	
 5zA~---/E
|6$qIJJ .r   c                    t        |t              st        |  dt        j                        t        | |       t        | |       y )NrE   )rG   r   r   r   rH   r=   rC   r   s     r   _check_iv_and_key_lengthrK   e   sF     i!56"f67''
 	
 $	*T9%r   c                  .    e Zd Zd ZddZedd       ZeZy)CBCc                >    t        j                  d|       || _        y Nr&   r   _check_byteslike_initialization_vectorr   r&   s     r   __init__zCBC.__init__t       68MN&;#r   c                    | j                   S NrR   r   s    r   r&   zCBC.initialization_vectorx       ***r   Nr&   r(   r'   	r   r   r   r   rT   r   r&   rK   r   r   r   r   rM   rM   q   (    D< + + 6r   rM   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 )Nr-      z!tweak must be 128-bits (16 bytes))r   rQ   r@   r<   _tweak)r   r-   s     r   rT   zXTS.__init__   s1    w.u:@AAr   c                    | j                   S rW   )ra   r   s    r   r-   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.)r9   i   z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)rG   r	   AES128AES256	TypeErrorr;   r<   r   s     r   r   zXTS.validate_for_algorithm   sV    i*"3"3Z5F5F!GH2 
 Z/3  0r   N)r-   r(   r'   r   )r   r   r   r   rT   r   r-   r   r   r   r   r^   r^      s%    D  r   r^   c                      e Zd Zd ZeZy)ECBN)r   r   r   r   r=   r   r   r   r   ri   ri      s    D2r   ri   c                  .    e Zd Zd ZddZedd       ZeZy)OFBc                >    t        j                  d|       || _        y rO   rP   rS   s     r   rT   zOFB.__init__   rU   r   c                    | j                   S rW   rX   r   s    r   r&   zOFB.initialization_vector   rY   r   NrZ   r'   r[   r   r   r   rk   rk      r\   r   rk   c                  .    e Zd Zd ZddZedd       ZeZy)CFBc                >    t        j                  d|       || _        y rO   rP   rS   s     r   rT   zCFB.__init__   rU   r   c                    | j                   S rW   rX   r   s    r   r&   zCFB.initialization_vector   rY   r   NrZ   r'   r[   r   r   r   ro   ro      r\   r   ro   c                  .    e Zd Zd ZddZedd       ZeZy)CFB8c                >    t        j                  d|       || _        y rO   rP   rS   s     r   rT   zCFB8.__init__   rU   r   c                    | j                   S rW   rX   r   s    r   r&   zCFB8.initialization_vector   rY   r   NrZ   r'   r[   r   r   r   rs   rs      s(    D< + + 6r   rs   c                  2    e Zd Zd ZddZedd       ZddZy)CTRc                >    t        j                  d|       || _        y )Nr1   )r   rQ   _nonce)r   r1   s     r   rT   zCTR.__init__   s    w.r   c                    | j                   S rW   )ry   r   s    r   r1   z	CTR.nonce   rc   r   c                ^    t        | |       t        | j                  | j                  |       y rW   )r=   rI   r1   r   r   s     r   r   zCTR.validate_for_algorithm   s     dI.DJJ		9=r   N)r1   r(   r'   r   )r   r   r   r   rT   r   r1   r   r   r   r   rw   rw      s%    D  >r   rw   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                H   t        j                  d|       t        |      dk  st        |      dkD  rt        d      || _        |Nt        j
                  d|       |dk  rt        d      t        |      |k  rt        dj                  |            || _        || _        y )	Nr&   r?      zIinitialization_vector must be between 8 and 128 bytes (64 and 1024 bits).r5      zmin_tag_length must be >= 4z.Authentication tag must be {} bytes or longer.)	r   rQ   r@   r<   rR   _check_bytesrB   _tag_min_tag_length)r   r&   r5   min_tag_lengths       r   rT   zGCM.__init__   s     	68MN$%)S1F-G#-M"  '<#?uc*! !>??3x.( DKK& 
 	-r   c                    | j                   S rW   )r   r   s    r   r5   zGCM.tag   s    yyr   c                    | j                   S rW   rX   r   s    r   r&   zGCM.initialization_vector  rY   r   c                   t        | |       t        |t              st        dt        j
                        |j                  dz  }| j                  3t        | j                        |kD  rt        dj                  |            y y )Nz%GCM requires a block cipher algorithmr?   z0Authentication tag cannot be more than {} bytes.)r=   rG   r   r   r   rH   rA   r   r@   r<   rB   )r   r   block_size_bytess      r   r   zGCM.validate_for_algorithm  s    dI.)%9:&7++  %//1499 S^6F%FBII$  &G r   )Nr`   )r&   r(   r5   r7   r   intr6   r'   r   )r   r   r   r   _MAX_ENCRYPTED_BYTES_MAX_AAD_BYTESrT   r   r5   r&   r   r   r   r   r}   r}      sh    D-!N
 '+ 	.$. $. 	.8   + +r   r}   )r   r   r   r   r   r   )r   r$   r   r   r   r   )r1   r(   r   r   r   r   r   r   )r   r$   r   r   r   r   ) 
__future__r   r    typingcryptographyr   cryptography.exceptionsr   r   /cryptography.hazmat.primitives._cipheralgorithmr   r   &cryptography.hazmat.primitives.ciphersr	   ABCMetar   r$   r+   r/   r3   r=   rC   rI   rK   rM   r^   ri   rk   ro   rs   rw   r}   r   r   r   <module>r      sI  
 # 
   B >S[[  43;; DCKK DCKK  


&
3G
	
	K	K	K(7	K		K	&
&	&3B	&		&6
& 6- :3$ 36
& 66
& 66' 6>- > 6
&(A 6r   