Skip to content

Commit ca84993

Browse files
committed
Remove vault folder from wasm-internal
1 parent 7c0e18a commit ca84993

File tree

11 files changed

+78
-116
lines changed

11 files changed

+78
-116
lines changed

crates/bitwarden-vault/src/cipher/attachment_client.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ use crate::{
1010
Cipher, DecryptError, EncryptError, VaultClient,
1111
};
1212

13+
#[cfg(feature = "wasm")]
14+
use wasm_bindgen::prelude::*;
15+
16+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
1317
pub struct AttachmentsClient {
1418
pub(crate) client: Client,
1519
}
@@ -34,6 +38,24 @@ pub enum DecryptFileError {
3438
Io(#[from] std::io::Error),
3539
}
3640

41+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
42+
impl AttachmentsClient {
43+
pub fn decrypt_buffer(
44+
&self,
45+
cipher: Cipher,
46+
attachment: AttachmentView,
47+
encrypted_buffer: &[u8],
48+
) -> Result<Vec<u8>, DecryptError> {
49+
let key_store = self.client.internal.get_key_store();
50+
51+
Ok(key_store.decrypt(&AttachmentFile {
52+
cipher,
53+
attachment,
54+
contents: EncString::from_buffer(encrypted_buffer)?,
55+
})?)
56+
}
57+
}
58+
3759
impl AttachmentsClient {
3860
pub fn encrypt_buffer(
3961
&self,
@@ -49,6 +71,7 @@ impl AttachmentsClient {
4971
contents: buffer,
5072
})?)
5173
}
74+
5275
pub fn encrypt_file(
5376
&self,
5477
cipher: Cipher,
@@ -65,20 +88,6 @@ impl AttachmentsClient {
6588
Ok(attachment)
6689
}
6790

68-
pub fn decrypt_buffer(
69-
&self,
70-
cipher: Cipher,
71-
attachment: AttachmentView,
72-
encrypted_buffer: &[u8],
73-
) -> Result<Vec<u8>, DecryptError> {
74-
let key_store = self.client.internal.get_key_store();
75-
76-
Ok(key_store.decrypt(&AttachmentFile {
77-
cipher,
78-
attachment,
79-
contents: EncString::from_buffer(encrypted_buffer)?,
80-
})?)
81-
}
8291
pub fn decrypt_file(
8392
&self,
8493
cipher: Cipher,
@@ -93,6 +102,7 @@ impl AttachmentsClient {
93102
}
94103
}
95104

105+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
96106
impl VaultClient {
97107
pub fn attachments(&self) -> AttachmentsClient {
98108
AttachmentsClient {

crates/bitwarden-vault/src/cipher/cipher_client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl CiphersClient {
8585
}
8686
}
8787

88+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
8889
impl VaultClient {
8990
pub fn ciphers(&self) -> CiphersClient {
9091
CiphersClient {

crates/bitwarden-vault/src/folder_client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ impl FoldersClient {
3333
}
3434
}
3535

36+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
3637
impl VaultClient {
3738
pub fn folders(&self) -> FoldersClient {
3839
FoldersClient {

crates/bitwarden-vault/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ mod vault_client;
3131
pub use vault_client::{VaultClient, VaultClientExt};
3232

3333
mod sync;
34-
mod totp_client;
3534
pub use sync::{SyncRequest, SyncResponse};
35+
36+
mod totp_client;
37+
pub use totp_client::TotpClient;

crates/bitwarden-vault/src/totp_client.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
1+
use bitwarden_core::Client;
12
use chrono::{DateTime, Utc};
23

34
use crate::{
45
generate_totp, generate_totp_cipher_view, CipherListView, TotpError, TotpResponse, VaultClient,
56
};
67

7-
impl VaultClient {
8+
#[cfg(feature = "wasm")]
9+
use wasm_bindgen::prelude::*;
10+
11+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
12+
pub struct TotpClient {
13+
pub(crate) client: Client,
14+
}
15+
16+
#[cfg(feature = "wasm")]
17+
#[wasm_bindgen]
18+
impl TotpClient {
19+
/// Generates a TOTP code from a provided key
20+
///
21+
/// # Arguments
22+
/// - `key` - Can be:
23+
/// - A base32 encoded string
24+
/// - OTP Auth URI
25+
/// - Steam URI
26+
/// - `time_ms` - Optional timestamp in milliseconds
27+
#[wasm_bindgen(js_name = "generate_totp")]
28+
pub fn generate_totp_wasm(
29+
&self,
30+
key: String,
31+
time_ms: Option<f64>,
32+
) -> Result<TotpResponse, TotpError> {
33+
let datetime = time_ms.and_then(|time| DateTime::<Utc>::from_timestamp_millis(time as i64));
34+
35+
self.generate_totp(key, datetime)
36+
}
37+
}
38+
39+
impl TotpClient {
840
/// Generate a TOTP code from a provided key.
941
///
1042
/// Key can be either:
@@ -30,3 +62,12 @@ impl VaultClient {
3062
generate_totp_cipher_view(&mut key_store.context(), view, time)
3163
}
3264
}
65+
66+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
67+
impl VaultClient {
68+
pub fn totp(&self) -> TotpClient {
69+
TotpClient {
70+
client: self.client.clone(),
71+
}
72+
}
73+
}

crates/bitwarden-vault/src/vault_client.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ use crate::{
55
SyncRequest, SyncResponse,
66
};
77

8+
#[cfg(feature = "wasm")]
9+
use wasm_bindgen::prelude::*;
10+
811
#[derive(Clone)]
12+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
913
pub struct VaultClient {
1014
pub(crate) client: Client,
1115
}

crates/bitwarden-wasm-internal/src/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use bitwarden_core::{Client, ClientSettings};
55
use bitwarden_error::bitwarden_error;
66
use bitwarden_exporters::ExporterClientExt;
77
use bitwarden_generators::GeneratorClientsExt;
8-
use bitwarden_vault::VaultClientExt;
8+
use bitwarden_vault::{VaultClient, VaultClientExt};
99
use wasm_bindgen::prelude::*;
1010

11-
use crate::{CryptoClient, VaultClient};
11+
use crate::CryptoClient;
1212

1313
#[wasm_bindgen]
1414
pub struct BitwardenClient(pub(crate) Client);
@@ -46,7 +46,7 @@ impl BitwardenClient {
4646
}
4747

4848
pub fn vault(&self) -> VaultClient {
49-
VaultClient::new(self.0.vault())
49+
self.0.vault()
5050
}
5151

5252
/// Constructs a specific client for generating passwords and passphrases

crates/bitwarden-wasm-internal/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ mod custom_types;
66
mod init;
77
mod pure_crypto;
88
mod ssh;
9-
mod vault;
109

1110
pub use bitwarden_ipc::wasm::*;
1211
pub use client::BitwardenClient;
1312
pub use crypto::CryptoClient;
1413
pub use init::init_sdk;
15-
pub use vault::VaultClient;

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

Lines changed: 0 additions & 24 deletions
This file was deleted.

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

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)