-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
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...) |
Plus i made sure to mention so in the method's documentation. |
96301e1
to
856c82a
Compare
This comment has been minimized.
This comment has been minimized.
Sure, but that doesn't prevent code that uses Why is |
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 |
@panva ... I don't think |
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. |
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. |
Would this be less controversial then? KeyObject.isKeyObject(any)
KeyObject.isCryptoKey(any) |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
@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
|
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. |
@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 :) |
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'd love to see an example where this helps across contexts, maybe even an added test.
Landed in 3ee1f9a |
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 |
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?) |
The WebCrypto API doesn't exist in versions <15.x |
closes #38611
cc @tniessen @mscdex @nodejs/crypto @nodejs/util