1use num_bigint::BigUint;
4use serde::{Deserialize, Deserializer};
5use std::collections::HashMap;
6
7static KEYS_JSON: &'static str = include_str!("../keys.json");
8
9fn deserialize_hex_as_biguint<'de, D>(deserializer: D) -> Result<BigUint, D::Error>
10where
11 D: Deserializer<'de>,
12{
13 let buf = String::deserialize(deserializer)?;
14
15 BigUint::parse_bytes(buf.as_bytes(), 16).ok_or(serde::de::Error::custom(format!(
16 "failed to parse exponent hex"
17 )))
18}
19
20#[derive(Deserialize, Debug)]
21pub struct IssuerKey {
22 pub is_private: bool,
23 pub is_test: bool,
24 pub issuer_id: String,
25 #[serde(
26 rename = "modulus_hex",
27 deserialize_with = "deserialize_hex_as_biguint"
28 )]
29 pub modulus: BigUint,
30 #[serde(
31 rename = "public_exponent_hex",
32 deserialize_with = "deserialize_hex_as_biguint"
33 )]
34 pub public_exponent: BigUint,
35 pub public_key_x509: Option<String>,
36}
37
38#[derive(Debug)]
39pub struct IssuerKeyStore {
40 pub keys: HashMap<String, Vec<IssuerKey>>,
41}
42
43impl IssuerKeyStore {
44 pub fn new() -> Self {
45 let keys = serde_json::from_str(KEYS_JSON).expect("failed to parse embedded keys.json");
46 Self { keys }
47 }
48
49 }