use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Profile {
PqPure,
PqHybrid,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ProfileError {
Missing,
Unknown(String),
}
impl fmt::Display for ProfileError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ProfileError::Missing => f.write_str("no crypto profile is configured"),
ProfileError::Unknown(value) => write!(f, "not a known crypto profile: {value:?}"),
}
}
}
impl std::error::Error for ProfileError {}
impl Profile {
pub fn parse(value: &str) -> Result<Profile, ProfileError> {
match value {
"" => Err(ProfileError::Missing),
"pq_pure" => Ok(Profile::PqPure),
"pq_hybrid" => Ok(Profile::PqHybrid),
other => Err(ProfileError::Unknown(other.to_owned())),
}
}
pub fn name(self) -> &'static str {
match self {
Profile::PqPure => "pq_pure",
Profile::PqHybrid => "pq_hybrid",
}
}
pub fn hybrid(self) -> bool {
self == Profile::PqHybrid
}
pub fn sig_alg(self) -> &'static str {
match self {
Profile::PqPure => "ML-DSA-87",
Profile::PqHybrid => "ML-DSA-87-PS384",
}
}
}
impl fmt::Display for Profile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.name())
}
}