From 84b358c934706135ece5995022a7614438260177 Mon Sep 17 00:00:00 2001 From: satvrn Date: Wed, 2 Aug 2023 14:11:26 +0000 Subject: [PATCH] better WASM support --- Cargo.toml | 20 +++++++++++++++----- benches/double_ratchet_bench.rs | 4 ++-- tests/mod.rs | 5 +++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4562fb5..febf231 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,17 @@ [package] name = "double-ratchet-rs" +version = "0.4.6" authors = ["satvrn", "Hannes Furmans"] +edition = "2021" +rust-version = "1.60" description = "A pure Rust implementation of the Double Ratchet algorithm as described by Signal." +documentation = "https://docs.rs/double-ratchet-rs" +readme = "README.md" homepage = "https://github.com/notsatvrn/double-ratchet-rs" repository = "https://github.com/notsatvrn/double-ratchet-rs" -readme = "README.md" -keywords = ["double-ratchet", "crypto", "cryptography", "signal"] -version = "0.4.6" -edition = "2021" license = "MIT" +keywords = ["double-ratchet", "signal"] +categories = ["algorithms", "cryptography", "no-std"] [dependencies] x25519-dalek = {version = "2.0.0-rc.3", default-features = false, features = ["serde", "static_secrets", "zeroize"]} @@ -22,9 +25,16 @@ postcard = {version = "1.0", default-features = false, features = ["alloc"]} hashbrown = {version = "0.14", features = ["serde"], optional = true} zeroize = {version = "1.6", default-features = false, features = ["zeroize_derive"]} -[dev-dependencies] +[target.'cfg(all(target_family = "wasm", target_vendor = "unknown"))'.dependencies] +getrandom = { version = "0.2", features = ["js"] } + +[target.'cfg(not(target_family = "wasm"))'.dev-dependencies] criterion = "0.4" +[target.'cfg(target_family = "wasm")'.dev-dependencies] +criterion = { version = "0.4", default-features = false, features = ["plotters", "cargo_bench_support"] } +wasm-bindgen-test = "0.2" + [[bench]] name = "double_ratchet_bench" harness = false diff --git a/benches/double_ratchet_bench.rs b/benches/double_ratchet_bench.rs index 0d5558d..82274eb 100644 --- a/benches/double_ratchet_bench.rs +++ b/benches/double_ratchet_bench.rs @@ -29,7 +29,7 @@ fn criterion_benchmark_2(c: &mut Criterion) { c.bench_function("Ratchet Enc Skip", |b| b.iter(|| ratchet_enc_skip())); } -fn ratchet_encryt_decrypt_four() { +fn ratchet_encrypt_decrypt_four() { let sk = [1; 32]; let data = include_bytes!("../src/dh.rs").to_vec(); let (mut bob_ratchet, public_key) = Ratchet::init_bob(sk); @@ -42,7 +42,7 @@ fn ratchet_encryt_decrypt_four() { fn criterion_benchmark_3(c: &mut Criterion) { c.bench_function("Ratchet Dec Four", |b| { - b.iter(|| ratchet_encryt_decrypt_four()) + b.iter(|| ratchet_encrypt_decrypt_four()) }); } diff --git a/tests/mod.rs b/tests/mod.rs index 234d8f3..ef73951 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -1,6 +1,11 @@ use double_ratchet_rs::{Ratchet, RatchetEncHeader}; + +#[cfg(not(feature = "std"))] extern crate alloc; +#[cfg(feature = "std")] +extern crate std as alloc; + #[test] fn init() { let sk = [1; 32];