pub mod keystore;
pub(crate) mod validator;
pub use pipeline::ValidationPipeline;
pub use validator::TokenValidator;
mod pipeline;
#[cfg(feature = "async")]
mod async_pipeline;
use crate::{
Algorithm,
JwtError,
};
pub trait VerificationKey {
fn alg(&self) -> Option<Algorithm>;
fn verify(&self, message: &[u8], signature: &[u8]) -> Result<(), JwtError>;
}
pub trait KeyProvider<H: ?Sized, C: ?Sized> {
type Key: VerificationKey;
fn resolve_key(&self, header: &H, claims: &C) -> Result<&Self::Key, JwtError>;
}
pub struct StaticKeyProvider<VK: VerificationKey> {
key: VK,
}
impl<VK: VerificationKey> StaticKeyProvider<VK> {
pub const fn new(key: VK) -> Self {
Self { key }
}
}
impl<H, C, VK: VerificationKey> KeyProvider<H, C> for StaticKeyProvider<VK> {
type Key = VK;
fn resolve_key(&self, _: &H, _: &C) -> Result<&VK, JwtError> {
Ok(&self.key)
}
}
impl<VK> From<VK> for StaticKeyProvider<VK>
where
VK: VerificationKey,
{
fn from(value: VK) -> Self {
Self { key: value }
}
}