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;
11 static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
14 /// Verifies an RFC 9102-formatted proof and returns the [`VerifiedRRStream`] in JSON form.
15 pub fn verify_byte_stream(stream: Vec<u8>) -> String {
16 match do_verify_byte_stream(stream) {
18 Err(e) => format!("{{\"error\":\"{:?}\"}}", e),
22 fn do_verify_byte_stream(stream: Vec<u8>) -> Result<String, ValidationError> {
23 let rrs = parse_rr_stream(&stream).map_err(|()| ValidationError::Invalid)?;
24 let verified_rrs = verify_rr_stream(&rrs)?;
25 let mut resp = String::new();
26 write!(&mut resp, "{}",
27 format_args!("{{\"valid_from\": {}, \"expires\": {}, \"max_cache_ttl\": {}, \"verified_rrs\": [",
28 verified_rrs.valid_from, verified_rrs.expires, verified_rrs.max_cache_ttl)
29 ).expect("Write to a String shouldn't fail");
30 for (idx, rr) in verified_rrs.verified_rrs.iter().enumerate() {
31 write!(&mut resp, "{}{}", if idx != 0 { ", " } else { "" }, rr.json())
32 .expect("Write to a String shouldn't fail");