B
    Ñš[O  ã               @   s€   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„ de	ƒZ
G d	d
„ d
e
ƒZG dd„ de
ƒZG dd„ de
ƒZdd„ ZdS )z5Implementing support for MySQL Authentication Pluginsé    )Úsha1Né   )Úerrors)ÚPY2Úisstrc               @   s2   e Zd ZdZdZdZddd„Zdd„ Zd	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             C   s"   || _ || _|| _|| _|| _dS )ZInitializationN)Ú
_auth_dataZ	_usernameÚ	_passwordZ	_databaseÚ_ssl_enabled)ÚselfÚ	auth_dataÚusernameÚpasswordZdatabaseZssl_enabled© r   ú¢C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-ioykiiwb\mysql-connector-python-rf\mysql_connector_python_rf-2.2.2.data\purelib\mysql\connector\authentication.pyÚ__init__2   s
    zBaseAuthPlugin.__init__c             C   s   t ‚dS )zåPrepares 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.
        N)ÚNotImplementedError)r   r   r   r   Úprepare_password;   s    zBaseAuthPlugin.prepare_passwordc             C   s(   | j r | js t dj| jd�¡‚|  ¡ S )z°Returns 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   r   r   r   Úauth_responseE   s    zBaseAuthPlugin.auth_response)NNNF)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   !   s    

r   c               @   s    e Zd ZdZdZdZdd„ ZdS )ÚMySQLNativePasswordAuthPluginzBClass implementing the MySQL Native Password authentication pluginFZmysql_native_passwordc       	   
   C   s*  | j st d¡‚| jsdS | j}t| jƒr8| j d¡}n| j}trzt|ƒ}yt| j ƒ}W q„ tk
rv   t d¡‚Y q„X n
|}| j }d}yht	|ƒ 
¡ }t	|ƒ 
¡ }t	|| ƒ 
¡ }trÌdd„ t||ƒD ƒ}ndd„ t||ƒD ƒ}tjd|žŽ }W n4 tk
�r$ } zt d
 |¡¡‚W dd}~X Y nX |S )z;Prepares and returns password as native MySQL 4.1+ passwordz"Missing authentication data (seed)ó    zutf-8zAuthentication data incorrectNc             S   s    g | ]\}}t |ƒt |ƒA ‘qS r   )Úord)Ú.0Úh1Úh3r   r   r   ú
<listcomp>w   s    zBMySQLNativePasswordAuthPlugin.prepare_password.<locals>.<listcomp>c             S   s   g | ]\}}||A ‘qS r   r   )r"   r#   r$   r   r   r   r%   y   s    Ú20BzFailed scrambling password; {0})r&   )r	   r   r   r
   r   Úencoder   ÚbufferÚ	TypeErrorr   ÚdigestÚzipÚstructÚpackÚ	Exceptionr   )	r   r   r   Zhash4Zhash1Zhash2Zhash3ZxoredÚexcr   r   r   r   Y   s:    

z.MySQLNativePasswordAuthPlugin.prepare_passwordN)r   r   r   r   r   r   r   r   r   r   r   r   S   s   r   c               @   s    e Zd ZdZdZdZdd„ ZdS )ÚMySQLClearPasswordAuthPluginzAClass implementing the MySQL Clear Password authentication pluginTZmysql_clear_passwordc             C   sF   | j s
dS | j }tr*t|tƒr>| d¡}nt|tƒr>| d¡}|d S )z!Returns password as as clear textó    Úutf8)r
   r   Ú
isinstanceÚunicoder'   Ústr)r   r   r   r   r   r   ˆ   s    


z-MySQLClearPasswordAuthPlugin.prepare_passwordN)r   r   r   r   r   r   r   r   r   r   r   r0   ‚   s   r0   c               @   s    e Zd ZdZdZdZdd„ ZdS )ÚMySQLSHA256PasswordAuthPluginzÆClass 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.
    TZsha256_passwordc             C   sF   | j s
dS | j }tr*t|tƒr>| d¡}nt|tƒr>| d¡}|d S )z!Returns password as as clear textr1   r2   )r
   r   r3   r4   r'   r5   )r   r   r   r   r   r   ¡   s    


z.MySQLSHA256PasswordAuthPlugin.prepare_passwordN)r   r   r   r   r   r   r   r   r   r   r   r6   —   s   r6   c             C   s4   xt  ¡ D ]}|j| kr
|S q
W t d | ¡¡‚dS )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 supportedN)r   Ú__subclasses__r   r   ZNotSupportedErrorr   )r   Z	authclassr   r   r   Úget_auth_plugin°   s
    

r8   )r   Úhashlibr   r,   r   r   Zcatch23r   r   Úobjectr   r   r0   r6   r8   r   r   r   r   Ú<module>   s   2/