confium_store/
keystore.rs1use std::ffi::c_void;
12
13use crate::backend::{Compartment, Options, StoreInstance, find};
14use crate::error::Result;
15
16pub struct Keystore {
22 instance: Box<dyn StoreInstance>,
23}
24
25impl Keystore {
26 pub fn new(backend_name: &str, opts: &Options) -> Result<Self> {
29 let backend = find(backend_name)?;
30 let instance = backend.open(opts)?;
31 Ok(Keystore { instance })
32 }
33
34 pub fn from_instance(instance: Box<dyn StoreInstance>) -> Self {
37 Keystore { instance }
38 }
39
40 pub fn instance_mut(&mut self) -> &mut dyn StoreInstance {
43 self.instance.as_mut()
44 }
45
46 pub fn instance(&self) -> &dyn StoreInstance {
49 self.instance.as_ref()
50 }
51
52 pub fn put_secret(
53 &mut self,
54 module: &str,
55 app: &str,
56 key_id: &str,
57 key: *mut c_void,
58 ) -> Result<()> {
59 self.instance.put_secret(module, app, key_id, key)
60 }
61
62 pub fn get_secret(&self, module: &str, app: &str, key_id: &str) -> Result<*mut c_void> {
63 self.instance.get_secret(module, app, key_id)
64 }
65
66 pub fn put_public(
67 &mut self,
68 module: &str,
69 app: &str,
70 identity: &str,
71 key: *mut c_void,
72 sig: &[u8],
73 ) -> Result<()> {
74 self.instance.put_public(module, app, identity, key, sig)
75 }
76
77 pub fn get_public(
78 &self,
79 module: &str,
80 app: &str,
81 identity: &str,
82 ) -> Result<(*mut c_void, Vec<u8>)> {
83 self.instance.get_public(module, app, identity)
84 }
85
86 pub fn sign(
89 &self,
90 module: &str,
91 app: &str,
92 key_id: &str,
93 algorithm: &str,
94 message: &[u8],
95 ) -> Result<Vec<u8>> {
96 self.instance.sign(module, app, key_id, algorithm, message)
97 }
98
99 pub fn enumerate(
100 &self,
101 module: &str,
102 app: &str,
103 compartment: Compartment,
104 ) -> Result<Vec<(*mut c_void, String)>> {
105 self.instance.enumerate(module, app, compartment)
106 }
107}