use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};
#[derive(Clone, Serialize, Deserialize, Debug)]
enum KeyAlgorithm {
RS256,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
enum KeyType {
RSA,
}
#[allow(dead_code)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub(crate) struct JWK {
kty: KeyType,
alg: Option<KeyAlgorithm>,
kid: Option<String>,
pub(crate) n: String,
pub(crate) e: String,
pub(crate) x5c: Option<Vec<String>>,
}
impl Display for JWK {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "JWK: {:?}", self)
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub(crate) struct JWKS {
keys: Vec<JWK>,
}
impl JWKS {
pub fn find(&self, kid: &str) -> Option<&JWK> {
self.keys.iter().find(|jwk| jwk.kid == Some(kid.into()))
}
}