sqlx_core_oldapi/mysql/protocol/
auth.rs

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