Uh oh!
There was an error while loading. Please reload this page.
util: add util.types.isKeyObject and util.types.isCryptoKey - #38619
Conversation
This would be the first visible deviation from the WebCrypto standard, wouldn't it? It might not be a violation of the spec since we are still implementing the required interface members, but it would still add a non-standard function to a standard class. One of the very few benefits of WebCrypto is portability, and this change appears to reduce that further. (But we are already doing that with Node.js specific algorithms, so...) |
panva
commented
May 10, 2021
Plus i made sure to mention so in the method's documentation. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
96301e1 to
856c82aCompare
This comment has been minimized.
This comment has been minimized.
tniessen
commented
May 10, 2021
Sure, but that doesn't prevent code that uses Why is |
jasnell
commented
May 10, 2021
None of the JavaScript or Web Platform standards that I'm aware of include APIs for brand checks like this. Node.js has always been unique in doing so (e.g. Other platforms don't solve this. Most rely on |
jasnell
commented
May 10, 2021
@panva ... I don't think |
panva
commented
May 10, 2021
I don't see a problem per se, but i'm fine with going either way. Depends on what the (hopefully) coming consensus here is going to be. |
tniessen
commented
May 10, 2021
As I said before, here and in various other places, from my perspective, the main benefit of having WebCrypto in Node.js is compatibility with other systems that implement the same standard. |
panva
commented
May 10, 2021
Would this be less controversial then? KeyObject.isKeyObject(any)KeyObject.isCryptoKey(any) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
tniessen
commented
May 10, 2021
|
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot
commented
May 14, 2021
tniessen
commented
May 14, 2021
@panva Your code LGTM :) But, to be honest, I'm confused. I'd like to ask a few more things for my own understanding. From #38611 (comment):
I traced the current behavior back to at least 22c68fd, which was eight years ago: Lines 508 to 510 in 22c68fd It appears to be the same logic that's still there today, so while the detection method probably changed in the past, it's been stable for at least eight years: Lines 507 to 509 in 70157b9
@jasnell Is there a fundamental difference between
@jasnell I am trying to come up with a scenario in which I don't usually use the
|
panva
commented
May 14, 2021
I have yet to come across the need to verify user input is Cipher, Hash, or Hmac. KeyObject/CryptoKey OTOH is much more likely to be a function input, specifically one that needs to be distinguished from Buffers, strings, objects that are otherwise accepted in the same argument.
I didn't know better at the time 🤷 as shown above doing instanceof is leaving performance on the table. |
tniessen
commented
May 14, 2021
@panva Neither of us should have to justify the design choices back then, I was just recapping for context. I think all your contributions to the crypto APIs were well-designed :) |
tniessen
left a comment
There was a problem hiding this comment.
LGTM but I'd love to see an example where this helps across contexts, maybe even an added test.
panva
commented
May 17, 2021
Landed in 3ee1f9a |
tniessen
commented
May 18, 2021
I realize that this was landed, but there are still some unanswered questions...
|
Notable changes: async_hooks: * (SEMVER-MINOR) use new v8::Context PromiseHook API (Stephen Belanger) #36394 lib: * support setting process.env.TZ on windows (James M Snell) #38642 module: * (SEMVER-MINOR) add support for `URL` to `import.meta.resolve` (Antoine du Hamel) #38587 process: * (SEMVER-MINOR) add `'worker'` event (James M Snell) #38659 util: * (SEMVER-MINOR) add util.types.isKeyObject and util.types.isCryptoKey (Filip Skokan) #38619 PR-URL: #38719
Notable changes: async_hooks: * (SEMVER-MINOR) use new v8::Context PromiseHook API (Stephen Belanger) #36394 lib: * support setting process.env.TZ on windows (James M Snell) #38642 module: * (SEMVER-MINOR) add support for `URL` to `import.meta.resolve` (Antoine du Hamel) #38587 process: * (SEMVER-MINOR) add `'worker'` event (James M Snell) #38659 util: * (SEMVER-MINOR) add util.types.isKeyObject and util.types.isCryptoKey (Filip Skokan) #38619 PR-URL: #38719
In the most typical case the context stuff won't matter, you're right, because even with the vm module, As for |
tniessen
commented
May 18, 2021
Thank you for the explanation, @jasnell! |
Notable changes: async_hooks: * (SEMVER-MINOR) use new v8::Context PromiseHook API (Stephen Belanger) #36394 lib: * support setting process.env.TZ on windows (James M Snell) #38642 module: * (SEMVER-MINOR) add support for `URL` to `import.meta.resolve` (Antoine du Hamel) #38587 process: * (SEMVER-MINOR) add `'worker'` event (James M Snell) #38659 util: * (SEMVER-MINOR) add util.types.isKeyObject and util.types.isCryptoKey (Filip Skokan) #38619 PR-URL: #38719
Notable changes: async_hooks: * (SEMVER-MINOR) use new v8::Context PromiseHook API (Stephen Belanger) #36394 lib: * support setting process.env.TZ on windows (James M Snell) #38642 module: * (SEMVER-MINOR) add support for `URL` to `import.meta.resolve` (Antoine du Hamel) #38587 process: * (SEMVER-MINOR) add `'worker'` event (James M Snell) #38659 util: * (SEMVER-MINOR) add util.types.isKeyObject and util.types.isCryptoKey (Filip Skokan) #38619 PR-URL: #38719
@nodejs/backporters leaving a note here that if backport were to happen to do so for (not sure i'm following the process right here, please correct me if i'm wrong to request a backport, or if i can open a backport PR myself?) |
targos
commented
Sep 4, 2021
The WebCrypto API doesn't exist in versions <15.x |
closes#38611
cc @tniessen@mscdex @nodejs/crypto @nodejs/util