aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/keys.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-18 20:10:53 +0000
committertv <tv@krebsco.de>2026-11-18 21:17:46 +0100
commit657765cc512743c248d71b852b4f2e81fa124af7 (patch)
tree546fca8830af331b448786a1d757f41cd56f1232 /src/federation/keys.rs
parent79614926332977718956f35e1adf80ae67e219f1 (diff)
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.
Diffstat (limited to 'src/federation/keys.rs')
-rw-r--r--src/federation/keys.rs24
1 files changed, 18 insertions, 6 deletions
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<Key> {
- 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<Key, String> {
+ 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.