bitwarden_uniffi/vault/
attachments.rs1use std::path::Path;
2
3use bitwarden_vault::{
4 Attachment, AttachmentEncryptResult, AttachmentView, Cipher, CipherId, CipherView,
5 CreateAttachmentRequest, CreatedAttachment,
6};
7
8use crate::Result;
9
10#[derive(uniffi::Object)]
11pub struct AttachmentsClient(pub(crate) bitwarden_vault::AttachmentsClient);
12
13#[uniffi::export(async_runtime = "tokio")]
14impl AttachmentsClient {
15 pub fn encrypt_buffer(
17 &self,
18 cipher: Cipher,
19 attachment: AttachmentView,
20 buffer: Vec<u8>,
21 ) -> Result<AttachmentEncryptResult> {
22 Ok(self.0.encrypt_buffer(cipher, attachment, &buffer)?)
23 }
24
25 pub fn encrypt_file(
27 &self,
28 cipher: Cipher,
29 attachment: AttachmentView,
30 decrypted_file_path: String,
31 encrypted_file_path: String,
32 ) -> Result<Attachment> {
33 Ok(self.0.encrypt_file(
34 cipher,
35 attachment,
36 Path::new(&decrypted_file_path),
37 Path::new(&encrypted_file_path),
38 )?)
39 }
40 pub fn decrypt_buffer(
42 &self,
43 cipher: Cipher,
44 attachment: AttachmentView,
45 buffer: Vec<u8>,
46 ) -> Result<Vec<u8>> {
47 Ok(self.0.decrypt_buffer(cipher, attachment, &buffer)?)
48 }
49
50 pub fn decrypt_file(
52 &self,
53 cipher: Cipher,
54 attachment: AttachmentView,
55 encrypted_file_path: String,
56 decrypted_file_path: String,
57 ) -> Result<()> {
58 Ok(self.0.decrypt_file(
59 cipher,
60 attachment,
61 Path::new(&encrypted_file_path),
62 Path::new(&decrypted_file_path),
63 )?)
64 }
65
66 pub async fn create_attachment(
69 &self,
70 cipher_id: CipherId,
71 request: CreateAttachmentRequest,
72 ) -> Result<CreatedAttachment> {
73 Ok(self.0.create_attachment(cipher_id, request).await?)
74 }
75
76 pub async fn delete_attachment(
78 &self,
79 cipher_id: CipherId,
80 attachment_id: String,
81 ) -> Result<Cipher> {
82 Ok(self.0.delete_attachment(cipher_id, attachment_id).await?)
83 }
84
85 pub async fn renew_file_upload_url(
87 &self,
88 cipher_id: CipherId,
89 attachment_id: String,
90 ) -> Result<String> {
91 Ok(self
92 .0
93 .renew_file_upload_url(cipher_id, attachment_id)
94 .await?)
95 }
96
97 pub async fn upgrade_attachment(
99 &self,
100 cipher_id: CipherId,
101 attachment_id: String,
102 ) -> Result<CipherView> {
103 Ok(self.0.upgrade_attachment(cipher_id, attachment_id).await?)
104 }
105
106 pub async fn get_attachment_download_url(
109 &self,
110 cipher_id: CipherId,
111 attachment_id: String,
112 emergency_access_id: Option<String>,
113 ) -> Result<String> {
114 Ok(self
115 .0
116 .get_attachment_download_url(cipher_id, attachment_id, emergency_access_id)
117 .await?)
118 }
119}