1mod cache;
5#[cfg(feature = "http-jwks-provider")]
6pub mod http_jwks_provider;
7
8use alloc::vec::Vec;
9use core::convert::Infallible;
10
11use serde::{Deserialize, Serialize};
12
13use crate::jwk::JsonWebKey;
14
15pub use cache::JsonWebKeyCache;
16
17pub trait JsonWebKeySetProvider: Clone + Send + Sync + 'static {
19 type Error: core::error::Error + 'static;
21
22 fn fetch(&self) -> impl Future<Output = Result<JsonWebKeySet, Self::Error>> + Send + Sync;
24}
25
26#[derive(Deserialize, Serialize, Debug, Clone)]
28#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
29pub struct JsonWebKeySet {
30 pub keys: Vec<JsonWebKey>,
32}
33
34#[derive(Clone, Debug)]
36pub struct StaticJsonWebKeySet {
37 jwks: JsonWebKeySet,
39}
40impl StaticJsonWebKeySet {
41 pub fn new(jwks: JsonWebKeySet) -> Self {
43 Self { jwks }
44 }
45}
46impl JsonWebKeySetProvider for StaticJsonWebKeySet {
47 type Error = Infallible;
48
49 async fn fetch(&self) -> Result<JsonWebKeySet, Self::Error> {
50 Ok(self.jwks.clone())
51 }
52}