use std::{fs::File, io::Write, path::PathBuf}; use bft_json_crdt::keypair::{make_keypair, KeyPair}; use pem::Pem; /// Makes an Ed25519 keypair and returns the public and private keys as a PEM-encoded string. pub(crate) fn setup() -> String { let keys = make_keypair(); let public_pem = Pem::new("PUBLIC", keys.public().to_string()); let private_pem = Pem::new("PRIVATE", keys.private().to_string()); pem::encode_many(&[public_pem, private_pem]) } /// Writes a PEM-encoded string to a file at key_path. pub(crate) fn write(key_path: PathBuf, pem: String) -> Result<(), std::io::Error> { let mut file = File::create(key_path)?; file.write(pem.to_string().as_bytes())?; Ok(()) }