use std::{error::Error, time::SystemTime};
use crate::otp;
pub trait OtpStore {
fn validate(&mut self, otp_str: &str, now: SystemTime) -> Result<(), StoreError>;
}
#[derive(Debug)]
pub enum StoreError {
UnknownPublicId,
Validation(otp::ValidationError),
Otp(otp::Error),
Other(Box<dyn Error>),
}
impl std::error::Error for StoreError {}
impl std::fmt::Display for StoreError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
StoreError::UnknownPublicId => write!(f, "Unknown PublicID"),
StoreError::Validation(err) => write!(f, "{err}"),
StoreError::Otp(err) => write!(f, "{err}"),
StoreError::Other(err) => write!(f, "{err}"),
}
}
}