Refactoring of the pbkdf2 crate.#20
Refactoring of the pbkdf2 crate.#20jfrimmel wants to merge 11 commits intoRustCrypto:masterfrom jfrimmel:cleanup
pbkdf2 crate.#20Conversation
This makes the PR compatible to Rust 1.22.
|
Do you want to keep the minimum Rust version of 1.22? Some dependencies (e.g. rand) could also be updated, if the MSRV is bumped |
newpavlov
left a comment
There was a problem hiding this comment.
Thank you! Looks good!
But I think we can add a small optimization.
pbkdf2/src/simple.rs
Outdated
|
|
||
| // check the format of the input: there may be no tokens before the first | ||
| // and after the last `$`, tokens must have correct information and length. | ||
| let (count, salt, hash) = match parts[..] { |
There was a problem hiding this comment.
I think you can remove the allocation and be compatible with Rust 1.22 by using:
let mut p = hashed_value.split('$');
let buf = [
p.next(), p.next(), p.next(), p.next(),
p.next(), p.next(), p.next(), p.next(),
];
let (count, salt, hash) = match buf {
[
Some(""), Some("rpbkdf2"), Some("0"), Some(count),
Some(salt), Some(hash), Some(""), None,
] => (count, salt, hash),
_ => return Err(CheckError::InvalidFormat),
};Also it looks like Err(CheckError::InvalidFormat)? is discouraged (e.g. by clippy), so we probably better to replace it with an explicit return.
There was a problem hiding this comment.
Thank you for your suggestion. I will remove the unnecessary allocation (I wasn't happy with it, too) by applying your changes 😄
Unfortunately, I don't think, that Rust 1.22 will support this code as well.
Edit: but I have an Idea how to do this in Rust 1.22. I'll update this PR soon
|
This will fix #17, correct? |
Unfortunately no, since this PR does not increase the MSRV. This would be required to use Rand 0.7. |
|
@jfrimmel can you rebase? we've bumped MSRV to 1.41+ |
|
I've included your refactor into #33. |
This PR applies refactoring to the
pbkdf2crate, especially for thesimplemodule.It is best viewed commit by commit.