Skip to content

Commit

Permalink
lib,doc: remove unused parameter, improve docs
Browse files Browse the repository at this point in the history
1) Remove 'callback' in 'check' function, because we don't check or use
that directly.

2) Make 'digest' clearer in the documentation.

PR-URL: #22858
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
MaleDong authored and targos committed Sep 19, 2018
1 parent f297866 commit c68addd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,9 @@ otherwise `err` will be `null`. By default, the successfully generated
`derivedKey` will be passed to the callback as a [`Buffer`][]. An error will be
thrown if any of the input arguments specify invalid values or types.

If `digest` is `null`, `'sha1'` will be used. This behavior will be deprecated
in a future version of Node.js.

The `iterations` argument must be a number set as high as possible. The
higher the number of iterations, the more secure the derived key will be,
but will take a longer amount of time to complete.
Expand Down Expand Up @@ -1871,6 +1874,9 @@ applied to derive a key of the requested byte length (`keylen`) from the
If an error occurs an `Error` will be thrown, otherwise the derived key will be
returned as a [`Buffer`][].

If `digest` is `null`, `'sha1'` will be used. This behavior will be deprecated
in a future version of Node.js.

The `iterations` argument must be a number set as high as possible. The
higher the number of iterations, the more secure the derived key will be,
but will take a longer amount of time to complete.
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/crypto/pbkdf2.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) {
}

({ password, salt, iterations, keylen, digest } =
check(password, salt, iterations, keylen, digest, callback));
check(password, salt, iterations, keylen, digest));

if (typeof callback !== 'function')
throw new ERR_INVALID_CALLBACK();
Expand All @@ -42,15 +42,15 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) {

function pbkdf2Sync(password, salt, iterations, keylen, digest) {
({ password, salt, iterations, keylen, digest } =
check(password, salt, iterations, keylen, digest, pbkdf2Sync));
check(password, salt, iterations, keylen, digest));
const keybuf = Buffer.alloc(keylen);
handleError(keybuf, password, salt, iterations, digest);
const encoding = getDefaultEncoding();
if (encoding === 'buffer') return keybuf;
return keybuf.toString(encoding);
}

function check(password, salt, iterations, keylen, digest, callback) {
function check(password, salt, iterations, keylen, digest) {
if (typeof digest !== 'string') {
if (digest !== null)
throw new ERR_INVALID_ARG_TYPE('digest', ['string', 'null'], digest);
Expand Down

0 comments on commit c68addd

Please sign in to comment.