remove "display name" from adding new friends

This commit is contained in:
2026-08-28 14:21:36 +08:00
parent a042945f5d
commit eb689210d4
17 changed files with 749 additions and 317 deletions
+29
View File
@@ -1,3 +1,6 @@
use base64::Engine;
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
use ed25519_dalek::VerifyingKey;
use serde::{Deserialize, Serialize};
use specta::Type;
@@ -9,3 +12,29 @@ pub struct User {
pub id: String,
pub display_name: String,
}
pub(crate) fn validate_id(id: &str) -> Result<(), String> {
let bytes = URL_SAFE_NO_PAD
.decode(id)
.map_err(|_| "Identification key is not valid base64url.".to_owned())?;
let bytes: [u8; 32] = bytes
.try_into()
.map_err(|_| "Identification key must encode a 32-byte public key.".to_owned())?;
VerifyingKey::from_bytes(&bytes)
.map(|_| ())
.map_err(|_| "Identification key is not a valid Ed25519 public key.".to_owned())
}
#[cfg(test)]
mod tests {
use ed25519_dalek::SigningKey;
use super::*;
#[test]
fn id_must_be_an_ed25519_public_key() {
let valid = URL_SAFE_NO_PAD.encode(SigningKey::from_bytes(&[7; 32]).verifying_key());
assert!(validate_id(&valid).is_ok());
assert!(validate_id("not a public key").is_err());
}
}