Skip to main content

aura_agent/runtime/effects/
storage.rs

1use super::AuraEffectSystem;
2use async_trait::async_trait;
3use aura_core::effects::storage::{StorageError, StorageStats};
4use aura_core::effects::{
5    SecureStorageCapability, SecureStorageEffects, SecureStorageError, SecureStorageLocation,
6    StorageCoreEffects, StorageExtendedEffects,
7};
8use std::collections::HashMap;
9
10// Implementation of StorageEffects
11#[async_trait]
12impl StorageCoreEffects for AuraEffectSystem {
13    async fn store(&self, key: &str, value: Vec<u8>) -> Result<(), StorageError> {
14        self.storage_handler.store(key, value).await
15    }
16
17    async fn retrieve(&self, key: &str) -> Result<Option<Vec<u8>>, StorageError> {
18        self.storage_handler.retrieve(key).await
19    }
20
21    async fn remove(&self, key: &str) -> Result<bool, StorageError> {
22        self.storage_handler.remove(key).await
23    }
24
25    async fn list_keys(&self, prefix: Option<&str>) -> Result<Vec<String>, StorageError> {
26        self.storage_handler.list_keys(prefix).await
27    }
28}
29
30#[async_trait]
31impl StorageExtendedEffects for AuraEffectSystem {
32    async fn exists(&self, key: &str) -> Result<bool, StorageError> {
33        self.storage_handler.exists(key).await
34    }
35
36    async fn store_batch(&self, pairs: HashMap<String, Vec<u8>>) -> Result<(), StorageError> {
37        self.storage_handler.store_batch(pairs).await
38    }
39
40    async fn retrieve_batch(
41        &self,
42        keys: &[String],
43    ) -> Result<HashMap<String, Vec<u8>>, StorageError> {
44        self.storage_handler.retrieve_batch(keys).await
45    }
46
47    async fn clear_all(&self) -> Result<(), StorageError> {
48        self.storage_handler.clear_all().await
49    }
50
51    async fn stats(&self) -> Result<StorageStats, StorageError> {
52        self.storage_handler.stats().await
53    }
54}
55
56// Implementation of SecureStorageEffects
57#[async_trait]
58impl SecureStorageEffects for AuraEffectSystem {
59    async fn secure_store(
60        &self,
61        location: &SecureStorageLocation,
62        key: &[u8],
63        caps: &[SecureStorageCapability],
64    ) -> Result<(), SecureStorageError> {
65        self.crypto
66            .secure_storage()
67            .secure_store(location, key, caps)
68            .await
69    }
70
71    async fn secure_retrieve(
72        &self,
73        location: &SecureStorageLocation,
74        caps: &[SecureStorageCapability],
75    ) -> Result<Vec<u8>, SecureStorageError> {
76        self.crypto
77            .secure_storage()
78            .secure_retrieve(location, caps)
79            .await
80    }
81
82    async fn secure_delete(
83        &self,
84        location: &SecureStorageLocation,
85        caps: &[SecureStorageCapability],
86    ) -> Result<(), SecureStorageError> {
87        self.crypto
88            .secure_storage()
89            .secure_delete(location, caps)
90            .await
91    }
92
93    async fn secure_exists(
94        &self,
95        location: &SecureStorageLocation,
96    ) -> Result<bool, SecureStorageError> {
97        self.crypto.secure_storage().secure_exists(location).await
98    }
99
100    async fn secure_list_keys(
101        &self,
102        namespace: &str,
103        caps: &[SecureStorageCapability],
104    ) -> Result<Vec<String>, SecureStorageError> {
105        self.crypto
106            .secure_storage()
107            .secure_list_keys(namespace, caps)
108            .await
109    }
110
111    async fn secure_generate_key(
112        &self,
113        location: &SecureStorageLocation,
114        context: &str,
115        caps: &[SecureStorageCapability],
116    ) -> Result<Option<Vec<u8>>, SecureStorageError> {
117        self.crypto
118            .secure_storage()
119            .secure_generate_key(location, context, caps)
120            .await
121    }
122
123    async fn secure_create_time_bound_token(
124        &self,
125        location: &SecureStorageLocation,
126        caps: &[SecureStorageCapability],
127        expires_at: &aura_core::time::PhysicalTime,
128    ) -> Result<Vec<u8>, SecureStorageError> {
129        self.crypto
130            .secure_storage()
131            .secure_create_time_bound_token(location, caps, expires_at)
132            .await
133    }
134
135    async fn secure_access_with_token(
136        &self,
137        token: &[u8],
138        location: &SecureStorageLocation,
139    ) -> Result<Vec<u8>, SecureStorageError> {
140        self.crypto
141            .secure_storage()
142            .secure_access_with_token(token, location)
143            .await
144    }
145
146    async fn get_device_attestation(&self) -> Result<Vec<u8>, SecureStorageError> {
147        self.crypto.secure_storage().get_device_attestation().await
148    }
149
150    async fn is_secure_storage_available(&self) -> bool {
151        self.crypto
152            .secure_storage()
153            .is_secure_storage_available()
154            .await
155    }
156
157    fn get_secure_storage_capabilities(&self) -> Vec<String> {
158        self.crypto
159            .secure_storage()
160            .get_secure_storage_capabilities()
161    }
162}