B
    Ñš[Ý	  ã               @   s<   d Z ddlZddlZddlmZmZmZ G dd„ deƒZdS )z.Implementation of MySQL Authentication Plugin.é    Né   )ÚPY3ÚUNICODE_TYPESÚhexlifyc               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚMySQL41AuthPluginc             C   s$   || _ t|tƒr| d¡n|| _d S )Nzutf-8)Ú	_usernameÚ
isinstancer   ÚencodeÚ	_password)ÚselfÚusernameÚpassword© r   ú™C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-ioykiiwb\mysql-connector-python-rf\mysql_connector_python_rf-2.2.2.data\purelib\mysqlx\authentication.pyÚ__init__!   s    zMySQL41AuthPlugin.__init__c             C   s   dS )NzMySQL 4.1 Authentication Pluginr   )r   r   r   r   Úname&   s    zMySQL41AuthPlugin.namec             C   s   dS )NZMYSQL41r   )r   r   r   r   Ú	auth_name)   s    zMySQL41AuthPlugin.auth_namec             C   s<   t rdd„ t||ƒD ƒ}ndd„ t||ƒD ƒ}tjd|žŽ S )zmEncrypt/Decrypt function used for password encryption in
        authentication, using a simple XOR.
        c             S   s   g | ]\}}||A ‘qS r   r   )Ú.0Úh1Úh2r   r   r   ú
<listcomp>1   s    z0MySQL41AuthPlugin.xor_string.<locals>.<listcomp>c             S   s    g | ]\}}t |ƒt |ƒA ‘qS r   )Úord)r   r   r   r   r   r   r   3   s    Ú20B)r   )r   ÚzipÚstructÚpack)r   Zhash1Zhash2Zxoredr   r   r   Ú
xor_string,   s    zMySQL41AuthPlugin.xor_stringc             C   sd   | j rRt | j ¡ ¡ }t |¡ ¡ }|  |t || ¡ ¡ ¡}d d| jt|ƒ¡S d d| j¡S dS )z-Hashing for MySQL 4.1 authentication
        z{0} {1} *{2} Ú z{0} {1} N)r
   ÚhashlibÚsha1Údigestr   Úformatr   r   )r   Údatar   r   Zauth_responser   r   r   Úbuild_authentication_response6   s    

z/MySQL41AuthPlugin.build_authentication_responseN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r#   r   r   r   r   r       s
   
r   )	Ú__doc__r   r   Úcompatr   r   r   Úobjectr   r   r   r   r   Ú<module>   s   