
    DhO                         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e	      Z
 G d	 d
e
      Z G d de
      Z G d de
      Zd Zy)z5Implementing support for MySQL Authentication Plugins    )sha1N   )errors)PY2isstrc                   0    e Zd ZdZdZdZ	 	 ddZd Zd Zy)	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                 J    || _         || _        || _        || _        || _        y)InitializationN)
_auth_data	_username	_password	_database_ssl_enabled)self	auth_datausernamepassworddatabasessl_enableds         ^/var/www/html/civilisation/venv/lib/python3.12/site-packages/mysql/connector/authentication.py__init__zBaseAuthPlugin.__init__2   s(     $!!!'    c                     t         )zPrepares 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.
        )NotImplementedErrorr   s    r   prepare_passwordzBaseAuthPlugin.prepare_password;   s
     "!r   c                     | j                   r;| j                  s/t        j                  dj	                  | j
                              | j                         S )zReturns 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   s    r   auth_responsezBaseAuthPlugin.auth_responseE   sT     T%6%6''(=(D(D%% )E )' ( ($$&&r   )NNNF)	__name__
__module____qualname____doc__r!   r$   r   r   r%    r   r   r	   r	   !   s(     LKIM"("'r   r	   c                       e Zd ZdZdZdZd Zy)MySQLNativePasswordAuthPluginzBClass implementing the MySQL Native Password authentication pluginFmysql_native_passwordc                    | j                   st        j                  d      | j                  sy| j                  }t	        | j                        r| j                  j                  d      }n| j                  }t        r"t        |      }	 t        | j                         }n|}| j                   }d}	 t        |      j                         }t        |      j                         }t        ||z         j                         }t        r4t        ||      D cg c]  \  }}t        |      t        |      z   }	}}n!t        ||      D cg c]
  \  }}||z   }	}}t        j                  dg|	 }|S # t        $ r t        j                  d      w xY wc c}}w c c}}w # t        $ r)}
t        j                  dj!                  |
            d}
~
ww xY w)z;Prepares and returns password as native MySQL 4.1+ passwordz"Missing authentication data (seed)r   zutf-8zAuthentication data incorrectN20BzFailed scrambling password; {0})r   r   r"   r   r   encoder   buffer	TypeErrorr   digestzipordstructpack	Exceptionr#   )r   r   r   hash4hash1hash2hash3h1h3xoredexcs              r   r   z.MySQLNativePasswordAuthPlugin.prepare_passwordY   s   ''(LMM~~>> ~~,,W5H~~Hh'HM"4??3	  HI	?N))+EK&&(EU*+224E;>ue;LMxBR3r7*MM14UE1BCXb"bCCKK..E
 )  M++,KLLM NC 	?''188=? ?	?sC   
E2 1A#F  !F5F  FF  2FF   	G)$GGNr&   r'   r(   r)   r!   r$   r   r*   r   r   r,   r,   S   s    LL)K&r   r,   c                       e Zd ZdZdZdZd Zy)MySQLClearPasswordAuthPluginzAClass implementing the MySQL Clear Password authentication pluginTmysql_clear_passwordc                     | j                   sy| j                   }t        r&t        |t              r|j	                  d      }|dz   S t        |t
              r|j	                  d      }|dz   S z!Returns password as as clear text    utf8r   r   
isinstanceunicoder0   strr   r   s     r   r   z-MySQLClearPasswordAuthPlugin.prepare_password   b    ~~>>(G,#??62 '!! #&v.H'!!r   NrA   r*   r   r   rC   rC      s    KL(K"r   rC   c                       e Zd ZdZdZdZd Zy)MySQLSHA256PasswordAuthPluginzClass 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.
    Tsha256_passwordc                     | j                   sy| j                   }t        r&t        |t              r|j	                  d      }|dz   S t        |t
              r|j	                  d      }|dz   S rF   rI   rM   s     r   r   z.MySQLSHA256PasswordAuthPlugin.prepare_password   rN   r   NrA   r*   r   r   rP   rP      s     L#K"r   rP   c                     t         j                         D ]  }|j                  | k(  s|c S  t        j                  dj                  |             )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 supported)r	   __subclasses__r$   r   NotSupportedErrorr#   )r$   	authclasss     r   get_auth_pluginrW      sU     $224 	  K/ 
"
"6==kJL Lr   )r)   hashlibr   r6   r
   r   catch23r   r   objectr	   r,   rC   rP   rW   r*   r   r   <module>r[      sN   0 <    /'V /'d,N ,^"> "*"N "2Lr   