tuwunel_admin/debug/
verify_json.rs1use ruma::CanonicalJsonObject;
2use tuwunel_core::{Err, Result, err, utils::math::Expected};
3
4use crate::admin_command;
5
6#[admin_command]
7pub(super) async fn verify_json(&self) -> Result {
8 if self.body.len() < 2
9 || !self.body[0].trim().starts_with("```")
10 || self.body.last().unwrap_or(&"").trim() != "```"
11 {
12 return Err!("Expected code block in command body. Add --help for details.");
13 }
14
15 let string = self.body[1..self.body.len().expected_sub(1)].join("\n");
16
17 let value = serde_json::from_str::<CanonicalJsonObject>(&string)
18 .map_err(|e| err!("Invalid json: {e}"))?;
19
20 self.services
21 .server_keys
22 .verify_json(&value, None)
23 .await
24 .map_err(|e| err!("Signature verification failed: {e}"))?;
25
26 self.write_str("Signature correct").await
27}