diff options
author | Linnnus <[email protected]> | 2024-10-02 17:17:05 +0200 |
---|---|---|
committer | Linnnus <[email protected]> | 2024-10-02 17:17:05 +0200 |
commit | 6aa23b27b5be52bcc6a27b566cf74cc0bc9c763d (patch) | |
tree | 89606bfb8436cecbf351db824e132176431999a4 | |
parent | 3783f68927a1a13c8ddcf96ffc3e78c06963414e (diff) |
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.
-rw-r--r-- | src/config.rs | 1 |
1 files changed, 1 insertions, 0 deletions
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) |