diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 37cbb20..3c7da1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,13 +86,13 @@ fn unconfigure_link(connection: &Connection) -> Result<()> { } fn read_or_generate_keypair() -> Result<KeyPair> { - Ok(match read_keypair() { - Ok(keypair) => keypair, + match read_keypair() { + Ok(keypair) => Ok(keypair), Err(e) => { println!("[warn] unable to read keypair: {}", e); - KeyPair::generate() + generate_and_save_keypair() } - }) + } } fn read_keypair() -> Result<KeyPair> { @@ -102,6 +102,12 @@ fn read_keypair() -> Result<KeyPair> { Ok(KeyPair::from_private(private_key)) } +fn generate_and_save_keypair() -> Result<KeyPair> { + let keypair = KeyPair::generate(); + fs::write(CONFIGFILE_PRIVATEKEY, keypair.private.to_base64())?; + Ok(keypair) +} + fn read_peers() -> Result<Vec<PeerConfigBuilder>> { let file = File::open(CONFIGFILE_PEERS)?; let br = BufReader::new(file); |