haste_server/auth_n/certificates/
mod.rs1use haste_config::{ConfigType, get_config};
2use serde::{Deserialize, Serialize};
3use std::sync::{Arc, LazyLock};
4
5pub mod providers;
6pub mod traits;
7
8#[derive(Serialize, Deserialize, Debug)]
9pub enum JSONWebKeyAlgorithm {
10 RS256,
11}
12
13#[derive(Serialize, Deserialize, Debug)]
14pub enum JSONWebKeyType {
15 RSA,
16}
17
18#[derive(Serialize, Deserialize, Debug)]
19pub struct JSONWebKey {
20 pub kid: String,
21
22 pub alg: JSONWebKeyAlgorithm,
23 pub kty: JSONWebKeyType,
24 pub e: String,
26 pub n: String,
27 pub x5t: Option<String>,
28}
29
30#[derive(Serialize, Deserialize, Debug)]
31pub struct JSONWebKeySet {
32 pub keys: Vec<JSONWebKey>,
33}
34
35static CERTIFICATION_PROVIDER: LazyLock<Arc<dyn traits::CertificationProvider>> =
36 LazyLock::new(|| {
37 let config = get_config(ConfigType::Environment);
38 Arc::new(
39 providers::local::LocalCertifications::new(config.as_ref())
40 .expect("Failed to create LocalCertifications"),
41 ) as Arc<dyn traits::CertificationProvider>
42 });
43
44pub fn get_certification_provider() -> Arc<dyn traits::CertificationProvider> {
45 CERTIFICATION_PROVIDER.clone()
46}