
    vdO                         d Z ddlmZ ddlZddlmZ ddlmZmZ  G d de	          Z
 G d	 d
e
          Z G d de
          Z G d de
          Zd ZdS )z5Implementing support for MySQL Authentication Plugins    )sha1N   )errors)PY2isstrc                   2    e Zd ZdZdZdZ	 	 ddZd Zd ZdS )	BaseAuthPlugina  Base class for authentication plugins


    Classes inheriting from BaseAuthPlugin should implement the method
    prepare_password(). When instantiating, auth_data argument is
    required. The username, password and database are optional. The
    ssl_enabled argument can be used to tell the plugin whether SSL is
    active or not.

    The method auth_response() method is used to retrieve the password
    which was prepared by prepare_password().
    F Nc                 L    || _         || _        || _        || _        || _        dS )InitializationN)
_auth_data	_username	_password	_database_ssl_enabled)self	auth_datausernamepassworddatabasessl_enableds         Z/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/mysql/connector/authentication.py__init__zBaseAuthPlugin.__init__2   s.     $!!!'    c                     t           )zPrepares and returns password to be send to MySQL

        This method needs to be implemented by classes inheriting from
        this class. It is used by the auth_response() method.

        Raises NotImplementedError.
        )NotImplementedErrorr   s    r   prepare_passwordzBaseAuthPlugin.prepare_password;   s
     "!r   c                     | j         r4| j        s-t          j        d                    | j                            |                                 S )zReturns the prepared password to send to MySQL

        Raises InterfaceError on errors. For example, when SSL is required
        by not enabled.

        Returns str
        z{name} requires SSL)name)requires_sslr   r   InterfaceErrorformatplugin_namer   r   s    r   auth_responsezBaseAuthPlugin.auth_responseE   s_      	(T%6 	('(=(D(D% )E )' )' ( ( ($$&&&r   )NNNF)	__name__
__module____qualname____doc__r!   r$   r   r   r%    r   r   r	   r	   !   sb          LKIM"( ( ( (" " "' ' ' ' 'r   r	   c                        e Zd ZdZdZdZd ZdS )MySQLNativePasswordAuthPluginzBClass implementing the MySQL Native Password authentication pluginFmysql_native_passwordc                 X   | j         st          j        d          | j        sdS | j        }t	          | j                  r| j                            d          }n| j        }t          rGt          |          }	 t          | j                   }n+# t          $ r t          j        d          w xY w|}| j         }d}	 t          |          
                                }t          |          
                                }t          ||z             
                                }t          rd t          ||          D             }nd t          ||          D             }t          j        dg|R  }n9# t          $ r,}t          j        d	                    |                    d}~ww xY w|S )
z;Prepares and returns password as native MySQL 4.1+ passwordz"Missing authentication data (seed)r   zutf-8zAuthentication data incorrectNc                 R    g | ]$\  }}t          |          t          |          z  %S r*   )ord.0h1h3s      r   
<listcomp>zBMySQLNativePasswordAuthPlugin.prepare_password.<locals>.<listcomp>w   s-    MMMxBR3r77*MMMr   c                     g | ]
\  }}||z  S r*   r*   r1   s      r   r5   zBMySQLNativePasswordAuthPlugin.prepare_password.<locals>.<listcomp>y   s     CCCXb"bCCCr   20BzFailed scrambling password; {0})r   r   r"   r   r   encoder   buffer	TypeErrorr   digestzipstructpack	Exceptionr#   )	r   r   r   hash4hash1hash2hash3xoredexcs	            r   r   z.MySQLNativePasswordAuthPlugin.prepare_passwordY   s    	N'(LMMM~ 	3>   	&~,,W55HH~H 	(h''HM"4?33		 M M M+,KLLLM  HI	?NN))++EKK&&((EU*++2244E DMM3ue;L;LMMMCCUE1B1BCCCK....EE 	? 	? 	?'188==? ? ?	? s%   9B B-<B4E1 1
F';'F""F'Nr&   r'   r(   r)   r!   r$   r   r*   r   r   r,   r,   S   s3        LLL)K& & & & &r   r,   c                        e Zd ZdZdZdZd ZdS )MySQLClearPasswordAuthPluginzAClass implementing the MySQL Clear Password authentication pluginTmysql_clear_passwordc                     | j         sdS | j         }t          r+t          |t                    r|                    d          }n*t          |t
                    r|                    d          }|dz   S z!Returns password as as clear text    utf8r   r   
isinstanceunicoder8   strr   r   s     r   r   z-MySQLClearPasswordAuthPlugin.prepare_password   r    ~ 	7> 	/(G,, 3#??622#&& 	/v..H'!!r   NrF   r*   r   r   rH   rH      s3        KKL(K" " " " "r   rH   c                        e Zd ZdZdZdZd ZdS )MySQLSHA256PasswordAuthPluginzClass implementing the MySQL SHA256 authentication plugin

    Note that encrypting using RSA is not supported since the Python
    Standard Library does not provide this OpenSSL functionality.
    Tsha256_passwordc                     | j         sdS | j         }t          r+t          |t                    r|                    d          }n*t          |t
                    r|                    d          }|dz   S rK   rN   rR   s     r   r   z.MySQLSHA256PasswordAuthPlugin.prepare_password   rS   r   NrF   r*   r   r   rU   rU      s9          L#K" " " " "r   rU   c                     t                                           D ]}|j        | k    r|c S t          j        d                    |                     )a.  Return authentication class based on plugin name

    This function returns the class for the authentication plugin plugin_name.
    The returned class is a subclass of BaseAuthPlugin.

    Raises errors.NotSupportedError when plugin_name is not supported.

    Returns subclass of BaseAuthPlugin.
    z,Authentication plugin '{0}' is not supported)r	   __subclasses__r$   r   NotSupportedErrorr#   )r$   	authclasss     r   get_auth_pluginr\      si     $2244  	 K// 0 
"6==kJJL L Lr   )r)   hashlibr   r=   r
   r   catch23r   r   objectr	   r,   rH   rU   r\   r*   r   r   <module>r`      s  0 < ;                     /' /' /' /' /'V /' /' /'d, , , , ,N , , ,^" " " " "> " " "*" " " " "N " " "2L L L L Lr   