1use std::collections::HashMap;
2use std::sync::Arc;
3
4use parking_lot::RwLock;
5
6pub type SharedKmsState = Arc<RwLock<KmsState>>;
7
8pub struct KmsState {
9 pub account_id: String,
10 pub region: String,
11 pub keys: HashMap<String, KmsKey>,
12 pub aliases: HashMap<String, KmsAlias>,
13 pub grants: Vec<KmsGrant>,
14 pub custom_key_stores: HashMap<String, CustomKeyStore>,
15}
16
17impl KmsState {
18 pub fn new(account_id: &str, region: &str) -> Self {
19 Self {
20 account_id: account_id.to_string(),
21 region: region.to_string(),
22 keys: HashMap::new(),
23 aliases: HashMap::new(),
24 grants: Vec::new(),
25 custom_key_stores: HashMap::new(),
26 }
27 }
28
29 pub fn reset(&mut self) {
30 self.keys.clear();
31 self.aliases.clear();
32 self.grants.clear();
33 self.custom_key_stores.clear();
34 }
35}
36
37#[derive(Clone)]
38pub struct KmsKey {
39 pub key_id: String,
40 pub arn: String,
41 pub creation_date: f64,
42 pub description: String,
43 pub enabled: bool,
44 pub key_usage: String,
45 pub key_spec: String,
46 pub key_manager: String,
47 pub key_state: String,
48 pub deletion_date: Option<f64>,
49 pub tags: HashMap<String, String>,
50 pub policy: String,
51 pub key_rotation_enabled: bool,
52 pub origin: String,
53 pub multi_region: bool,
54 pub rotations: Vec<KeyRotation>,
55 pub signing_algorithms: Option<Vec<String>>,
56 pub encryption_algorithms: Option<Vec<String>>,
57 pub mac_algorithms: Option<Vec<String>>,
58 pub custom_key_store_id: Option<String>,
59 pub imported_key_material: bool,
60 pub imported_material_bytes: Option<Vec<u8>>,
62 pub private_key_seed: Vec<u8>,
64 pub primary_region: Option<String>,
65}
66
67pub struct KmsAlias {
68 pub alias_name: String,
69 pub alias_arn: String,
70 pub target_key_id: String,
71 pub creation_date: f64,
72}
73
74pub struct KmsGrant {
75 pub grant_id: String,
76 pub grant_token: String,
77 pub key_id: String,
78 pub grantee_principal: String,
79 pub retiring_principal: Option<String>,
80 pub operations: Vec<String>,
81 pub constraints: Option<serde_json::Value>,
82 pub name: Option<String>,
83 pub creation_date: f64,
84}
85
86#[derive(Clone)]
87pub struct KeyRotation {
88 pub key_id: String,
89 pub rotation_date: f64,
90 pub rotation_type: String,
91}
92
93pub struct CustomKeyStore {
94 pub custom_key_store_id: String,
95 pub custom_key_store_name: String,
96 pub custom_key_store_type: String,
97 pub cloud_hsm_cluster_id: Option<String>,
98 pub trust_anchor_certificate: Option<String>,
99 pub connection_state: String,
100 pub creation_date: f64,
101 pub xks_proxy_uri_endpoint: Option<String>,
102 pub xks_proxy_uri_path: Option<String>,
103 pub xks_proxy_vpc_endpoint_service_name: Option<String>,
104 pub xks_proxy_connectivity: Option<String>,
105}