aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/keys.rs
diff options
context:
space:
mode:
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.