Skip to content

Commit

Permalink
fix(key): remove any newlines from passphrase
Browse files Browse the repository at this point in the history
To match the behavior of the C code and because there may be newlines
under some conditions.

Signed-off-by: Thomas Mühlbacher <[email protected]>
  • Loading branch information
tmuehlbacher committed Jun 18, 2024
1 parent 87ab1fd commit e4271d7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>) -> Result<Self> {
Expand All @@ -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'))?))
}
}

0 comments on commit e4271d7

Please sign in to comment.