38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
use serde::{Deserialize,Serialize,Deserializer};
|
|
|
|
#[derive(Eq, PartialEq, Clone, Serialize, Debug, Deserialize)]
|
|
pub enum TotpMode {
|
|
Mandatory,
|
|
Optional,
|
|
No,
|
|
}
|
|
impl Default for TotpMode {
|
|
fn default() -> Self {
|
|
TotpMode::No
|
|
}
|
|
}
|
|
impl std::fmt::Display for TotpMode {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
TotpMode::Mandatory => write!(f,"mandatory"),
|
|
TotpMode::Optional => write!(f,"optional"),
|
|
TotpMode::No => write!(f,"no"),
|
|
}
|
|
}
|
|
}
|
|
impl TotpMode {
|
|
pub fn from_str(value: &str) -> TotpMode {
|
|
match value {
|
|
"mandatory" | "Mandaltory" | "required" | "Required" => TotpMode::Mandatory,
|
|
"optional" | "Optional" => TotpMode::Optional,
|
|
"no" | "No" => TotpMode::No,
|
|
_ => TotpMode::default(),
|
|
}
|
|
}
|
|
}
|
|
pub fn deserialize_totp_mode<'de, D>(deserializer: D) -> Result<TotpMode, D::Error>
|
|
where D: Deserializer<'de> {
|
|
let buf = String::deserialize(deserializer)?;
|
|
Ok(TotpMode::from_str(&buf))
|
|
}
|