Skip to content
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

doc: fix crypto.hkdf callback derivedKey type #39453

Closed
wants to merge 1 commit into from

Conversation

panva
Copy link
Member

@panva panva commented Jul 19, 2021

crypto.hkdf('sha512', 'key', 'salt', 'info', 64, console.log)
// ArrayBuffer {
//  [Uint8Contents]: <24 15 6e 2c 35 52 5b aa f3 d0 fb b9 2b 73 4c 80 32 a1 10 a3 f1 2e 25 96 e4 41 e1 92 48 70 d8 4c 3a 50 06 52 a7 23 73 80 24 43 24 51 04 6f d2 37 ef ad 83 92 fb 68 6c 52 77 a5 9e 01 05 39 16 53>,
//  byteLength: 64
// }

The example snippet below this block as well as hkdfSync are correct in that ArrayBuffer is returned.

@panva panva added crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations. fast-track PRs that do not need to wait for 48 hours to land. labels Jul 19, 2021
@github-actions
Copy link
Contributor

Fast-track has been requested by @panva. Please 👍 to approve.

@panva panva added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 19, 2021
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 19, 2021
@nodejs-github-bot
Copy link
Collaborator

@panva panva requested a review from jasnell July 20, 2021 08:31
@tniessen
Copy link
Member

Buffer is consistent with the rest of the Node.js crypto API though... why does this not return a Buffer? :(

@tniessen
Copy link
Member

So... we have three key derivation functions now: crypto.pbkdf2, crypto.scrypt, and crypto.hkdf. All three accept a callback and all three callbacks accept the arguments (err, derivedKey), but derivedKey has different types?!

@panva
Copy link
Member Author

panva commented Jul 20, 2021

Buffer is consistent with the rest of the Node.js crypto API though... why does this not return a Buffer? :(

@jasnell would be best to answer with confidence. But if i was to guess, hkdf was built in because it is required for the SubtleCrypto interface. As such as it was built with the return types that interface requires and was then just exposed as-is without thinking about it "fitting in" with the rest.

I was also surprised to see ArrayBuffer returned, I expected a Buffer both from "that's how node crypto works" perspective as well as docs.

@panva
Copy link
Member Author

panva commented Jul 20, 2021

@tniessen @jasnell do you see a way we could change the return type to be more fitting now?

@tniessen
Copy link
Member

Personally, I'd consider the current behavior a bug, but even if we changed it to match the documentation, it would be inconsistent with hkdfSync, which returns an ArrayBuffer (and is documented as such). Changing both to return Buffer is either impossible or, at least, semver-major :(

@panva
Copy link
Member Author

panva commented Jul 20, 2021

Screenshot 2021-07-20 at 15 05 36

@tniessen
Copy link
Member

Refs: #39471

@panva panva added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 26, 2021
@github-actions github-actions bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jul 26, 2021
@github-actions
Copy link
Contributor

Commit Queue failed
- Loading data for nodejs/node/pull/39453
✔  Done loading data for nodejs/node/pull/39453
----------------------------------- PR info ------------------------------------
Title      doc: fix crypto.hkdf callback derivedKey type (#39453)
Author     Filip Skokan  (@panva)
Branch     panva:doc-hkdf-fix -> nodejs:master
Labels     crypto, doc, fast-track
Commits    1
 - doc: fix crypto.hkdf callback derivedKey type
Committers 1
 - Filip Skokan 
PR-URL: https://github.com/nodejs/node/pull/39453
Reviewed-By: James M Snell 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/39453
Reviewed-By: James M Snell 
--------------------------------------------------------------------------------
   ℹ  This PR was created on Mon, 19 Jul 2021 20:42:16 GMT
   ✔  Approvals: 1
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/39453#pullrequestreview-710559837
   ℹ  This PR is being fast-tracked
   ✖  This PR needs to wait 3 more hours to land (or 0 hours if there is one more approval)
   ✔  Last GitHub Actions successful
   ℹ  Green GitHub Actions CI is sufficient
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/1066883872

@panva panva added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Jul 26, 2021
@github-actions github-actions bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 26, 2021
@github-actions
Copy link
Contributor

Landed in c1354ff...5ad6a99

@github-actions github-actions bot closed this Jul 26, 2021
nodejs-github-bot pushed a commit that referenced this pull request Jul 26, 2021
PR-URL: #39453
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Aug 2, 2021
PR-URL: #39453
Reviewed-By: James M Snell <jasnell@gmail.com>
@targos targos mentioned this pull request Aug 2, 2021
@panva panva deleted the doc-hkdf-fix branch October 13, 2022 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations. fast-track PRs that do not need to wait for 48 hours to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants