Starting to write config file
This commit is contained in:
21
side-node/src/init/keys.rs
Normal file
21
side-node/src/init/keys.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
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_pem(key_path: PathBuf, pem: String) -> Result<(), std::io::Error> {
|
||||
println!("Writing key to: {:?}", key_path);
|
||||
let mut file = File::create(key_path)?;
|
||||
file.write(pem.to_string().as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user