-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
crypto: optimize sign.update() and verify.update() #31767
Conversation
Make the cipher/decipher/hash/hmac update() methods ignore the input encoding when the input is a buffer. This is the documented behavior but some inputs were rejected, notably when the specified encoding is 'hex' and the buffer has an odd length (because a _string_ with an odd length is never a valid hex string.) The sign/verify update() methods work okay because they use different validation logic. Fixes: nodejs#31751
Use `StringBytes::InlineDecoder` to decode strings inputs in C++ land instead of decoding them to buffers in JS land before passing them on to the C++ layer. This is what the other update() methods already did.
Factor out the common logic into a template function. Removes approximately six instances of copy/pasted code.
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.
LGTM, but I am wondering if it makes sense to return a ByteSource
instead of calling lambdas here? It doesn't solve the unwrapping, but the lambda obscures the control flow in my opinion. ByteSource
can deal with static and dynamically allocated memory.
@tniessen I'm afraid I'm not following. If you want to open an alternate PR, I'll be happy to review it and abandon this one. |
@bnoordhuis Sorry, I didn't have time to try that yet. I am okay with the change as it is, it is definitely an improvement, and if I ever end up attempting something else, we can still change it, so I would suggest to land this :-) |
This comment has been minimized.
This comment has been minimized.
Use `StringBytes::InlineDecoder` to decode strings inputs in C++ land instead of decoding them to buffers in JS land before passing them on to the C++ layer. This is what the other update() methods already did. PR-URL: #31767 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Factor out the common logic into a template function. Removes approximately six instances of copy/pasted code. PR-URL: #31767 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Landed in d09e1da...47c2b67 |
Use `StringBytes::InlineDecoder` to decode strings inputs in C++ land instead of decoding them to buffers in JS land before passing them on to the C++ layer. This is what the other update() methods already did. PR-URL: #31767 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Factor out the common logic into a template function. Removes approximately six instances of copy/pasted code. PR-URL: #31767 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
The second commit doesn't land cleanly on v12.x because it's on top of a semver-major change. Please open a backport PR or change the label to |
The first commit is #31766.
Second commit:
Third commit: