1 //! WASM-compatible verification wrappers
3 use dnssec_prover::ser::parse_rr_stream;
4 use dnssec_prover::validation::{verify_rr_stream, ValidationError};
6 use wasm_bindgen::prelude::wasm_bindgen;
9 static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
12 /// Verifies an RFC 9102-formatted proof and returns the [`VerifiedRRStream`] in JSON form.
13 pub fn verify_byte_stream(stream: Vec<u8>) -> String {
14 match do_verify_byte_stream(stream) {
16 Err(e) => format!("{{\"error\":\"{:?}\"}}", e),
20 fn do_verify_byte_stream(stream: Vec<u8>) -> Result<String, ValidationError> {
21 let rrs = parse_rr_stream(&stream).map_err(|()| ValidationError::Invalid)?;
22 let verified_rrs = verify_rr_stream(&rrs)?;
23 let mut resp = String::new();
24 resp += &format!("{{\"valid_from\": {}, \"expires\": {}, \"max_cache_ttl\": {}, \"verified_rrs\": [",
25 verified_rrs.valid_from, verified_rrs.expires, verified_rrs.max_cache_ttl);
26 for (idx, rr) in verified_rrs.verified_rrs.iter().enumerate() {
27 resp += &format!("{}\"{:?}\"", if idx != 0 { ", " } else { "" }, rr);