From e4271d7a3e5c0197b2a71eb001b93c3d7601847f Mon Sep 17 00:00:00 2001 From: Thomas Mühlbacher Date: Sat, 15 Jun 2024 23:45:06 +0200 Subject: fix(key): remove any newlines from passphrase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To match the behavior of the C code and because there may be newlines under some conditions. Signed-off-by: Thomas Mühlbacher --- src/key.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/key.rs b/src/key.rs index 54959d6e..44f2ad67 100644 --- a/src/key.rs +++ b/src/key.rs @@ -158,7 +158,7 @@ impl Passphrase { line }; - Ok(Self(CString::new(passphrase.as_str())?)) + Ok(Self(CString::new(passphrase.trim_end_matches('\n'))?)) } pub fn new_from_file(sb: &bch_sb_handle, passphrase_file: impl AsRef) -> Result { @@ -172,6 +172,6 @@ impl Passphrase { let passphrase = Zeroizing::new(fs::read_to_string(passphrase_file)?); - Ok(Self(CString::new(passphrase.as_str())?)) + Ok(Self(CString::new(passphrase.trim_end_matches('\n'))?)) } } -- cgit v1.2.3