Skip to main content

fakecloud_kms/
state.rs

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
37pub struct KmsKey {
38    pub key_id: String,
39    pub arn: String,
40    pub creation_date: f64,
41    pub description: String,
42    pub enabled: bool,
43    pub key_usage: String,
44    pub key_spec: String,
45    pub key_manager: String,
46    pub key_state: String,
47    pub deletion_date: Option<f64>,
48    pub tags: HashMap<String, String>,
49    pub policy: String,
50    pub key_rotation_enabled: bool,
51    pub origin: String,
52    pub multi_region: bool,
53    pub rotations: Vec<KeyRotation>,
54    pub signing_algorithms: Option<Vec<String>>,
55    pub encryption_algorithms: Option<Vec<String>>,
56    pub mac_algorithms: Option<Vec<String>>,
57    pub custom_key_store_id: Option<String>,
58    pub imported_key_material: bool,
59    /// Raw bytes of imported key material (used as AES key for encrypt/decrypt).
60    pub imported_material_bytes: Option<Vec<u8>>,
61    /// Deterministic seed for the key (used for DeriveSharedSecret).
62    pub private_key_seed: Vec<u8>,
63    pub primary_region: Option<String>,
64}
65
66pub struct KmsAlias {
67    pub alias_name: String,
68    pub alias_arn: String,
69    pub target_key_id: String,
70    pub creation_date: f64,
71}
72
73pub struct KmsGrant {
74    pub grant_id: String,
75    pub grant_token: String,
76    pub key_id: String,
77    pub grantee_principal: String,
78    pub retiring_principal: Option<String>,
79    pub operations: Vec<String>,
80    pub constraints: Option<serde_json::Value>,
81    pub name: Option<String>,
82    pub creation_date: f64,
83}
84
85pub struct KeyRotation {
86    pub key_id: String,
87    pub rotation_date: f64,
88    pub rotation_type: String,
89}
90
91pub struct CustomKeyStore {
92    pub custom_key_store_id: String,
93    pub custom_key_store_name: String,
94    pub custom_key_store_type: String,
95    pub cloud_hsm_cluster_id: Option<String>,
96    pub trust_anchor_certificate: Option<String>,
97    pub connection_state: String,
98    pub creation_date: f64,
99    pub xks_proxy_uri_endpoint: Option<String>,
100    pub xks_proxy_uri_path: Option<String>,
101    pub xks_proxy_vpc_endpoint_service_name: Option<String>,
102    pub xks_proxy_connectivity: Option<String>,
103}