use std::{fmt, str::FromStr};
use crate::{Error, Result};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AuthMechanism {
External,
Anonymous,
}
impl AuthMechanism {
pub fn as_str(&self) -> &'static str {
match self {
AuthMechanism::External => "EXTERNAL",
AuthMechanism::Anonymous => "ANONYMOUS",
}
}
}
impl fmt::Display for AuthMechanism {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mech = self.as_str();
write!(f, "{mech}")
}
}
impl FromStr for AuthMechanism {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s {
"EXTERNAL" => Ok(AuthMechanism::External),
"ANONYMOUS" => Ok(AuthMechanism::Anonymous),
_ => Err(Error::Handshake(format!("Unsupported mechanism: {s}"))),
}
}
}