crates/gunnar-crypt/tests/wasm-cross.sh
#!/bin/sh
# Native <-> wasm32 cross-check for gunnar-crypt: the SAME vectors on both
# targets, and a key file wrapped by the wasm32 build unwrapped natively.
#
# crates/gunnar-crypt/tests/wasm-cross.sh
#
# Needs the wasm32-unknown-unknown target, wasm-bindgen-test-runner matching
# the lock's wasm-bindgen, and node on PATH (wasm-bindgen-test runs in node).
set -eu
cd "$(dirname "$0")/../../.."
out=$(mktemp -d)
trap 'rm -rf "$out"' EXIT
export CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner
echo "== wasm32: format + vectors + chunked (envelope v2) + fuzz_open"
cargo test -p gunnar-crypt --target wasm32-unknown-unknown --test format --test vectors --test chunked --test fuzz_open --test userkey -- --nocapture \
>"$out/wasm.log" 2>&1 || { cat "$out/wasm.log"; exit 1; }
grep -E "^test result" "$out/wasm.log"
sed -n 's/.*GUNNAR-CRYPT-CROSS \([A-Za-z0-9+/=]*\).*/\1/p' "$out/wasm.log" | head -1 >"$out/wrapped"
sed -n 's/.*GUNNAR-CRYPT-CROSS-USER-KEY \([A-Za-z0-9+/=]*\).*/\1/p' "$out/wasm.log" | head -1 >>"$out/wrapped"
test -s "$out/wrapped" || { echo "FAIL: the wasm run printed no wrapped key file"; exit 1; }
echo "== native: format + vectors + chunked + fuzz_open + the wasm-wrapped key file"
GUNNAR_CRYPT_WASM_WRAPPED="$out/wrapped" cargo test -q -p gunnar-crypt --test format --test vectors --test chunked --test fuzz_open --test userkey -- --nocapture \
>"$out/native.log" 2>&1 || { cat "$out/native.log"; exit 1; }
grep -E "^test result" "$out/native.log"
grep -q "CROSS-OK" "$out/native.log" || { echo "FAIL: the native build did not unwrap the wasm key file"; exit 1; }
echo "PASS: one format on both targets; wasm-wrapped key file unwrapped natively"