Skip to content
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

Improve error message for invalid privkey length #97

Merged
merged 1 commit into from
Aug 17, 2023

Conversation

sangaman
Copy link
Contributor

This adds a more specific error message when a Uint8Array is provided for a privkey but it does not have the correct length. Previously, the error message stated "Uint8Array expected" - which is confusing because a Uint8Array was in fact provided. This should make debugging invalid privkeys easier.

A test case is added that checks for the new error message.

@paulmillr
Copy link
Owner

How about we keep one error, but make it more descriptive e.g. "Uint8Array of valid length expected"?

@sangaman
Copy link
Contributor Author

How about we keep one error, but make it more descriptive e.g. "Uint8Array of valid length expected"?

Personally I think the separate error messages are a bit more helpful because it tells you exactly what the problem is without further investigation, although a single descriptive message would still be an improvement. I just helped a colleague through debugging this error and only figured out it was due to length (passing 64 bytes instead of 32 due to decoding a hex string as utf8 earlier in the code) after many sanity checks that the variable we were passing was, in fact, a Uint8array. "Uint8Array of valid length expected" would've helped but "Invalid Uint8Array length" would've saved us one more check.

That said, it's your repo so I can change this to "Uint8Array of valid length expected" if you think that's best. Thanks for all your excellent cryptography libraries.

@paulmillr
Copy link
Owner

yes, please change to my suggested format

This adds detail to the error message when a Uint8Array is provided as
a privkey but it does not have the correct length. Previously, the error
message stated only "Uint8Array expected" - which is confusing because a
Uint8Array was in fact provided. This should make debugging invalid
privkeys easier.

A test case is added that checks for the new error message.
@sangaman
Copy link
Contributor Author

yes, please change to my suggested format

Done.

@paulmillr paulmillr merged commit 6e4b160 into paulmillr:main Aug 17, 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.

None yet

2 participants