File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
src/MySqlConnector/Authentication Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+
4
+ namespace MySqlConnector . Authentication
5
+ {
6
+ /// <summary>
7
+ /// A registry of known authentication plugins.
8
+ /// </summary>
9
+ public static class AuthenticationPlugins
10
+ {
11
+ /// <summary>
12
+ /// Registers the specified authentication plugin. The name of this plugin must be unique.
13
+ /// </summary>
14
+ /// <param name="plugin">The authentication plugin.</param>
15
+ public static void Register ( IAuthenticationPlugin plugin )
16
+ {
17
+ if ( plugin is null )
18
+ throw new ArgumentNullException ( nameof ( plugin ) ) ;
19
+ if ( string . IsNullOrEmpty ( plugin . Name ) )
20
+ throw new ArgumentException ( "Invalid plugin name." , nameof ( plugin ) ) ;
21
+
22
+ lock ( s_lock )
23
+ s_plugins . Add ( plugin . Name , plugin ) ;
24
+ }
25
+
26
+ internal static bool TryGetPlugin ( string name , out IAuthenticationPlugin plugin )
27
+ {
28
+ lock ( s_lock )
29
+ return s_plugins . TryGetValue ( name , out plugin ) ;
30
+ }
31
+
32
+ static readonly object s_lock = new object ( ) ;
33
+ static readonly Dictionary < string , IAuthenticationPlugin > s_plugins = new Dictionary < string , IAuthenticationPlugin > ( ) ;
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ using System ;
2
+
3
+ namespace MySqlConnector . Authentication
4
+ {
5
+ /// <summary>
6
+ /// The primary interface implemented by an authentication plugin.
7
+ /// </summary>
8
+ public interface IAuthenticationPlugin
9
+ {
10
+ /// <summary>
11
+ /// The authentication plugin name.
12
+ /// </summary>
13
+ string Name { get ; }
14
+
15
+ /// <summary>
16
+ /// Creates the authentication response.
17
+ /// </summary>
18
+ /// <param name="password">The client's password.</param>
19
+ /// <param name="authenticationData">The authentication data supplied by the server; this is the <code>auth method data</code>
20
+ /// from the <a href="https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchRequest">Authentication
21
+ /// Method Switch Request Packet</a>.</param>
22
+ /// <returns></returns>
23
+ byte [ ] CreateResponse ( string password , ReadOnlySpan < byte > authenticationData ) ;
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments