From 6aa23b27b5be52bcc6a27b566cf74cc0bc9c763d Mon Sep 17 00:00:00 2001 From: Linnnus Date: Wed, 2 Oct 2024 17:17:05 +0200 Subject: Trim end of string when reading secret file Originally I used something akin to printf "mysecret" >secret.txt to avoid adding a newline to the end of the file, but that doesn't work for more advanced usecases, such as when using agenix to edit an encryped secret (Vim really likes to add final newlines). Since the addition/lack of a newline affects the resulting hash, this is pretty important. I opted to just trim the end of the file, since that's probably what the user wants and isn't likely to break anything. I don't think it's even possible to submit a secret containing final whitespace through GitHub's web interface anyways. --- src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.rs b/src/config.rs index 7254887..b929be0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -40,6 +40,7 @@ impl Config { which is most likely not what you want!"); } config.secret = fs::read_to_string(&config.secret_path) + .map(|mut s| { s.truncate(s.trim_end().len()); s }) .map_err(ConfigError::IoReadingSecret)?; Ok(config) -- cgit v1.2.3