
    "i7                         d Z ddlZddlZddlmZ d Z G d de          Z G d d	e          Z G d
 de          Z	 G d de          Z
dS )z.Implementation of MySQL Authentication Plugin.    N   )hexlifyc                     d t          | |          D             }t          j        d                    |          g|R  S )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.
    c                     g | ]
\  }}||z  S  r   ).0h1h2s      M/srv/django_bis/venv311/lib/python3.11/site-packages/mysqlx/authentication.py
<listcomp>zxor_string.<locals>.<listcomp>0   s     777"bR"W777    z{0}B)zipstructpackformat)hash1hash2	hash_sizexoreds       r   
xor_stringr   %   sE     87S%6%6777E;v}}Y//8%8888r   c                   &    e Zd ZdZddZd Zd ZdS )BaseAuthPluginz7Base class for implementing the authentication plugins.Nc                 "    || _         || _        d S )N)	_username	_password)selfusernamepasswords      r   __init__zBaseAuthPlugin.__init__6   s    !!r   c                     t           )UReturns the plugin name.

        Returns:
            str: The plugin name.
        NotImplementedErrorr   s    r   namezBaseAuthPlugin.name:   
     "!r   c                     t           )eReturns the authentication name.

        Returns:
            str: The authentication name.
        r"   r$   s    r   	auth_namezBaseAuthPlugin.auth_nameB   r&   r   )NN)__name__
__module____qualname____doc__r   r%   r)   r   r   r   r   r   4   sL        AA" " " "" " "" " " " "r   r   c                   $    e Zd ZdZd Zd Zd ZdS )MySQL41AuthPluginzCClass implementing the MySQL Native Password authentication plugin.c                     dS )r!   zMySQL 4.1 Authentication Pluginr   r$   s    r   r%   zMySQL41AuthPlugin.nameM   s
     10r   c                     dS )r(   MYSQL41r   r$   s    r   r)   zMySQL41AuthPlugin.auth_nameU   s	     yr   c                    | j         rt          | j         t                    r| j                             d          n| j         }t	          j        |                                          }t	          j        |                                          }t          |t	          j        ||z                                             d          }d                    d| j	        t          |                    S d                    d| j	                  S )zHashing for MySQL 4.1 authentication.

        Args:
            data (str): The authentication data.

        Returns:
            str: The authentication response.
        utf-8   z{0} {1} *{2}  z{0} {1} )r   
isinstancestrencodehashlibsha1digestr   r   r   r   r   datar   r   r   r   s         r   	auth_datazMySQL41AuthPlugin.auth_data]   s     > 	Qdnc22Gt~,,W5558< L**1133EL''..00Eugl4%<&@&@&G&G&I&I2NNE%,,RPPP""2t~666r   Nr*   r+   r,   r-   r%   r)   r?   r   r   r   r/   r/   K   sG        MM1 1 1  7 7 7 7 7r   r/   c                   $    e Zd ZdZd Zd Zd ZdS )PlainAuthPluginz9Class implementing the MySQL Plain authentication plugin.c                     dS )r!   zPlain Authentication Pluginr   r$   s    r   r%   zPlainAuthPlugin.namer   s
     -,r   c                     dS )r(   PLAINr   r$   s    r   r)   zPlainAuthPlugin.auth_namez   s	     wr   c                 B    d                     | j        | j                  S )zeReturns the authentication data.

        Returns:
            str: The authentication data.
         {0} {1})r   r   r   r$   s    r   r?   zPlainAuthPlugin.auth_data   s     ""4>4>BBBr   Nr@   r   r   r   rB   rB   p   sL        CC- - -  C C C C Cr   rB   c                   $    e Zd ZdZd Zd Zd ZdS )Sha256MemoryAuthPluginz;Class implementing the SHA256_MEMORY authentication plugin.c                     dS )r!   z#SHA256_MEMORY Authentication Pluginr   r$   s    r   r%   zSha256MemoryAuthPlugin.name   s
     54r   c                     dS )r(   SHA256_MEMORYr   r$   s    r   r)   z Sha256MemoryAuthPlugin.auth_name   s	     r   c                    t          | j        t                    r| j                            d          n| j        }t	          j        |                                          }t	          j        t	          j        |                                          |z                                             }t          ||d          }d                    | j	        t          |                    S )a   Hashing for SHA256_MEMORY authentication.

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

        Args:
            data (str): The authentication data.

        Returns:
            str: The authentication response.
        r4       rG   )r7   r   r8   r9   r:   sha256r<   r   r   r   r   r=   s         r   r?   z Sha256MemoryAuthPlugin.auth_data   s     $.#..C4>((11148N 	x((//11w~e44;;==DEELLNN5%,,""4>75>>BBBr   Nr@   r   r   r   rI   rI      sL        EE5 5 5  C C C C Cr   rI   )r-   r:   r   helpersr   r   objectr   r/   rB   rI   r   r   r   <module>rR      s  : 5 4        9 9 9" " " " "V " " "."7 "7 "7 "7 "7 "7 "7 "7JC C C C Cn C C C6#C #C #C #C #C^ #C #C #C #C #Cr   