//! Test suite for the Web and headless browsers. #![cfg(target_arch = "wasm32")] extern crate wasm_bindgen_test; wasm_bindgen_test_configure!(run_in_browser); use ring::rand::{SecureRandom, SystemRandom}; use serde::{Deserialize, Serialize}; use serde_crypt::setup; use std::error::Error; use wasm_bindgen_test::*; #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] struct Test { #[serde(with = "serde_crypt")] field: Vec, #[serde(with = "serde_crypt")] other: Other, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] struct Other { #[serde(with = "serde_crypt")] field: Vec, } #[wasm_bindgen_test] fn flow() -> Result<(), Box> { let mut key: [u8; 256] = [0; 256]; let rand_gen = SystemRandom::new(); rand_gen.fill(&mut key).unwrap(); setup(key.to_vec()); let instance = Test { field: "a super secret message".as_bytes().to_vec(), other: Other { field: "another secret message".as_bytes().to_vec(), }, }; let serialized = serde_json::to_string(&instance)?; let deserialized: Test = serde_json::from_str(&serialized)?; assert_eq!(deserialized.field, instance.field); Ok(()) }