Function ruma_signatures::verify_json [−][src]
pub fn verify_json(
public_key_map: &PublicKeyMap,
object: &CanonicalJsonObject
) -> Result<(), Error>
Expand description
Uses a set of public keys to verify a signed JSON object.
Parameters
- public_key_map: A map from entity identifiers to a map from key identifiers to public keys. Generally, entity identifiers are server names—the host/IP/port of a homeserver (e.g. “example.com”) for which a signature must be verified. Key identifiers for each server (e.g. “ed25519:1”) then map to their respective public keys.
- object: The JSON object that was signed.
Errors
Returns an error if verification fails.
Examples
use std::collections::BTreeMap; const PUBLIC_KEY: &str = "XGX0JRS2Af3be3knz2fBiRbApjm2Dh61gXDJA8kcJNI"; // Deserialize the signed JSON. let object = serde_json::from_str( r#"{ "signatures": { "domain": { "ed25519:1": "K8280/U9SSy9IVtjBuVeLr+HpOB4BQFWbg+UZaADMtTdGYI7Geitb76LTrr5QV/7Xg4ahLwYGYZzuHGZKM5ZAQ" } } }"# ).unwrap(); // Create the `PublicKeyMap` that will inform `verify_json` which signatures to verify. let mut public_key_set = BTreeMap::new(); public_key_set.insert("ed25519:1".into(), PUBLIC_KEY.to_owned()); let mut public_key_map = BTreeMap::new(); public_key_map.insert("domain".into(), public_key_set); // Verify at least one signature for each entity in `public_key_map`. assert!(ruma_signatures::verify_json(&public_key_map, &object).is_ok());