bitwarden_uniffi/vault/
attachments.rs

1use std::path::Path;
2
3use bitwarden_vault::{Attachment, AttachmentEncryptResult, AttachmentView, Cipher};
4
5use crate::Result;
6
7#[derive(uniffi::Object)]
8pub struct AttachmentsClient(pub(crate) bitwarden_vault::AttachmentsClient);
9
10#[uniffi::export]
11impl AttachmentsClient {
12    /// Encrypt an attachment file in memory
13    pub fn encrypt_buffer(
14        &self,
15        cipher: Cipher,
16        attachment: AttachmentView,
17        buffer: Vec<u8>,
18    ) -> Result<AttachmentEncryptResult> {
19        Ok(self.0.encrypt_buffer(cipher, attachment, &buffer)?)
20    }
21
22    /// Encrypt an attachment file located in the file system
23    pub fn encrypt_file(
24        &self,
25        cipher: Cipher,
26        attachment: AttachmentView,
27        decrypted_file_path: String,
28        encrypted_file_path: String,
29    ) -> Result<Attachment> {
30        Ok(self.0.encrypt_file(
31            cipher,
32            attachment,
33            Path::new(&decrypted_file_path),
34            Path::new(&encrypted_file_path),
35        )?)
36    }
37    /// Decrypt an attachment file in memory
38    pub fn decrypt_buffer(
39        &self,
40        cipher: Cipher,
41        attachment: AttachmentView,
42        buffer: Vec<u8>,
43    ) -> Result<Vec<u8>> {
44        Ok(self.0.decrypt_buffer(cipher, attachment, &buffer)?)
45    }
46
47    /// Decrypt an attachment file located in the file system
48    pub fn decrypt_file(
49        &self,
50        cipher: Cipher,
51        attachment: AttachmentView,
52        encrypted_file_path: String,
53        decrypted_file_path: String,
54    ) -> Result<()> {
55        Ok(self.0.decrypt_file(
56            cipher,
57            attachment,
58            Path::new(&encrypted_file_path),
59            Path::new(&decrypted_file_path),
60        )?)
61    }
62}