bitwarden_uniffi/vault/
attachments.rsuse std::{path::Path, sync::Arc};
use bitwarden_vault::{
Attachment, AttachmentEncryptResult, AttachmentView, Cipher, VaultClientExt,
};
use crate::{error::Error, Client, Result};
#[derive(uniffi::Object)]
pub struct ClientAttachments(pub Arc<Client>);
#[uniffi::export]
impl ClientAttachments {
pub fn encrypt_buffer(
&self,
cipher: Cipher,
attachment: AttachmentView,
buffer: Vec<u8>,
) -> Result<AttachmentEncryptResult> {
Ok(self
.0
.0
.vault()
.attachments()
.encrypt_buffer(cipher, attachment, &buffer)
.map_err(Error::Encrypt)?)
}
pub fn encrypt_file(
&self,
cipher: Cipher,
attachment: AttachmentView,
decrypted_file_path: String,
encrypted_file_path: String,
) -> Result<Attachment> {
Ok(self
.0
.0
.vault()
.attachments()
.encrypt_file(
cipher,
attachment,
Path::new(&decrypted_file_path),
Path::new(&encrypted_file_path),
)
.map_err(Error::EncryptFile)?)
}
pub fn decrypt_buffer(
&self,
cipher: Cipher,
attachment: Attachment,
buffer: Vec<u8>,
) -> Result<Vec<u8>> {
Ok(self
.0
.0
.vault()
.attachments()
.decrypt_buffer(cipher, attachment, &buffer)
.map_err(Error::Decrypt)?)
}
pub fn decrypt_file(
&self,
cipher: Cipher,
attachment: Attachment,
encrypted_file_path: String,
decrypted_file_path: String,
) -> Result<()> {
Ok(self
.0
.0
.vault()
.attachments()
.decrypt_file(
cipher,
attachment,
Path::new(&encrypted_file_path),
Path::new(&decrypted_file_path),
)
.map_err(Error::DecryptFile)?)
}
}