localauthentication/
la_right_store.rs1use crate::ffi;
4use crate::la_error::Result;
5use crate::la_persisted_right::LAPersistedRight;
6use crate::la_right::LARight;
7use crate::private::{bridge_ptr, bridge_unit, cstring, OwnedHandle};
8
9#[derive(Debug)]
11pub struct LARightStore {
12 handle: OwnedHandle,
13}
14
15impl LARightStore {
16 pub fn shared() -> Result<Self> {
22 let raw = bridge_ptr(|out, error_out| unsafe {
23 ffi::la_right_store::la_right_store_shared(out, error_out)
24 })?;
25 Ok(Self {
26 handle: OwnedHandle::new(raw, ffi::la_right_store::la_right_store_release),
27 })
28 }
29
30 pub fn right_for_identifier(&self, identifier: &str) -> Result<LAPersistedRight> {
36 let identifier = cstring(identifier)?;
37 Ok(LAPersistedRight::from_raw(bridge_ptr(
38 |out, error_out| unsafe {
39 ffi::la_right_store::la_right_store_right_for_identifier(
40 self.handle.as_ptr(),
41 identifier.as_ptr(),
42 out,
43 error_out,
44 )
45 },
46 )?))
47 }
48
49 pub fn save_right(&self, right: &LARight, identifier: &str) -> Result<LAPersistedRight> {
55 let identifier = cstring(identifier)?;
56 Ok(LAPersistedRight::from_raw(bridge_ptr(
57 |out, error_out| unsafe {
58 ffi::la_right_store::la_right_store_save_right(
59 self.handle.as_ptr(),
60 right.as_ptr(),
61 identifier.as_ptr(),
62 out,
63 error_out,
64 )
65 },
66 )?))
67 }
68
69 pub fn save_right_with_secret(
75 &self,
76 right: &LARight,
77 identifier: &str,
78 secret: &[u8],
79 ) -> Result<LAPersistedRight> {
80 let identifier = cstring(identifier)?;
81 Ok(LAPersistedRight::from_raw(bridge_ptr(
82 |out, error_out| unsafe {
83 ffi::la_right_store::la_right_store_save_right_with_secret(
84 self.handle.as_ptr(),
85 right.as_ptr(),
86 identifier.as_ptr(),
87 secret.as_ptr(),
88 secret.len(),
89 out,
90 error_out,
91 )
92 },
93 )?))
94 }
95
96 pub fn remove_right(&self, right: &LAPersistedRight) -> Result<()> {
102 bridge_unit(|error_out| unsafe {
103 ffi::la_right_store::la_right_store_remove_right(
104 self.handle.as_ptr(),
105 right.as_ptr(),
106 error_out,
107 )
108 })
109 }
110
111 pub fn remove_right_for_identifier(&self, identifier: &str) -> Result<()> {
117 let identifier = cstring(identifier)?;
118 bridge_unit(|error_out| unsafe {
119 ffi::la_right_store::la_right_store_remove_right_for_identifier(
120 self.handle.as_ptr(),
121 identifier.as_ptr(),
122 error_out,
123 )
124 })
125 }
126
127 pub fn remove_all_rights(&self) -> Result<()> {
133 bridge_unit(|error_out| unsafe {
134 ffi::la_right_store::la_right_store_remove_all_rights(self.handle.as_ptr(), error_out)
135 })
136 }
137}