U
    4Je+                     @   sL   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 G dd deZ
d	S )
z!Base Authentication Plugin class.    )ABC)OptionalUnion   )errors)
StrOrBytesc                   @   sx   e Zd ZU dZdZeed< dZeed< de	e
 e	e e	e e	e edddd	Ze
d
ddZde	e
 e
dddZdS )BaseAuthPlugina  Base class for authentication pluginsF


    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requires_ssl plugin_nameN)	auth_datausernamepassworddatabasessl_enabledreturnc                 C   s:   || _ t|ttfr|dn|| _|| _|| _|| _dS )ZInitializationutf8N)	Z
_auth_data
isinstancebytes	bytearraydecodeZ	_username	_passwordZ	_database_ssl_enabled)selfr   r   r   r   r    r   D/tmp/pip-unpacked-wheel-7_167w8m/mysql/connector/plugins/__init__.py__init__7   s    	zBaseAuthPlugin.__init__)r   c                 C   s,   | j s
dS | j }t|tr$|d}|d S )znPrepare and return password as as clear text.

        Returns:
            bytes: Prepared password.
            r   )r   r   strencode)r   r   r   r   r   prepare_passwordJ   s    

zBaseAuthPlugin.prepare_password)r   r   c                 C   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	   r   r   ZInterfaceErrorr   r    )r   r   r   r   r   auth_responseY   s    zBaseAuthPlugin.auth_response)NNNF)N)__name__
__module____qualname____doc__r	   int__annotations__r   r   r   r   r   boolr   r    r!   r   r   r   r   r   &   s*   
     r   N)r%   abcr   typingr   r   r
   r   typesr   r   r   r   r   r   <module>   s
   