bitwarden_uniffi/vault/
ciphers.rs1use bitwarden_collections::collection::CollectionId;
2use bitwarden_core::OrganizationId;
3use bitwarden_vault::{
4 Cipher, CipherCreateRequest, CipherEditRequest, CipherId, CipherListView,
5 CipherPartialEditRequest, CipherView, DecryptCipherListResult, DecryptCipherResult,
6 EncryptionContext, FolderId,
7};
8
9use crate::Result;
10
11#[allow(missing_docs)]
12#[derive(uniffi::Object)]
13pub struct CiphersClient(pub(crate) bitwarden_vault::CiphersClient);
14
15#[uniffi::export(async_runtime = "tokio")]
16impl CiphersClient {
17 pub async fn encrypt(&self, cipher_view: CipherView) -> Result<EncryptionContext> {
19 Ok(self.0.encrypt(cipher_view).await?)
20 }
21
22 pub async fn decrypt(&self, cipher: Cipher) -> Result<CipherView> {
24 Ok(self.0.decrypt(cipher).await?)
25 }
26
27 pub async fn decrypt_list(&self, ciphers: Vec<Cipher>) -> Result<Vec<CipherListView>> {
29 Ok(self.0.decrypt_list(ciphers.into()).await?)
30 }
31
32 pub async fn encrypt_list(
34 &self,
35 cipher_views: Vec<CipherView>,
36 ) -> Result<Vec<EncryptionContext>> {
37 Ok(self.0.encrypt_list(cipher_views).await?)
38 }
39
40 pub async fn decrypt_list_with_failures(
45 &self,
46 ciphers: Vec<Cipher>,
47 ) -> Result<DecryptCipherListResult> {
48 Ok(self.0.decrypt_list_with_failures(ciphers.into()).await?)
49 }
50
51 pub fn move_to_organization(
53 &self,
54 cipher: CipherView,
55 organization_id: OrganizationId,
56 ) -> Result<CipherView> {
57 Ok(self.0.move_to_organization(cipher, organization_id)?)
58 }
59
60 pub async fn prepare_ciphers_for_bulk_share(
62 &self,
63 ciphers: Vec<CipherView>,
64 organization_id: OrganizationId,
65 collection_ids: Vec<CollectionId>,
66 ) -> Result<Vec<EncryptionContext>> {
67 Ok(self
68 .0
69 .prepare_ciphers_for_bulk_share(ciphers, organization_id, collection_ids)
70 .await?)
71 }
72
73 pub async fn decrypt_list_full_with_failures(
78 &self,
79 ciphers: Vec<Cipher>,
80 ) -> Result<DecryptCipherResult> {
81 Ok(self
82 .0
83 .decrypt_list_full_with_failures(ciphers.into())
84 .await?)
85 }
86
87 pub async fn create(&self, request: CipherCreateRequest) -> Result<CipherView> {
89 Ok(self.0.create(request).await?)
90 }
91
92 pub async fn edit(&self, request: CipherEditRequest) -> Result<CipherView> {
94 Ok(self.0.edit(request).await?)
95 }
96
97 pub async fn edit_gated(
102 &self,
103 request: CipherEditRequest,
104 original_cipher_view: CipherView,
105 ) -> Result<CipherView> {
106 Ok(self.0.edit_gated(request, original_cipher_view).await?)
107 }
108
109 pub async fn edit_partial(&self, request: CipherPartialEditRequest) -> Result<CipherView> {
111 Ok(self.0.edit_partial(request).await?)
112 }
113
114 pub async fn update_collection(
116 &self,
117 cipher_id: CipherId,
118 collection_ids: Vec<CollectionId>,
119 ) -> Result<CipherView> {
120 Ok(self.0.update_collection(cipher_id, collection_ids).await?)
121 }
122
123 pub async fn get(&self, cipher_id: CipherId) -> Result<CipherView> {
125 Ok(self.0.get(cipher_id).await?)
126 }
127
128 pub async fn list(&self) -> Result<DecryptCipherListResult> {
131 Ok(self.0.list().await?)
132 }
133
134 pub async fn get_all(&self) -> Result<DecryptCipherResult> {
137 Ok(self.0.get_all().await?)
138 }
139
140 pub async fn delete(&self, cipher_id: CipherId) -> Result<()> {
142 Ok(self.0.delete(cipher_id).await?)
143 }
144
145 pub async fn delete_many(
147 &self,
148 cipher_ids: Vec<CipherId>,
149 organization_id: Option<OrganizationId>,
150 ) -> Result<()> {
151 Ok(self.0.delete_many(cipher_ids, organization_id).await?)
152 }
153
154 pub async fn soft_delete(&self, cipher_id: CipherId) -> Result<()> {
156 Ok(self.0.soft_delete(cipher_id).await?)
157 }
158
159 pub async fn soft_delete_many(
161 &self,
162 cipher_ids: Vec<CipherId>,
163 organization_id: Option<OrganizationId>,
164 ) -> Result<()> {
165 Ok(self.0.soft_delete_many(cipher_ids, organization_id).await?)
166 }
167
168 pub async fn restore(&self, cipher_id: CipherId) -> Result<CipherView> {
170 Ok(self.0.restore(cipher_id).await?)
171 }
172
173 pub async fn restore_many(&self, cipher_ids: Vec<CipherId>) -> Result<DecryptCipherListResult> {
175 Ok(self.0.restore_many(cipher_ids).await?)
176 }
177
178 pub async fn share_cipher(
180 &self,
181 cipher_view: CipherView,
182 organization_id: OrganizationId,
183 collection_ids: Vec<CollectionId>,
184 original_cipher_view: Option<CipherView>,
185 ) -> Result<CipherView> {
186 Ok(self
187 .0
188 .share_cipher(
189 cipher_view,
190 organization_id,
191 collection_ids,
192 original_cipher_view,
193 )
194 .await?)
195 }
196
197 pub async fn share_ciphers_bulk(
199 &self,
200 cipher_views: Vec<CipherView>,
201 organization_id: OrganizationId,
202 collection_ids: Vec<CollectionId>,
203 ) -> Result<Vec<CipherView>> {
204 Ok(self
205 .0
206 .share_ciphers_bulk(cipher_views, organization_id, collection_ids)
207 .await?)
208 }
209
210 pub async fn move_many(
212 &self,
213 cipher_ids: Vec<CipherId>,
214 folder_id: Option<FolderId>,
215 ) -> Result<()> {
216 Ok(self.0.move_many(cipher_ids, folder_id).await?)
217 }
218
219 pub async fn bulk_update_collections(
221 &self,
222 organization_id: OrganizationId,
223 cipher_ids: Vec<CipherId>,
224 collection_ids: Vec<CollectionId>,
225 remove_collections: bool,
226 ) -> Result<()> {
227 Ok(self
228 .0
229 .bulk_update_collections(
230 organization_id,
231 cipher_ids,
232 collection_ids,
233 remove_collections,
234 )
235 .await?)
236 }
237}