Skip to content

Conversation

@dns2utf8
Copy link

Making the API for Salt and SaltString better to understand

  • Update lints to 2021
  • Rustify the API

Initially opened the issue in the wrong repo, sorry for RustCrypto/password-hashes#371

@tarcieri
Copy link
Member

tarcieri commented Jan 24, 2023

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 password-hash crate rather than trying to change unrelated lints in other crates.

@dns2utf8
Copy link
Author

Thanks for the feedback. Let's focus on the Salt and SaltString here.

Comment on lines +146 to +151
/*
/// Borrow this value as bytes.
pub fn as_bytes(&self) -> &'a [u8] {
self.as_str().as_bytes()
}
*/
Copy link
Author

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]> {
Copy link
Member

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],
Copy link
Member

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,
Copy link
Member

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> {
Copy link
Member

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]> {
Copy link
Member

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] {
Copy link
Member

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

@tarcieri tarcieri changed the title Rustify the api password-hash: proposed API changes for Salt/SaltString Feb 8, 2023
@tarcieri
Copy link
Member

tarcieri commented Mar 4, 2023

I opened #1266 as an alternative

@tarcieri tarcieri closed this Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants