a
    lJh                     @   sd   d Z ddlmZmZmZ ddlmZ ddlmZ ddlmZ erLddl	m
Z
 d	ZG d
d	 d	eZdS )z&SHA256 Password Authentication Plugin.    )TYPE_CHECKINGAnyOptional   )errors)logger   )MySQLAuthPlugin)MySQLSocketMySQLSHA256PasswordAuthPluginc                   @   sl   e Zd ZdZedddZeedddZee	dddZ
eeee d	d
dZdeeedddZdS )r   zClass 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.
    )returnc                 C   s   | j  d S )zyPrepare and return password as as clear text.

        Returns:
            password (bytes): Prepared password.
            )Z	_passwordencodeself r   Y/var/www/shaz/venv/lib/python3.9/site-packages/mysql/connector/plugins/sha256_password.py_prepare_password2   s    z/MySQLSHA256PasswordAuthPlugin._prepare_passwordc                 C   s   dS )zPlugin official name.Zsha256_passwordr   r   r   r   r   name:   s    z"MySQLSHA256PasswordAuthPlugin.namec                 C   s   dS )z'Signals whether or not SSL is required.Tr   r   r   r   r   requires_ssl?   s    z*MySQLSHA256PasswordAuthPlugin.requires_ssl)	auth_datakwargsr   c                 K   s&   | j r| jst| j d|  S )zReturn the prepared password to send to MySQL.

        Raises:
            InterfaceError: When SSL is required by not enabled.

        Returns:
            str: The prepared password.
        z requires SSL)r   Zssl_enabledr   InterfaceErrorr   r   )r   r   r   r   r   r   auth_responseD   s    	z+MySQLSHA256PasswordAuthPlugin.auth_responser
   )sockr   r   r   c                 K   s\   | j |fi |}|du r$tdtd|t| || t| }td| |S )aS  Handles server's `auth switch request` response.

        Args:
            sock: Pointer to the socket connection.
            auth_data: Plugin provided data (extracted from a packet
                       representing an `auth switch request` response).
            kwargs: Custom configuration to be passed to the auth plugin
                    when invoked. The parameters defined here will override the ones
                    defined in the auth plugin itself.

        Returns:
            packet: Last server's response after back-and-forth
                    communication.
        NzGot a NULL auth responsez# request: %s size: %sz# server response packet: %s)	r   r   r   r   debuglensendbytesrecv)r   r   r   r   responseZpktr   r   r   auth_switch_responseQ   s    

z2MySQLSHA256PasswordAuthPlugin.auth_switch_responseN)__name__
__module____qualname____doc__r   r   propertystrr   boolr   r   r   r   r!   r   r   r   r   r   +   s   N)r%   typingr   r   r    r   r   r	   networkr
   ZAUTHENTICATION_PLUGIN_CLASSr   r   r   r   r   <module>   s   