Skip to main content

bitwarden_uniffi/vault/
ciphers.rs

1use bitwarden_collections::collection::CollectionId;
2use bitwarden_core::OrganizationId;
3use bitwarden_vault::{
4    Cipher, CipherListView, CipherView, DecryptCipherListResult, EncryptionContext,
5};
6
7use crate::Result;
8
9#[allow(missing_docs)]
10#[derive(uniffi::Object)]
11pub struct CiphersClient(pub(crate) bitwarden_vault::CiphersClient);
12
13#[uniffi::export(async_runtime = "tokio")]
14impl CiphersClient {
15    /// Encrypt cipher
16    pub async fn encrypt(&self, cipher_view: CipherView) -> Result<EncryptionContext> {
17        Ok(self.0.encrypt(cipher_view).await?)
18    }
19
20    /// Decrypt cipher
21    pub async fn decrypt(&self, cipher: Cipher) -> Result<CipherView> {
22        Ok(self.0.decrypt(cipher).await?)
23    }
24
25    /// Decrypt cipher list
26    pub async fn decrypt_list(&self, ciphers: Vec<Cipher>) -> Result<Vec<CipherListView>> {
27        Ok(self.0.decrypt_list(ciphers).await?)
28    }
29
30    /// Decrypt cipher list with failures
31    /// Returns both successfully decrypted ciphers and any that failed to decrypt
32    // Note that this function still needs to return a Result, as the parameter conversion can still
33    // fail
34    pub async fn decrypt_list_with_failures(
35        &self,
36        ciphers: Vec<Cipher>,
37    ) -> Result<DecryptCipherListResult> {
38        Ok(self.0.decrypt_list_with_failures(ciphers).await)
39    }
40
41    /// Move a cipher to an organization, reencrypting the cipher key if necessary
42    pub fn move_to_organization(
43        &self,
44        cipher: CipherView,
45        organization_id: OrganizationId,
46    ) -> Result<CipherView> {
47        Ok(self.0.move_to_organization(cipher, organization_id)?)
48    }
49
50    /// Prepare ciphers for bulk share to an organization
51    pub async fn prepare_ciphers_for_bulk_share(
52        &self,
53        ciphers: Vec<CipherView>,
54        organization_id: OrganizationId,
55        collection_ids: Vec<CollectionId>,
56    ) -> Result<Vec<EncryptionContext>> {
57        Ok(self
58            .0
59            .prepare_ciphers_for_bulk_share(ciphers, organization_id, collection_ids)
60            .await?)
61    }
62}