pub fn verify_signed(public_key: &str, domain: Domain, signed: &Signed) -> boolExpand description
Whether signed is a message of domain signed by public_key. Three things have to
hold at once — the right key, the right domain, and an untouched body — and this
answers about all three with one boolean, because a link has no use for the difference:
any of them failing means the message does not come from the peer it claims to.
use majordomus_cli::mesh::identity::NodeIdentity;
use majordomus_cli::mesh::link::{sign, verify_signed, Domain};
let node = NodeIdentity::ephemeral().unwrap();
let impostor = NodeIdentity::ephemeral().unwrap();
let mut signed = sign(&node, Domain::Hello, serde_json::json!({ "a": 1, "b": 2 }));
assert!(verify_signed(&node.public.public_key, Domain::Hello, &signed));
// another key did not sign it, and a reordered body is the same body
assert!(!verify_signed(&impostor.public.public_key, Domain::Hello, &signed));
signed.body = serde_json::json!({ "b": 2, "a": 1 });
assert!(verify_signed(&node.public.public_key, Domain::Hello, &signed));
// an edited one is not
signed.body = serde_json::json!({ "b": 3, "a": 1 });
assert!(!verify_signed(&node.public.public_key, Domain::Hello, &signed));