Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sends API in bitwarden-uniffi #217

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
target
languages
languages/*
!/languages/kotlin
languages/kotlin/*
Comment on lines +3 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit awkward but that seems to be how the ignore file works yeah:
prettier/prettier#3328 (comment)

We could always remove it and add an extra step on the Readme to format the doc file after it's generated.

!/languages/kotlin/doc.md
schemas
/crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts
about.hbs
Expand Down
5 changes: 4 additions & 1 deletion crates/bitwarden-uniffi/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bitwarden::{
client::auth_settings::Kdf,
mobile::crypto::InitCryptoRequest,
tool::{ExportFormat, PassphraseGeneratorRequest, PasswordGeneratorRequest},
vault::{Cipher, CipherView, Collection, Folder, FolderView},
vault::{Cipher, CipherView, Collection, Folder, FolderView, Send, SendListView, SendView},
};
use schemars::JsonSchema;

Expand All @@ -16,6 +16,9 @@ pub enum DocRef {
Collection(Collection),
Folder(Folder),
FolderView(FolderView),
Send(Send),
SendView(SendView),
SendListView(SendListView),

// Crypto
InitCryptoRequest(InitCryptoRequest),
Expand Down
8 changes: 7 additions & 1 deletion crates/bitwarden-uniffi/src/vault/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod ciphers;
pub mod collections;
pub mod folders;
pub mod password_history;
pub mod sends;

#[derive(uniffi::Object)]
pub struct ClientVault(pub(crate) Arc<Client>);
Expand All @@ -27,8 +28,13 @@ impl ClientVault {
Arc::new(ciphers::ClientCiphers(self.0.clone()))
}

/// Ciphers operations
/// Password history operations
pub fn password_history(self: Arc<Self>) -> Arc<password_history::ClientPasswordHistory> {
Arc::new(password_history::ClientPasswordHistory(self.0.clone()))
}

/// Sends operations
pub fn sends(self: Arc<Self>) -> Arc<sends::ClientSends> {
Arc::new(sends::ClientSends(self.0.clone()))
}
}
104 changes: 104 additions & 0 deletions crates/bitwarden-uniffi/src/vault/sends.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use std::{path::Path, sync::Arc};

use bitwarden::vault::{Send, SendListView, SendView};

use crate::{Client, Result};

#[derive(uniffi::Object)]
pub struct ClientSends(pub Arc<Client>);

#[uniffi::export]
impl ClientSends {
/// Encrypt send
pub async fn encrypt(&self, send: SendView) -> Result<Send> {
Ok(self.0 .0.read().await.vault().sends().encrypt(send).await?)
}

/// Encrypt a send file in memory
pub async fn encrypt_buffer(&self, send: Send, buffer: Vec<u8>) -> Result<Vec<u8>> {
Ok(self
.0
.0
.read()
.await
.vault()
.sends()
.encrypt_buffer(send, &buffer)
.await?)
}

/// Encrypt a send file located in the file system
pub async fn encrypt_file(
&self,
send: Send,
decrypted_file_path: String,
encrypted_file_path: String,
) -> Result<()> {
Ok(self
.0
.0
.read()
.await
.vault()
.sends()
.encrypt_file(
send,
Path::new(&decrypted_file_path),
Path::new(&encrypted_file_path),
)
.await?)
}

/// Decrypt send
pub async fn decrypt(&self, send: Send) -> Result<SendView> {
Ok(self.0 .0.read().await.vault().sends().decrypt(send).await?)
}

/// Decrypt send list
pub async fn decrypt_list(&self, sends: Vec<Send>) -> Result<Vec<SendListView>> {
Ok(self
.0
.0
.read()
.await
.vault()
.sends()
.decrypt_list(sends)
.await?)
}

/// Decrypt a send file in memory
pub async fn decrypt_buffer(&self, send: Send, buffer: Vec<u8>) -> Result<Vec<u8>> {
Ok(self
.0
.0
.read()
.await
.vault()
.sends()
.decrypt_buffer(send, &buffer)
.await?)
}

/// Decrypt a send file located in the file system
pub async fn decrypt_file(
&self,
send: Send,
encrypted_file_path: String,
decrypted_file_path: String,
) -> Result<()> {
Ok(self
.0
.0
.read()
.await
.vault()
.sends()
.decrypt_file(
send,
Path::new(&encrypted_file_path),
Path::new(&decrypted_file_path),
)
.await?)
}
}
97 changes: 96 additions & 1 deletion languages/kotlin/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,91 @@ Decrypt password history

**Output**: std::result::Result<Vec,BitwardenError>

## ClientSends

### `encrypt`

Encrypt send

**Arguments**:

- self:
- send: SendView

**Output**: std::result::Result<Send,BitwardenError>

### `encrypt_buffer`

Encrypt a send file in memory

**Arguments**:

- self:
- send: Send
- buffer: Vec<>

**Output**: std::result::Result<Vec,BitwardenError>

### `encrypt_file`

Encrypt a send file located in the file system

**Arguments**:

- self:
- send: Send
- decrypted_file_path: String
- encrypted_file_path: String

**Output**: std::result::Result<,BitwardenError>

### `decrypt`

Decrypt send

**Arguments**:

- self:
- send: Send

**Output**: std::result::Result<SendView,BitwardenError>

### `decrypt_list`

Decrypt send list

**Arguments**:

- self:
- sends: Vec<Send>

**Output**: std::result::Result<Vec,BitwardenError>

### `decrypt_buffer`

Decrypt a send file in memory

**Arguments**:

- self:
- send: Send
- buffer: Vec<>

**Output**: std::result::Result<Vec,BitwardenError>

### `decrypt_file`

Decrypt a send file located in the file system

**Arguments**:

- self:
- send: Send
- encrypted_file_path: String
- decrypted_file_path: String

**Output**: std::result::Result<,BitwardenError>

## ClientVault

### `folders`
Expand Down Expand Up @@ -325,14 +410,24 @@ Ciphers operations

### `password_history`

Ciphers operations
Password history operations

**Arguments**:

- self: Arc<Self>

**Output**: Arc<password_history::ClientPasswordHistory>

### `sends`

Sends operations

**Arguments**:

- self: Arc<Self>

**Output**: Arc<sends::ClientSends>

# References

References are generated from the JSON schemas and should mostly match the kotlin and swift
Expand Down
1 change: 1 addition & 0 deletions support/docs/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const rootElements = [
"ClientFolders",
"ClientGenerators",
"ClientPasswordHistory",
"ClientSends",
"ClientVault",
];

Expand Down