{{ message }}
crypto: optimize sign.update() and verify.update()#31767
Closed
bnoordhuis wants to merge 3 commits into
Closed
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.
Collaborator
santigimeno
reviewed
Feb 13, 2020
santigimeno
approved these changes
Feb 13, 2020
addaleax
approved these changes
Feb 13, 2020
cjihrig
approved these changes
Feb 13, 2020
jasnell
approved these changes
Feb 13, 2020
devnexen
approved these changes
Feb 13, 2020
tniessen
approved these changes
Feb 23, 2020
tniessen
left a comment
Member
There was a problem hiding this comment.
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.
Member
Author
|
@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. |
Member
|
@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.
Collaborator
addaleax
pushed a commit
that referenced
this pull request
Mar 11, 2020
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 <santiago.gimeno@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
addaleax
pushed a commit
that referenced
this pull request
Mar 11, 2020
Factor out the common logic into a template function. Removes approximately six instances of copy/pasted code. PR-URL: #31767 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Member
|
Landed in d09e1da...47c2b67 |
MylesBorins
pushed a commit
that referenced
this pull request
Mar 11, 2020
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 <santiago.gimeno@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
MylesBorins
pushed a commit
that referenced
this pull request
Mar 11, 2020
Factor out the common logic into a template function. Removes approximately six instances of copy/pasted code. PR-URL: #31767 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Merged
Member
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The first commit is #31766.
Second commit:
Third commit: