Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upcrypto: add Hash.prototype.copy() method #29910
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
overlookmotel
commented
Oct 10, 2019
|
Author of #29903 here. I wasn't able to help with implementation of this feature as I don't know C/C++. But if anything I can do here on docs or testing, or anything involving JS, please shout. Really appreciate this being added to Node. |
overlookmotel left a comment •
|
Could be good to add to end of Use |
| of the current `Hash` object. | ||
|
|
||
| The optional `options` argument controls stream behavior. For XOF hash | ||
| functions such as `'shake256'`, the `outputLength` option can be used to |
This comment has been minimized.
This comment has been minimized.
sam-github
Oct 10, 2019
Member
https://nodejs.org/api/stream.html#stream_new_stream_transform_options doesn't have an outputLength option!
It looks like the options are "whatever crypto.createHash() accepts", and that the crypto.createHash docs are wrong, https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options, and got copied here.
You could fix the createHash docs, but that's unrelated to this feature, perhaps just change the docs here to link to them and say "same options as over there", so when the createHash docs get fixed this will be fixed, too.
This comment has been minimized.
This comment has been minimized.
bnoordhuis
Oct 15, 2019
Author
Member
Personally, I don't think it's too confusing but I can split it off into a separate issue if you like.
This comment has been minimized.
This comment has been minimized.
|
Could this suffer from problems similar to #28245 depending on OpenSSL internals, since we don't always set |
This comment has been minimized.
This comment has been minimized.
Interesting question. I don't believe it actually hurts to copy a finalized hash object, it's just pointless (and that's why I added the guard.) |
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
|
Example added to the documentation.
I didn't use that because it can be construed as meaning that copy() after digest() should work when it doesn't. Food for thought: we could also make const hash = crypto.createHash('sha256');
const one = hash.update('one').digest();
const two = hash.update('two').digest();The downside is that it imposes a (possibly small) performance penalty on single-use hash objects. |
This comment has been minimized.
This comment has been minimized.
overlookmotel
commented
Oct 15, 2019
|
@bnoordhuis Only problem with that is that some people feel that the hash object should be reusable in that its internal state is reset after a call to It's not so hard to call |
This comment has been minimized.
This comment has been minimized.
|
I don't think it is a good idea to implicitely reset the internal state of the object in
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
overlookmotel
commented
Oct 16, 2019
|
@tniessen Ah sorry I wasn't clear. I understand this is not what With this code: const hash = crypto.createHash('md5');
hash.update('abc');
hash.digest('hex');
hash.update('def');
const res = hash.digest('hex');
My expectation would be (1), but it seems from #25857 that some people would expect (2). Personally I think there's little merit to the arguments made by the OP in that issue. But since there are seemingly different opinions, it could lead to confusion and bugs as you say. So I was trying to say: probably it's safer to keep behavior of Hope that make more sense. |
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot
commented
Oct 16, 2019
•
This comment has been minimized.
This comment has been minimized.
|
Landed in 9f203f9 |
Make it possible to clone the internal state of a Hash object into a new Hash object, i.e., to fork the state of the object. Fixes: #29903 PR-URL: #29910 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This comment has been minimized.
This comment has been minimized.
overlookmotel
commented
Oct 16, 2019
|
Fantastic. Thanks very much @bnoordhuis for implementing this and everyone else for reviewing. Can I ask: Is this likely to get into a Node 12.x release before it goes LTS? |
This comment has been minimized.
This comment has been minimized.
Probably not before it goes LTS but probably the next release after that one. /ping @nodejs/releasers in case I'm wrong about that. |
This comment has been minimized.
This comment has been minimized.
overlookmotel
commented
Oct 16, 2019
|
Ah OK great. My mistake - I was confusing the Active and Maintenance phases in terms of when new features can be added, so was wrongly thinking this might not land in an LTS release line until 14.x. |
This comment has been minimized.
This comment has been minimized.
|
@overlookmotel Thanks for the clarification, I absolutely agree. Resetting the state in |
This comment has been minimized.
This comment has been minimized.
|
It seems the YAML processing is broken for this doc section. IIRC, we usually use this structure with PR URL field only in history entries. |
This fixes YAML that gets incorrectly processed by our tooling. Refs: nodejs#29910 (comment)
This fixes YAML that gets incorrectly processed by our tooling. Refs: nodejs#29910 (comment) PR-URL: nodejs#30016 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Make it possible to clone the internal state of a Hash object into a new Hash object, i.e., to fork the state of the object. Fixes: #29903 PR-URL: #29910 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This fixes YAML that gets incorrectly processed by our tooling. Refs: #29910 (comment) PR-URL: #30016 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Make it possible to clone the internal state of a Hash object into a new Hash object, i.e., to fork the state of the object. Fixes: #29903 PR-URL: #29910 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This fixes YAML that gets incorrectly processed by our tooling. Refs: #29910 (comment) PR-URL: #30016 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Notable changes:
* cli:
* Added a new flag (`--trace-uncaught`) that makes Node.js print the
stack trace at the time of throwing uncaught exceptions, rather than
at the creation of the `Error` object, if there is any. This is
disabled by default because it affects GC behavior.
#30025
* crypto
* Added `Hash.prototype.copy()` method. It returns a new `Hash` object
with its internal state cloned from the original one.
#29910
* dgram
* Added source-specific multicast support. This adds methods to
Datagram sockets to support RFC 4607
(https://tools.ietf.org/html/rfc4607) for IPv4 and IPv6.
#15735
* fs
* Added a `bufferSize` option to `fs.opendir()`. It allows to control
the number of entries that are buffered internally when reading from
the directory. #30114
* meta
* Added Chengzhong Wu (https://github.com/legendecas) to
collaborators. #30115
PR-URL: #30262
Notable changes:
* cli:
* Added a new flag (`--trace-uncaught`) that makes Node.js print the
stack trace at the time of throwing uncaught exceptions, rather than
at the creation of the `Error` object, if there is any. This is
disabled by default because it affects GC behavior.
#30025
* crypto
* Added `Hash.prototype.copy()` method. It returns a new `Hash` object
with its internal state cloned from the original one.
#29910
* dgram
* Added source-specific multicast support. This adds methods to
Datagram sockets to support RFC 4607
(https://tools.ietf.org/html/rfc4607) for IPv4 and IPv6.
#15735
* fs
* Added a `bufferSize` option to `fs.opendir()`. It allows to control
the number of entries that are buffered internally when reading from
the directory. #30114
* meta
* Added Chengzhong Wu (https://github.com/legendecas) to
collaborators. #30115
PR-URL: #30262

bnoordhuis commentedOct 9, 2019
Make it possible to clone the internal state of a Hash object
into a new Hash object, i.e., to fork the state of the object.
Fixes: #29903