bitwarden_uniffi/tool/
sends.rs

1use std::path::Path;
2
3use bitwarden_send::{Send, SendListView, SendView};
4
5use crate::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)?)
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.0.encrypt_buffer(send, &buffer)?)
20    }
21
22    /// Encrypt a send file located in the file system
23    pub fn encrypt_file(
24        &self,
25        send: Send,
26        decrypted_file_path: String,
27        encrypted_file_path: String,
28    ) -> Result<()> {
29        Ok(self.0.encrypt_file(
30            send,
31            Path::new(&decrypted_file_path),
32            Path::new(&encrypted_file_path),
33        )?)
34    }
35
36    /// Decrypt send
37    pub fn decrypt(&self, send: Send) -> Result<SendView> {
38        Ok(self.0.decrypt(send)?)
39    }
40
41    /// Decrypt send list
42    pub fn decrypt_list(&self, sends: Vec<Send>) -> Result<Vec<SendListView>> {
43        Ok(self.0.decrypt_list(sends)?)
44    }
45
46    /// Decrypt a send file in memory
47    pub fn decrypt_buffer(&self, send: Send, buffer: Vec<u8>) -> Result<Vec<u8>> {
48        Ok(self.0.decrypt_buffer(send, &buffer)?)
49    }
50
51    /// Decrypt a send file located in the file system
52    pub fn decrypt_file(
53        &self,
54        send: Send,
55        encrypted_file_path: String,
56        decrypted_file_path: String,
57    ) -> Result<()> {
58        Ok(self.0.decrypt_file(
59            send,
60            Path::new(&encrypted_file_path),
61            Path::new(&decrypted_file_path),
62        )?)
63    }
64}