sqlx_mysql/protocol/
auth.rs1use std::str::FromStr;
2
3use crate::error::Error;
4
5#[derive(Debug, Copy, Clone)]
6#[allow(clippy::enum_variant_names)]
8pub enum AuthPlugin {
9 MySqlNativePassword,
10 CachingSha2Password,
11 Sha256Password,
12 MySqlClearPassword,
13}
14
15impl AuthPlugin {
16 pub(crate) fn name(self) -> &'static str {
17 match self {
18 AuthPlugin::MySqlNativePassword => "mysql_native_password",
19 AuthPlugin::CachingSha2Password => "caching_sha2_password",
20 AuthPlugin::Sha256Password => "sha256_password",
21 AuthPlugin::MySqlClearPassword => "mysql_clear_password",
22 }
23 }
24}
25
26impl FromStr for AuthPlugin {
27 type Err = Error;
28
29 fn from_str(s: &str) -> Result<Self, Self::Err> {
30 match s {
31 "mysql_native_password" => Ok(AuthPlugin::MySqlNativePassword),
32 "caching_sha2_password" => Ok(AuthPlugin::CachingSha2Password),
33 "sha256_password" => Ok(AuthPlugin::Sha256Password),
34 "mysql_clear_password" => Ok(AuthPlugin::MySqlClearPassword),
35
36 _ => Err(err_protocol!("unknown authentication plugin: {}", s)),
37 }
38 }
39}