From af9ebfb9e5a7e6d857a8165929d0624be440398c Mon Sep 17 00:00:00 2001 From: Andrey Golovizin Date: Tue, 11 Apr 2023 20:33:03 +0200 Subject: [PATCH] Add a newline when saving keys to files --- src/keys.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/keys.rs b/src/keys.rs index a5b5248..b6dc717 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -3,7 +3,10 @@ use gethostname::gethostname; use log::debug; use x25519_dalek::{PublicKey, StaticSecret}; -use std::path::{Path, PathBuf}; +use std::{ + io::Write, + path::{Path, PathBuf}, +}; use crate::dirs::get_data_dir; @@ -25,13 +28,14 @@ impl Key { BASE64_STANDARD.encode(self.0) } - fn read(path: &Path) -> anyhow::Result { + fn load(path: &Path) -> anyhow::Result { let key_data = std::fs::read_to_string(path)?; - Self::try_from_base64(&key_data) + Self::try_from_base64(&key_data.trim_end()) } - fn write(&self, path: &Path) -> anyhow::Result<()> { - std::fs::write(path, self.to_base64())?; + fn save(&self, path: &Path) -> anyhow::Result<()> { + let mut file = std::fs::File::create(path)?; + writeln!(file, "{}", self.to_base64())?; Ok(()) } } @@ -55,18 +59,18 @@ pub(crate) fn get_keys(machine: Option<&PathBuf>) -> Result