use std::collections::HashSet;
use std::time::Duration;
use jsonwebtoken::Algorithm;
#[derive(Debug, Clone)]
pub struct VerifierConfig {
pub trusted_issuers: HashSet<String>,
pub allowed_algs: Vec<Algorithm>,
pub max_clock_skew: Duration,
pub max_signature_lifetime: Duration,
pub audience: String,
}
impl VerifierConfig {
pub fn new(
trusted_issuers: impl IntoIterator<Item = impl Into<String>>,
allowed_algs: impl IntoIterator<Item = Algorithm>,
max_clock_skew: Duration,
max_signature_lifetime: Duration,
audience: impl Into<String>,
) -> Self {
let allowed_algs: Vec<Algorithm> = allowed_algs
.into_iter()
.filter(|alg| !is_symmetric(*alg))
.collect();
Self {
trusted_issuers: trusted_issuers.into_iter().map(Into::into).collect(),
allowed_algs,
max_clock_skew,
max_signature_lifetime,
audience: audience.into(),
}
}
}
pub(crate) fn is_symmetric(alg: Algorithm) -> bool {
matches!(alg, Algorithm::HS256 | Algorithm::HS384 | Algorithm::HS512)
}