Skip to content

Commit ad572b2

Browse files
authored
[PM-18043] Add serialization/deserialization support (#187)
## 🎟️ Tracking <!-- Paste the link to the Jira or GitHub issue or otherwise describe / point to where this change is coming from. --> ## 📔 Objective I did my best to anticipate usage patterns but I'm open to feedback from other teams Relevant clients PR: bitwarden/clients#13804 ## ⏰ 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 8f4e521 commit ad572b2

File tree

13 files changed

+557
-66
lines changed

13 files changed

+557
-66
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bitwarden-ipc/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ wasm = [
2121
bitwarden-error = { workspace = true }
2222
js-sys = { workspace = true, optional = true }
2323
serde = { workspace = true }
24+
serde_json = { workspace = true }
2425
thiserror = { workspace = true }
25-
tokio = { features = ["sync"], workspace = true }
26+
tokio = { features = ["sync", "time"], workspace = true }
2627
tsify-next = { workspace = true, optional = true }
2728
wasm-bindgen = { workspace = true, optional = true }
2829
wasm-bindgen-futures = { workspace = true, optional = true }
2930

31+
[dev-dependencies]
32+
tokio = { workspace = true, features = ["rt"] }
33+
3034
[lints]
3135
workspace = true

crates/bitwarden-ipc/src/endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
22
#[cfg(feature = "wasm")]
33
use {tsify_next::Tsify, wasm_bindgen::prelude::*};
44

5-
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
5+
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
66
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
77
pub enum Endpoint {
88
Web { id: i32 },

crates/bitwarden-ipc/src/error.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,47 @@ use thiserror::Error;
33
#[derive(Clone, Debug, Error, PartialEq, Eq)]
44
pub enum SendError<Crypto, Com> {
55
#[error("Crypto error: {0}")]
6-
CryptoError(Crypto),
6+
Crypto(Crypto),
77

88
#[error("Communication error: {0}")]
9-
CommunicationError(Com),
9+
Communication(Com),
1010
}
1111

1212
#[derive(Clone, Debug, Error, PartialEq, Eq)]
1313
pub enum ReceiveError<Crypto, Com> {
14+
#[error("The receive operation timed out")]
15+
Timeout,
16+
1417
#[error("Crypto error: {0}")]
15-
CryptoError(Crypto),
18+
Crypto(Crypto),
1619

1720
#[error("Communication error: {0}")]
18-
CommunicationError(Com),
21+
Communication(Com),
22+
}
23+
24+
#[derive(Clone, Debug, Error, PartialEq, Eq)]
25+
pub enum TypedReceiveError<Typing, Crypto, Com> {
26+
#[error("Typing error: {0}")]
27+
Typing(Typing),
28+
29+
#[error("The receive operation timed out")]
30+
Timeout,
31+
32+
#[error("Crypto error: {0}")]
33+
Crypto(Crypto),
34+
35+
#[error("Communication error: {0}")]
36+
Communication(Com),
37+
}
38+
39+
impl<Typing, Crypto, Com> From<ReceiveError<Crypto, Com>>
40+
for TypedReceiveError<Typing, Crypto, Com>
41+
{
42+
fn from(value: ReceiveError<Crypto, Com>) -> Self {
43+
match value {
44+
ReceiveError::Timeout => TypedReceiveError::Timeout,
45+
ReceiveError::Crypto(crypto) => TypedReceiveError::Crypto(crypto),
46+
ReceiveError::Communication(com) => TypedReceiveError::Communication(com),
47+
}
48+
}
1949
}

0 commit comments

Comments
 (0)