Skip to main content

ppoppo_token/
key_set.rs

1//! Server-pinned set of decoding keys indexed by `kid`.
2//!
3//! `kid` resolution is M12: the engine MUST look the key up in this struct
4//! and never follow `jku`/`x5u` URLs (those headers fail M07/M08 first).
5
6use jsonwebtoken::DecodingKey;
7use std::collections::HashMap;
8
9pub struct KeySet {
10    keys: HashMap<String, DecodingKey>,
11}
12
13impl KeySet {
14    #[must_use]
15    pub fn new() -> Self {
16        Self {
17            keys: HashMap::new(),
18        }
19    }
20
21    pub fn insert(&mut self, kid: impl Into<String>, key: DecodingKey) {
22        self.keys.insert(kid.into(), key);
23    }
24
25    pub(crate) fn get(&self, kid: &str) -> Option<&DecodingKey> {
26        self.keys.get(kid)
27    }
28}
29
30impl Default for KeySet {
31    fn default() -> Self {
32        Self::new()
33    }
34}