bitwarden_uniffi/tool/
sends.rs

1use std::path::Path;
2
3use bitwarden_send::{Send, SendListView, SendView};
4
5use crate::{error::Error, Result};
6
7#[derive(uniffi::Object)]
8pub struct SendClient(pub(crate) bitwarden_send::SendClient);
9
10#[uniffi::export]
11impl SendClient {
12    /// Encrypt send
13    pub fn encrypt(&self, send: SendView) -> Result<Send> {
14        Ok(self.0.encrypt(send).map_err(Error::SendEncrypt)?)
15    }
16
17    /// Encrypt a send file in memory
18    pub fn encrypt_buffer(&self, send: Send, buffer: Vec<u8>) -> Result<Vec<u8>> {
19        Ok(self
20            .0
21            .encrypt_buffer(send, &buffer)
22            .map_err(Error::SendEncrypt)?)
23    }
24
25    /// Encrypt a send file located in the file system
26    pub fn encrypt_file(
27        &self,
28        send: Send,
29        decrypted_file_path: String,
30        encrypted_file_path: String,
31    ) -> Result<()> {
32        Ok(self
33            .0
34            .encrypt_file(
35                send,
36                Path::new(&decrypted_file_path),
37                Path::new(&encrypted_file_path),
38            )
39            .map_err(Error::SendEncryptFile)?)
40    }
41
42    /// Decrypt send
43    pub fn decrypt(&self, send: Send) -> Result<SendView> {
44        Ok(self.0.decrypt(send).map_err(Error::SendDecrypt)?)
45    }
46
47    /// Decrypt send list
48    pub fn decrypt_list(&self, sends: Vec<Send>) -> Result<Vec<SendListView>> {
49        Ok(self.0.decrypt_list(sends).map_err(Error::SendDecrypt)?)
50    }
51
52    /// Decrypt a send file in memory
53    pub fn decrypt_buffer(&self, send: Send, buffer: Vec<u8>) -> Result<Vec<u8>> {
54        Ok(self
55            .0
56            .decrypt_buffer(send, &buffer)
57            .map_err(Error::SendDecrypt)?)
58    }
59
60    /// Decrypt a send file located in the file system
61    pub fn decrypt_file(
62        &self,
63        send: Send,
64        encrypted_file_path: String,
65        decrypted_file_path: String,
66    ) -> Result<()> {
67        Ok(self
68            .0
69            .decrypt_file(
70                send,
71                Path::new(&encrypted_file_path),
72                Path::new(&decrypted_file_path),
73            )
74            .map_err(Error::SendDecryptFile)?)
75    }
76}