#[cfg(any(feature = "app-server-types", feature = "authnz-server-types"))]
use impulse_server_kit::salvo;
#[cfg(any(feature = "app-server-types", feature = "authnz-server-types"))]
use salvo::oapi::ToSchema;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, PartialEq, Eq, Hash, Clone, Debug, Default)]
#[cfg_attr(any(feature = "app-server-types", feature = "authnz-server-types"), derive(ToSchema))]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum TOTPAlgorithm {
#[default]
Sha1,
Sha256,
Sha512,
}
impl TOTPAlgorithm {
pub fn from_unchecked(alg: &str) -> Self {
match alg {
"SHA1" => Self::Sha1,
"SHA256" => Self::Sha256,
"SHA512" => Self::Sha512,
_ => unreachable!(),
}
}
pub fn into_totp_rs(&self) -> authnz_totp::Algorithm {
match self {
Self::Sha1 => authnz_totp::Algorithm::SHA1,
Self::Sha256 => authnz_totp::Algorithm::SHA256,
Self::Sha512 => authnz_totp::Algorithm::SHA512,
}
}
}
impl std::fmt::Display for TOTPAlgorithm {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Sha1 => f.write_str("SHA1"),
Self::Sha256 => f.write_str("SHA256"),
Self::Sha512 => f.write_str("SHA512"),
}
}
}