-
Notifications
You must be signed in to change notification settings - Fork 53
Document error kinds and remove dead BcryptError::Io branch
#93
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
base: master
Are you sure you want to change the base?
Conversation
While looking at how best to handle this error, I found that it's actually not used.
| /// Cost is provided as an argument to hashing functions, and extracted from the hash in | ||
| /// verification functions. |
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 pointed out where the cost value comes from because if this error is raised from bcrypt::hash(), it was actually a programmer error, and if you have a hardcoded cost you can just handle that branch with unreachable!(). But during verification it means the hash was malformed which is something you have to deal with always.
src/errors.rs
Outdated
| InvalidHash(String), | ||
| /// Raised when verifying against an incorrectly formatted hash. | ||
| InvalidSaltLen(usize), | ||
| /// Raised when verifying against an incorrectly formatted hash. |
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.
All those different errors mapping to the same thing makes me thing it should probably a single error with details in the string
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.
Sorta thought the same while doing it, I think as a user you wouldn't do different things for these different branches. I didn't change it already because they have different data inside the branch (like the length of the salt for InvalidSaltLen, but that might also not be that useful. I'll change it to a single branch later today so you can see if you like it :)
|
In the latest commit I've changed the errors that can occur when parsing a hash for verification to be |
|
FWIW I recently revamped the error type in the That's trying to be a sort of universal error type for this case, so I'd be curious how well it lines up with yours and what features anyone things are missing. Also, with the latest prereleases of |
|
I think one variant makes sense. I'm not familiar with password-hash but i guess once there is a new release we can look at maybe implementing the trait behind a feature |
Hi! I was looking into how I should best handle the errors returned by
bcryptin my web service. I especially wasn't sure what conditions some errors could be raised under.This PR documents whether errors can happen during hashing or verification, so users can more easily decide what they want to do with the different error cases.
Additionally, the
BcryptError::Iobranch appears to be unused, so I suggest removing it outright 😇