From 657765cc512743c248d71b852b4f2e81fa124af7 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 18 Nov 2026 20:10:53 +0000 Subject: version: say why a version is none `Version::read` names what makes a version none: the field it lacks, or the one more it has, that this continuum doesn't know (of the version, a party's keys or node list, a rule), the federation it names beside the one this continuum knows, how many keys or nodes a party has against how many it may, the node ID that is none, and of a key why it is none (`keys::spelled`): its type, its point, or its spelling. A node that stops at a version says so in `stopped` (`GET /events`) and its log; a party's client in what it won't propose or back. The guide to a node that stopped says what `why` tells. --- src/federation/keys.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/federation/keys.rs') diff --git a/src/federation/keys.rs b/src/federation/keys.rs index 22940ad..0dbe5f7 100644 --- a/src/federation/keys.rs +++ b/src/federation/keys.rs @@ -100,12 +100,24 @@ impl Key { /// The key `text` spells, where it spells one as the federation does. pub(crate) fn key(text: &str) -> Option { - let key = Key::parse(text).ok()?; - let valid = match &key { - Key::Ed25519(public) => VerifyingKey::from_bytes(&public.0).is_ok(), - Key::P256(_) => true, - }; - (key.line() == text && valid).then_some(key) + spelled(text).ok() +} + +/// The key `text` spells as the federation does, or why it spells none. +pub(crate) fn spelled(text: &str) -> Result { + let key = Key::parse(text)?; + if let Key::Ed25519(public) = &key + && VerifyingKey::from_bytes(&public.0).is_err() + { + return Err("not a point on Ed25519".to_owned()); + } + if key.line() != text { + return Err(format!( + "not spelled as the federation spells it: `{}`, without a comment", + key.line() + )); + } + Ok(key) } /// Whether `text` is a node ID spelled as continuum spells one. -- cgit v1.3.1