lib,doc: remove unused parameter, improve docs

1) Remove 'callback' in 'check' function, because we don't check or use
that directly.

2) Make 'digest' clearer in the documentation.

PR-URL: https://github.com/nodejs/node/pull/22858
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
MaleDong 2018-09-14 16:13:14 +08:00 committed by Tobias Nießen
parent 8989c76c6e
commit ba0b4e43e4
No known key found for this signature in database
GPG Key ID: 718207F8FD156B70
2 changed files with 9 additions and 3 deletions

View File

@ -1786,6 +1786,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 `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. 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 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, higher the number of iterations, the more secure the derived key will be,
but will take a longer amount of time to complete. but will take a longer amount of time to complete.
@ -1849,6 +1852,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 If an error occurs an `Error` will be thrown, otherwise the derived key will be
returned as a [`Buffer`][]. 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 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, higher the number of iterations, the more secure the derived key will be,
but will take a longer amount of time to complete. but will take a longer amount of time to complete.

View File

@ -23,7 +23,7 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) {
} }
({ password, salt, iterations, keylen, digest } = ({ password, salt, iterations, keylen, digest } =
check(password, salt, iterations, keylen, digest, callback)); check(password, salt, iterations, keylen, digest));
if (typeof callback !== 'function') if (typeof callback !== 'function')
throw new ERR_INVALID_CALLBACK(); throw new ERR_INVALID_CALLBACK();
@ -43,7 +43,7 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) {
function pbkdf2Sync(password, salt, iterations, keylen, digest) { function pbkdf2Sync(password, salt, iterations, keylen, digest) {
({ 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); const keybuf = Buffer.alloc(keylen);
handleError(keybuf, password, salt, iterations, digest); handleError(keybuf, password, salt, iterations, digest);
const encoding = getDefaultEncoding(); const encoding = getDefaultEncoding();
@ -51,7 +51,7 @@ function pbkdf2Sync(password, salt, iterations, keylen, digest) {
return keybuf.toString(encoding); return keybuf.toString(encoding);
} }
function check(password, salt, iterations, keylen, digest, callback) { function check(password, salt, iterations, keylen, digest) {
if (typeof digest !== 'string') { if (typeof digest !== 'string') {
if (digest !== null) if (digest !== null)
throw new ERR_INVALID_ARG_TYPE('digest', ['string', 'null'], digest); throw new ERR_INVALID_ARG_TYPE('digest', ['string', 'null'], digest);