
    :?h                         S r SSKrSSKrSSKJr  SSKJr  S\S\S\S	\4S
 jr	 " S S5      r
 " S S\
5      r " S S\
5      r " S S\
5      rg)z.Implementation of MySQL Authentication Plugin.    N)Optional   )hexlifyhash1hash2	hash_sizereturnc                     [        X5       VVs/ sH	  u  p4X4-  PM     nnn[        R                  " U S3/UQ76 $ s  snnf )zEncrypt/Decrypt function used for password encryption in
authentication, using a simple XOR.

Args:
    hash1 (str): The first hash.
    hash2 (str): The second hash.

Returns:
    str: A string with the xor applied.
B)zipstructpack)r   r   r   h1h2xoreds         ]/var/www/ev-aguas/ev-aguas-proceso/venv/lib/python3.13/site-packages/mysqlx/authentication.py
xor_stringr   '   sB     &)%67%6"RW%6E7;;)A/// 8s   ;c                   V    \ rS rSrSrSS\\   S\\   4S jjrS\4S jrS\4S	 jr	S
r
g)BaseAuthPlugin6   z7Base class for implementing the authentication plugins.Nusernamepasswordc                     Xl         X l        g )N	_username	_password)selfr   r   s      r   __init__BaseAuthPlugin.__init__9   s    (0(0    r	   c                     [         e)=Returns the plugin name.

Returns:
    str: The plugin name.
NotImplementedErrorr   s    r   nameBaseAuthPlugin.name=   
     "!r    c                     [         e)MReturns the authentication name.

Returns:
    str: The authentication name.
r#   r%   s    r   	auth_nameBaseAuthPlugin.auth_nameE   r(   r    )r   r   )NN)__name__
__module____qualname____firstlineno____doc__r   strr   r&   r+   __static_attributes__ r    r   r   r   6   s8    A1# 1# 1"c ""3 "r    r   c                   F    \ rS rSrSrS\4S jrS\4S jrS\S\4S jr	Sr
g	)
MySQL41AuthPluginN   zCClass implementing the MySQL Native Password authentication plugin.r	   c                     g)r"   zMySQL 4.1 Authentication Pluginr4   r%   s    r   r&   MySQL41AuthPlugin.nameQ   s     1r    c                     g)r*   MYSQL41r4   r%   s    r   r+   MySQL41AuthPlugin.auth_nameY   s     r    datac                    U R                   (       a  [        U R                   [        5      (       a  U R                   R                  S5      OU R                   n[        R
                  " U5      R                  5       n[        R
                  " U5      R                  5       n[        U[        R
                  " X-   5      R                  5       S5      nSU R                   S[        U5       S3$ SU R                   S3$ )zHashing for MySQL 4.1 authentication.

Args:
    data (bytes): The authentication data.

Returns:
    str: The authentication response.
utf-8    z *)
r   
isinstancer2   encodehashlibsha1digestr   r   r   r   r=   r   r   r   r   s         r   	auth_dataMySQL41AuthPlugin.auth_dataa   s     >> dnnc22 %%g.^^ 
 LL*113ELL'..0Eugll4<&@&G&G&I2NE's75>*:"==DNN#2&&r    r4   Nr-   r.   r/   r0   r1   r2   r&   r+   bytesrH   r3   r4   r    r   r6   r6   N   s0    M1c 13 'e ' 'r    r6   c                   B    \ rS rSrSrS\4S jrS\4S jrS\4S jrSr	g)	PlainAuthPluginw   z9Class implementing the MySQL Plain authentication plugin.r	   c                     g)r"   zPlain Authentication Pluginr4   r%   s    r   r&   PlainAuthPlugin.namez   s     -r    c                     g)r*   PLAINr4   r%   s    r   r+   PlainAuthPlugin.auth_name   s     r    c                 :    SU R                    SU R                   3$ )zMReturns the authentication data.

Returns:
    str: The authentication data.
rA   r   r%   s    r   rH   PlainAuthPlugin.auth_data   s!     DNN#2dnn%566r    r4   N)
r-   r.   r/   r0   r1   r2   r&   r+   rH   r3   r4   r    r   rM   rM   w   s)    C-c -3 73 7r    rM   c                   F    \ rS rSrSrS\4S jrS\4S jrS\S\4S jr	Sr
g	)
Sha256MemoryAuthPlugin   z;Class implementing the SHA256_MEMORY authentication plugin.r	   c                     g)r"   z#SHA256_MEMORY Authentication Pluginr4   r%   s    r   r&   Sha256MemoryAuthPlugin.name   s     5r    c                     g)r*   SHA256_MEMORYr4   r%   s    r   r+    Sha256MemoryAuthPlugin.auth_name   s     r    r=   c                    [        U R                  [        5      (       a  U R                  R                  S5      OU R                  n[        R
                  " U5      R                  5       n[        R
                  " [        R
                  " U5      R                  5       U-   5      R                  5       n[        XCS5      nSU R                   S[        U5       3$ )zHashing for SHA256_MEMORY authentication.

The scramble is of the form:
    SHA256(SHA256(SHA256(PASSWORD)),NONCE) XOR SHA256(PASSWORD)

Args:
    data (bytes): The authentication data.

Returns:
    str: The authentication response.
r?       rA   )
rB   r   r2   rC   rD   sha256rF   r   r   r   rG   s         r   rH    Sha256MemoryAuthPlugin.auth_data   s     $..#.. NN!!'* 	
 x(//1w~~e4;;=DELLN5,DNN#2gen%566r    r4   NrJ   r4   r    r   rW   rW      s0    E5c 53 7e 7 7r    rW   )r1   rD   r   typingr   helpersr   rK   intr   r   r6   rM   rW   r4   r    r   <module>re      sf   : 5    0e 0E 0c 0e 0" "0&' &'R7n 78'7^ '7r    