
    #	h                         S SK Jr  S SKrS SKJr  S SKJrJr  S SKJ	r	J
r
  S SKJr   " S S\R                  S	9r " S
 S\\R                  S	9r " S S\\R                  S	9r " S S\\R                  S	9r " S S\\R                  S	9rS&S jr      S'S jr        S(S jr      S)S jr " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S  S!\5      r " S" S#\5      r " S$ S%\\5      rg)*    )annotationsN)utils)UnsupportedAlgorithm_Reasons)BlockCipherAlgorithmCipherAlgorithm)
algorithmsc                  n    \ rS rSr\\R                  SS j5       5       r\R                  SS j5       rSr	g)Mode   c                    g)z0
A string naming this mode (e.g. "ECB", "CBC").
N selfs    ^/var/www/html/env/lib/python3.13/site-packages/cryptography/hazmat/primitives/ciphers/modes.pyname	Mode.name           c                    g)zY
Checks that all the necessary invariants of this (mode, algorithm)
combination are met.
Nr   r   	algorithms     r   validate_for_algorithmMode.validate_for_algorithm   r   r   r   N)returnstrr   r   r   None)
__name__
__module____qualname____firstlineno__propertyabcabstractmethodr   r   __static_attributes__r   r   r   r   r      s<      
 	 r   r   )	metaclassc                  F    \ rS rSr\\R                  SS j5       5       rSrg)ModeWithInitializationVector"   c                    g)z@
The value of the initialization vector for this mode as bytes.
Nr   r   s    r   initialization_vector2ModeWithInitializationVector.initialization_vector#   r   r   r   Nr   bytes)	r   r    r!   r"   r#   r$   r%   r,   r&   r   r   r   r)   r)   "   "      r   r)   c                  F    \ rS rSr\\R                  SS j5       5       rSrg)ModeWithTweak+   c                    g)z0
The value of the tweak for this mode as bytes.
Nr   r   s    r   tweakModeWithTweak.tweak,   r   r   r   Nr.   )	r   r    r!   r"   r#   r$   r%   r5   r&   r   r   r   r2   r2   +   r0   r   r2   c                  F    \ rS rSr\\R                  SS j5       5       rSrg)ModeWithNonce4   c                    g)z0
The value of the nonce for this mode as bytes.
Nr   r   s    r   nonceModeWithNonce.nonce5   r   r   r   Nr.   )	r   r    r!   r"   r#   r$   r%   r;   r&   r   r   r   r8   r8   4   r0   r   r8   c                  F    \ rS rSr\\R                  SS j5       5       rSrg)ModeWithAuthenticationTag=   c                    g)z@
The value of the tag supplied to the constructor of this mode.
Nr   r   s    r   tagModeWithAuthenticationTag.tag>   r   r   r   Nr   bytes | None)	r   r    r!   r"   r#   r$   r%   rA   r&   r   r   r   r>   r>   =   r0   r   r>   c                \    UR                   S:  a  UR                  S:X  a  [        S5      eg g )N   AESz=Only 128, 192, and 256 bit keys are allowed for this AES mode)key_sizer   
ValueErrorr   s     r   _check_aes_key_lengthrJ   F   s3    CINNe$;K
 	
 %<r   c                    [        U R                  5      nUS-  UR                  :w  a  [        SU SU R                   S35      eg )N   zInvalid IV size () for .)lenr,   
block_sizerI   r   )r   r   iv_lens      r   _check_iv_lengthrR   M   sJ     ++,FzY))),VHF499+QGHH *r   c                    [        U[        5      (       d  [        U S3[        R                  5      e[        U 5      S-  UR                  :w  a  [        S[        U 5       SU S35      eg )N" requires a block cipher algorithmrL   zInvalid nonce size (rM   rN   )
isinstancer   r   r   UNSUPPORTED_CIPHERrO   rP   rI   )r;   r   r   s      r   _check_nonce_lengthrW   U   so     i!566"f67''
 	
 5zA~---/E
|6$qIJJ .r   c                    [        U[        5      (       d  [        U  S3[        R                  5      e[        X5        [        X5        g )NrT   )rU   r   r   r   rV   rJ   rR   r   s     r   _check_iv_and_key_lengthrY   a   sE     i!566"f67''
 	
 $*T%r   c                  :    \ rS rSrS rSS jr\SS j5       r\r	Sr
g)CBCm   c                >    [         R                  " SU5        Xl        g Nr,   r   _check_byteslike_initialization_vectorr   r,   s     r   __init__CBC.__init__p       68MN&;#r   c                    U R                   $ Nra   r   s    r   r,   CBC.initialization_vectort       ***r   rh   Nr,   r/   r.   r   r    r!   r"   r   rc   r#   r,   rY   r   r&   r   r   r   r[   r[   m   (    D< + + 6r   r[   c                  @    \ rS rSrS rSS jr\SS j5       rS	S jrSr	g)
XTS{   c                r    [         R                  " SU5        [        U5      S:w  a  [        S5      eXl        g )Nr5      z!tweak must be 128-bits (16 bytes))r   r`   rO   rI   _tweak)r   r5   s     r   rc   XTS.__init__~   s/    w.u:@AAr   c                    U R                   $ rg   rs   r   s    r   r5   	XTS.tweak       {{r   c                    [        U[        R                  [        R                  45      (       a  [	        S5      eUR
                  S;  a  [        S5      eg )Nz\The AES128 and AES256 classes do not support XTS, please use the standard AES class instead.)rF   i   z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)rU   r	   AES128AES256	TypeErrorrH   rI   r   s     r   r   XTS.validate_for_algorithm   sY    i*"3"3Z5F5F!GHH2 
 Z/3  0r   rv   N)r5   r/   r.   r   )
r   r    r!   r"   r   rc   r#   r5   r   r&   r   r   r   ro   ro   {   s%    D  r   ro   c                      \ rS rSrS r\rSrg)ECB   r   N)r   r    r!   r"   r   rJ   r   r&   r   r   r   r   r      s    D2r   r   c                  :    \ rS rSrS rSS jr\SS j5       r\r	Sr
g)OFB   c                >    [         R                  " SU5        Xl        g r^   r_   rb   s     r   rc   OFB.__init__   re   r   c                    U R                   $ rg   rh   r   s    r   r,   OFB.initialization_vector   rj   r   rh   Nrk   r.   rl   r   r   r   r   r      rm   r   r   c                  :    \ rS rSrS rSS jr\SS j5       r\r	Sr
g)CFB   c                >    [         R                  " SU5        Xl        g r^   r_   rb   s     r   rc   CFB.__init__   re   r   c                    U R                   $ rg   rh   r   s    r   r,   CFB.initialization_vector   rj   r   rh   Nrk   r.   rl   r   r   r   r   r      rm   r   r   c                  :    \ rS rSrS rSS jr\SS j5       r\r	Sr
g)CFB8   c                >    [         R                  " SU5        Xl        g r^   r_   rb   s     r   rc   CFB8.__init__   re   r   c                    U R                   $ rg   rh   r   s    r   r,   CFB8.initialization_vector   rj   r   rh   Nrk   r.   rl   r   r   r   r   r      s(    D< + + 6r   r   c                  @    \ rS rSrS rSS jr\SS j5       rS	S jrSr	g)
CTR   c                >    [         R                  " SU5        Xl        g )Nr;   )r   r`   _nonce)r   r;   s     r   rc   CTR.__init__   s    w.r   c                    U R                   $ rg   r   r   s    r   r;   	CTR.nonce   rx   r   c                \    [        X5        [        U R                  U R                  U5        g rg   )rJ   rW   r;   r   r   s     r   r   CTR.validate_for_algorithm   s    d.DJJ		9=r   r   N)r;   r/   r.   r   )
r   r    r!   r"   r   rc   r#   r;   r   r&   r   r   r   r   r      s%    D  >r   r   c                  n    \ rS rSrS rSrSr  S
     SS jjr\SS j5       r	\SS j5       r
SS jrS	rg)GCM   l   ? l            Nc                :   [         R                  " SU5        [        U5      S:  d  [        U5      S:  a  [        S5      eXl        UbF  [         R
                  " SU5        US:  a  [        S5      e[        U5      U:  a  [        SU S	35      eX l        X0l        g )
Nr,   rL      zIinitialization_vector must be between 8 and 128 bytes (64 and 1024 bits).rA      zmin_tag_length must be >= 4zAuthentication tag must be z bytes or longer.)r   r`   rO   rI   ra   _check_bytes_tag_min_tag_length)r   r,   rA   min_tag_lengths       r   rc   GCM.__init__   s     	68MN$%)S1F-G#-M"  '<#?uc*! !>??3x.( 1.1A B   	-r   c                    U R                   $ rg   )r   r   s    r   rA   GCM.tag   s    yyr   c                    U R                   $ rg   rh   r   s    r   r,   GCM.initialization_vector   rj   r   c                   [        X5        [        U[        5      (       d  [        S[        R
                  5      eUR                  S-  nU R                  b)  [        U R                  5      U:  a  [        SU S35      eg g )Nz%GCM requires a block cipher algorithmrL   z'Authentication tag cannot be more than z bytes.)
rJ   rU   r   r   r   rV   rP   r   rO   rI   )r   r   block_size_bytess      r   r   GCM.validate_for_algorithm   s    d.)%9::&7++  %//1499 S^6F%F9:J9K L   &G r   )ra   r   r   )Nrr   )r,   r/   rA   rD   r   intrC   r.   r   )r   r    r!   r"   r   _MAX_ENCRYPTED_BYTES_MAX_AAD_BYTESrc   r#   rA   r,   r   r&   r   r   r   r   r      sh    D-!N
 ! 	.$. . 	.6   + +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   r   )
__future__r   r$   cryptographyr   cryptography.exceptionsr   r   /cryptography.hazmat.primitives._cipheralgorithmr   r   &cryptography.hazmat.primitives.ciphersr	   ABCMetar   r)   r2   r8   r>   rJ   rR   rW   rY   r[   ro   r   r   r   r   r   r   r   r   r   <module>r      sJ  
 # 
  B >S[[  43;; DCKK DCKK  
I
&I3GI	I	K	K	K(7	K		K	&
&	&3B	&		&6
& 6- :3$ 36
& 66
& 66' 6>- > 4
&(A 4r   