use std::sync::Arc;
use crate::epoch_revocation::EpochRevocation;
use crate::replay_defense::ReplayDefense;
use crate::session_revocation::SessionRevocation;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Algorithm {
EdDSA,
}
impl std::str::FromStr for Algorithm {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"EdDSA" => Ok(Algorithm::EdDSA),
_ => Err(()),
}
}
}
#[derive(Debug, Clone)]
#[allow(dead_code)] pub struct VerifyConfig {
pub(crate) issuer: String,
pub(crate) audience: String,
pub(crate) expected_typ: &'static str,
pub(crate) max_token_size: usize,
pub(crate) algorithms: Vec<Algorithm>,
pub(crate) replay: Option<Arc<dyn ReplayDefense>>,
pub(crate) session: Option<Arc<dyn SessionRevocation>>,
pub(crate) epoch: Option<Arc<dyn EpochRevocation>>,
}
impl VerifyConfig {
pub fn access_token(issuer: impl Into<String>, audience: impl Into<String>) -> Self {
Self {
issuer: issuer.into(),
audience: audience.into(),
expected_typ: "at+jwt",
max_token_size: 8 * 1024,
algorithms: vec![Algorithm::EdDSA],
replay: None,
session: None,
epoch: None,
}
}
#[must_use]
pub fn with_algorithms(mut self, algorithms: Vec<Algorithm>) -> Self {
self.algorithms = algorithms;
self
}
#[must_use]
pub fn with_replay_defense(mut self, port: Arc<dyn ReplayDefense>) -> Self {
self.replay = Some(port);
self
}
#[must_use]
pub fn with_session_revocation(mut self, port: Arc<dyn SessionRevocation>) -> Self {
self.session = Some(port);
self
}
#[must_use]
pub fn with_epoch_revocation(mut self, port: Arc<dyn EpochRevocation>) -> Self {
self.epoch = Some(port);
self
}
}