Skip to content

Commit 7574f8b

Browse files
committed
feat: make features additive and extract js snippets for better debuggability
1 parent d792356 commit 7574f8b

File tree

8 files changed

+34
-33
lines changed

8 files changed

+34
-33
lines changed

mls-rs-core/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ exclude = ["test_data"]
1111

1212

1313
[features]
14-
web = []
1514
node = []
16-
default = ["std", "rfc_compliant", "fast_serialize", "web"]
15+
default = ["std", "rfc_compliant", "fast_serialize"]
1716
arbitrary = ["std", "dep:arbitrary"]
1817
fast_serialize = ["mls-rs-codec/preallocate"]
1918
std = ["mls-rs-codec/std", "zeroize/std", "safer-ffi-gen?/std", "dep:thiserror", "serde?/std"]

mls-rs-core/js/es-time.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function date_now() {
2+
return Date.now();
3+
}

mls-rs-core/js/node-time.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const a = require("assert");
2+
3+
module.exports.date_now = function() {
4+
a(true);
5+
return Date.now();
6+
};

mls-rs-core/src/time.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use core::time::Duration;
66

7+
use cfg_if::cfg_if;
78
#[cfg(target_arch = "wasm32")]
89
use wasm_bindgen::prelude::*;
910

@@ -48,20 +49,14 @@ impl From<u64> for MlsTime {
4849
}
4950
}
5051

51-
#[cfg(all(target_arch = "wasm32", feature = "web"))]
52-
#[wasm_bindgen(inline_js = r#"
53-
export function date_now() {
54-
return Date.now();
55-
}"#)]
56-
extern "C" {
57-
fn date_now() -> f64;
58-
}
59-
60-
#[cfg(all(target_arch = "wasm32", feature = "node", not(feature = "web")))]
61-
#[wasm_bindgen(inline_js = r#"
62-
module.exports.date_now = function() {
63-
return Date.now();
64-
};"#)]
52+
#[cfg_attr(
53+
all(target_arch = "wasm32", not(feature = "node")),
54+
wasm_bindgen(module = "/js/es-time.js")
55+
)]
56+
#[cfg_attr(
57+
all(target_arch = "wasm32", feature = "node"),
58+
wasm_bindgen(module = "/js/node-time.js")
59+
)]
6560
extern "C" {
6661
fn date_now() -> f64;
6762
}

mls-rs-crypto-webcrypto/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ keywords = ["mls", "mls-rs"]
99
license = "Apache-2.0 OR MIT"
1010

1111
[features]
12-
web = []
1312
node = []
14-
default = ["web"]
1513

1614
[dependencies]
1715
cfg-if = "1.0.0"

mls-rs-crypto-webcrypto/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,7 @@ impl From<JsValue> for CryptoError {
6565
}
6666

6767
cfg_if! {
68-
if #[cfg(feature = "web")] {
69-
#[inline]
70-
pub(crate) fn crypto() -> Result<Crypto, CryptoError> {
71-
Ok(web_sys::window()
72-
.ok_or(CryptoError::WindowNotFound)?
73-
.crypto()?)
74-
}
75-
76-
#[inline]
77-
pub(crate) fn get_crypto() -> Result<SubtleCrypto, CryptoError> {
78-
crypto().map(|c| c.subtle())
79-
}
80-
} else {
68+
if #[cfg(feature = "node")] {
8169
#[wasm_bindgen(module = "/js/node-crypto.js")]
8270
extern "C" {
8371
#[wasm_bindgen]
@@ -94,6 +82,18 @@ cfg_if! {
9482
Ok(node_crypto()
9583
.subtle())
9684
}
85+
} else {
86+
#[inline]
87+
pub(crate) fn crypto() -> Result<Crypto, CryptoError> {
88+
Ok(web_sys::window()
89+
.ok_or(CryptoError::WindowNotFound)?
90+
.crypto()?)
91+
}
92+
93+
#[inline]
94+
pub(crate) fn get_crypto() -> Result<SubtleCrypto, CryptoError> {
95+
crypto().map(|c| c.subtle())
96+
}
9797
}
9898
}
9999

mls-rs-identity-x509/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ default = ["std"]
1313
std = ["mls-rs-core/std", "dep:thiserror"]
1414

1515
[dependencies]
16-
mls-rs-core = { path = "../mls-rs-core", default-features = false, features = ["x509", "web"], version = "0.19.0" }
16+
mls-rs-core = { path = "../mls-rs-core", default-features = false, features = ["x509"], version = "0.19.0" }
1717
maybe-async = "0.2.10"
1818
thiserror = { version = "1.0.40", optional = true }
1919

mls-rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ benchmark_util = ["test_util", "default", "dep:mls-rs-crypto-openssl"]
5151
fuzz_util = ["test_util", "default", "dep:once_cell", "dep:mls-rs-crypto-openssl"]
5252

5353
[dependencies]
54-
mls-rs-core = { path = "../mls-rs-core", default-features = false, version = "0.19.1", features = ["web"]}
54+
mls-rs-core = { path = "../mls-rs-core", default-features = false, version = "0.19.1"}
5555
mls-rs-identity-x509 = { path = "../mls-rs-identity-x509", default-features = false, version = "0.12.0", optional = true }
5656
zeroize = { version = "1", default-features = false, features = ["alloc", "zeroize_derive"] }
5757
mls-rs-codec = { version = "0.5.2", path = "../mls-rs-codec", default-features = false}

0 commit comments

Comments
 (0)