Skip to content

Commit fe76be2

Browse files
authored
Expose attachment content decryption via WASM SDK bindings (#220)
## 🎟️ Tracking Related to https://bitwarden.atlassian.net/browse/PM-12423 <!-- Paste the link to the Jira or GitHub issue or otherwise describe / point to where this change is coming from. --> ## 📔 Objective Expose attachment content decryption method to enable TS client-side file decryption without requiring a separate decrypted key. <!-- Describe what the purpose of this PR is, for example what bug you're fixing or new feature you're adding. --> ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes
1 parent 2028495 commit fe76be2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use bitwarden_vault::{Attachment, Cipher, DecryptError};
2+
use wasm_bindgen::prelude::wasm_bindgen;
3+
4+
#[wasm_bindgen]
5+
pub struct ClientAttachments(bitwarden_vault::ClientAttachments);
6+
7+
impl ClientAttachments {
8+
pub fn new(client: bitwarden_vault::ClientAttachments) -> Self {
9+
Self(client)
10+
}
11+
}
12+
13+
#[wasm_bindgen]
14+
impl ClientAttachments {
15+
/// Decrypts an attachment's encrypted content
16+
pub fn decrypt_buffer(
17+
&self,
18+
cipher: Cipher,
19+
attachment: Attachment,
20+
encrypted_buffer: &[u8],
21+
) -> Result<Vec<u8>, DecryptError> {
22+
self.0.decrypt_buffer(cipher, attachment, encrypted_buffer)
23+
}
24+
}

crates/bitwarden-wasm-internal/src/vault/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
pub mod attachments;
12
pub mod ciphers;
23
pub mod folders;
34
pub mod totp;
45

6+
use attachments::ClientAttachments;
57
use ciphers::ClientCiphers;
68
use totp::ClientTotp;
79
use wasm_bindgen::prelude::*;
@@ -19,6 +21,10 @@ impl VaultClient {
1921

2022
#[wasm_bindgen]
2123
impl VaultClient {
24+
pub fn attachments(&self) -> ClientAttachments {
25+
ClientAttachments::new(self.0.attachments())
26+
}
27+
2228
pub fn ciphers(&self) -> ClientCiphers {
2329
ClientCiphers::new(self.0.ciphers())
2430
}

0 commit comments

Comments
 (0)