a
    ’éi´  ã                   @   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   zÆ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.
    )Úreturnc                 C   s   | j  ¡ d S )zyPrepare and return password as as clear text.

        Returns:
            password (bytes): Prepared password.
        ó    )Z	_passwordÚencode©Úself© r   úW/home/Claro/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 )zÃReturn 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   