Skip to content

Commit bffa504

Browse files
committed
crypto: move pbkdf2 without digest to EOL
API has been being incrementally deprecated since 6.0.0 PR-URL: #31166 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 907c07f commit bffa504

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

doc/api/deprecations.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ to the `constants` property exposed by the relevant module. For instance,
236236
### DEP0009: `crypto.pbkdf2` without digest
237237
<!-- YAML
238238
changes:
239+
- version: REPLACEME
240+
pr-url: https://github.com/nodejs/node/pull/31166
241+
description: End-of-Life (for `digest === null`)
239242
- version: v11.0.0
240243
pr-url: https://github.com/nodejs/node/pull/22861
241244
description: Runtime deprecation (for `digest === null`).
@@ -250,7 +253,7 @@ changes:
250253
description: Runtime deprecation (for `digest === undefined`).
251254
-->
252255

253-
Type: Runtime
256+
Type: End-of-Life
254257

255258
Use of the [`crypto.pbkdf2()`][] API without specifying a digest was deprecated
256259
in Node.js 6.0 because the method defaulted to using the non-recommended
@@ -259,9 +262,11 @@ Node.js 8.0.0, calling `crypto.pbkdf2()` or `crypto.pbkdf2Sync()` with
259262
`digest` set to `undefined` will throw a `TypeError`.
260263

261264
Beginning in Node.js v11.0.0, calling these functions with `digest` set to
262-
`null` will print a deprecation warning to align with the behavior when `digest`
265+
`null` would print a deprecation warning to align with the behavior when `digest`
263266
is `undefined`.
264267

268+
Now, however, passing either `undefined` or `null` will throw a `TypeError`.
269+
265270
<a id="DEP0010"></a>
266271
### DEP0010: `crypto.createCredentials`
267272
<!-- YAML

lib/internal/crypto/pbkdf2.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const { AsyncWrap, Providers } = internalBinding('async_wrap');
44
const { Buffer } = require('buffer');
55
const { pbkdf2: _pbkdf2 } = internalBinding('crypto');
66
const { validateUint32 } = require('internal/validators');
7-
const { deprecate } = require('internal/util');
87
const {
98
ERR_CRYPTO_INVALID_DIGEST,
109
ERR_CRYPTO_PBKDF2_ERROR,
@@ -52,17 +51,9 @@ function pbkdf2Sync(password, salt, iterations, keylen, digest) {
5251
return keybuf.toString(encoding);
5352
}
5453

55-
const defaultDigest = deprecate(() => 'sha1',
56-
'Calling pbkdf2 or pbkdf2Sync with "digest" ' +
57-
'set to null is deprecated.',
58-
'DEP0009');
59-
6054
function check(password, salt, iterations, keylen, digest) {
61-
if (typeof digest !== 'string') {
62-
if (digest !== null)
63-
throw new ERR_INVALID_ARG_TYPE('digest', ['string', 'null'], digest);
64-
digest = defaultDigest();
65-
}
55+
if (typeof digest !== 'string')
56+
throw new ERR_INVALID_ARG_TYPE('digest', 'string', digest);
6657

6758
password = getArrayBufferView(password, 'password');
6859
salt = getArrayBufferView(salt, 'salt');

test/parallel/test-crypto-pbkdf2.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ if (!common.hasCrypto)
66
const assert = require('assert');
77
const crypto = require('crypto');
88

9-
common.expectWarning(
10-
'DeprecationWarning',
11-
'Calling pbkdf2 or pbkdf2Sync with "digest" set to null is deprecated.',
12-
'DEP0009');
13-
149
//
1510
// Test PBKDF2 with RFC 6070 test vectors (except #4)
1611
//
@@ -61,7 +56,7 @@ function ondone(err, key) {
6156

6257
// Error path should not leak memory (check with valgrind).
6358
assert.throws(
64-
() => crypto.pbkdf2('password', 'salt', 1, 20, null),
59+
() => crypto.pbkdf2('password', 'salt', 1, 20, 'sha1'),
6560
{
6661
code: 'ERR_INVALID_CALLBACK',
6762
name: 'TypeError'
@@ -127,7 +122,7 @@ assert.throws(
127122
{
128123
code: 'ERR_INVALID_ARG_TYPE',
129124
name: 'TypeError',
130-
message: 'The "digest" argument must be of type string or null. ' +
125+
message: 'The "digest" argument must be of type string. ' +
131126
'Received undefined'
132127
});
133128

@@ -136,10 +131,18 @@ assert.throws(
136131
{
137132
code: 'ERR_INVALID_ARG_TYPE',
138133
name: 'TypeError',
139-
message: 'The "digest" argument must be of type string or null. ' +
134+
message: 'The "digest" argument must be of type string. ' +
140135
'Received undefined'
141136
});
142137

138+
assert.throws(
139+
() => crypto.pbkdf2Sync('password', 'salt', 8, 8, null),
140+
{
141+
code: 'ERR_INVALID_ARG_TYPE',
142+
name: 'TypeError',
143+
message: 'The "digest" argument must be of type string. ' +
144+
'Received null'
145+
});
143146
[1, {}, [], true, undefined, null].forEach((input) => {
144147
const msgPart2 = 'an instance of Buffer, TypedArray, or DataView.' +
145148
common.invalidArgTypeHelper(input);

0 commit comments

Comments
 (0)