Server structure

This commit is contained in:
2026-08-11 22:07:02 -04:00
parent 79366a28d0
commit c910769eb3
5 changed files with 278 additions and 28 deletions
+21
View File
@@ -0,0 +1,21 @@
use std::path::PathBuf;
use ed25519_dalek::SigningKey;
use rand::rngs::OsRng;
pub async fn get() -> anyhow::Result<SigningKey> {
let private_key_path = PathBuf::from("private.key");
if !private_key_path.exists() {
let key = SigningKey::generate(&mut OsRng);
tokio::fs::write(private_key_path, &key.to_bytes()).await?;
Ok(key)
} else {
Ok(SigningKey::from_bytes(
&tokio::fs::read(private_key_path)
.await?
.try_into()
.map_err(|_| anyhow::anyhow!("Invalid private key"))?,
))
}
}