-
Notifications
You must be signed in to change notification settings - Fork 228
password-hash: proposed API changes for Salt/SaltString
#1216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
It looks like you're trying to do quite a few different things in a single PR. Please scope your PRs so they are either focused on a single crate or focused on making cross-cutting changes to all crates. For example, in this PR it would be good if you could just focus on the |
d4778e2 to
ead7d5e
Compare
|
Thanks for the feedback. Let's focus on the |
| /* | ||
| /// Borrow this value as bytes. | ||
| pub fn as_bytes(&self) -> &'a [u8] { | ||
| self.as_str().as_bytes() | ||
| } | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this method because it is misleading in the rust context. Since this would leak a not ideal memory representation
| /// | ||
| /// [1]: https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md#argon2-encoding | ||
| pub fn b64_decode<'b>(&self, buf: &'b mut [u8]) -> Result<&'b [u8]> { | ||
| pub fn to_raw<'b>(&self, buf: &'b mut [u8]) -> Result<&'b [u8]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this name is an improvement
| /// Byte array containing an ASCiI-encoded string. | ||
| bytes: [u8; Salt::MAX_LENGTH], | ||
| /// Byte array containing an ASCiI-encoded string, length always matches the byte length. | ||
| characters: [u8; Salt::MAX_LENGTH], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably suggest the shorter chars
| /// Length of the string in ASCII characters (i.e. bytes). | ||
| length: u8, | ||
| /// Length of the string in ASCII characters in Bytes. | ||
| ascii_length: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is an improvement. ascii_length is the same as the length in bytes.
| /// Encode the given byte slice as B64 into a new [`SaltString`]. | ||
| /// | ||
| /// Returns `None` if the slice is too long. | ||
| pub fn from_raw(input: &[u8]) -> Result<Self> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, not sure this is an improvement. Perhaps from_bytes?
| } | ||
|
|
||
| /// Decode this [`SaltString`] from B64 into the provided output buffer. | ||
| pub fn to_raw<'a>(&self, buf: &'a mut [u8]) -> Result<&'a [u8]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, raw is unclear
| /// Borrow this value as bytes. | ||
| pub fn as_bytes(&self) -> &[u8] { | ||
| self.as_str().as_bytes() | ||
| pub fn as_b64_bytes(&self) -> &[u8] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not wild about this name either
Salt/SaltString
|
I opened #1266 as an alternative |
Making the API for Salt and SaltString better to understand
Initially opened the issue in the wrong repo, sorry for RustCrypto/password-hashes#371