| 1 | use std::str::FromStr; |
| 2 | |
| 3 | use crate::error::Error; |
| 4 | |
| 5 | #[derive(Debug, Copy, Clone)] |
| 6 | // These have all the same suffix but they match the auth plugin names. |
| 7 | #[allow(clippy::enum_variant_names)] |
| 8 | pub enum AuthPlugin { |
| 9 | MySqlNativePassword, |
| 10 | CachingSha2Password, |
| 11 | Sha256Password, |
| 12 | MySqlClearPassword, |
| 13 | } |
| 14 | |
| 15 | impl 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 | |
| 26 | impl 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 | } |