Add new PlainTextString type to ensure all passwords are valid UTF-8 #2070
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue Addressed
Issue #1205
Feedback from PR #1217
This supersedes my previous PR #1770 .
Proposed Changes
fs::read_to_string
to enforce utf8 when dealing with reading passwords from files.PlainText(Vec<u8>)
to becomePlainText(String)
. This was not possible because I found existing (and valid) instances wherePlainText
contained invalid utf8. I do like the idea of aPlainTextString
though, so this PR introduces a new and more specific type,PlainTextString(String)
. It might be a little clumsy to have two differentPlainText
types, but I think it makes sense.&[u8]
, and I switched some (but not all) to use the newPlainTextString
. Happy to remove what I added if you would like these changed in a followup PR.PlainTextString
type uses anunsafe
block to makeas_mut_bytes
work. This will panic if the caller of this method changes the internal bytes to become invalid utf8. Any ideas around making this more sound?Additional Info
I mentioned this in the other PR but I'm relatively new to rust, so don't hesitate to add lots of feedback!