Skip to content

Commit c3b9868

Browse files
committed
crypto: move deprecated hash and mgf1Hash options to EOL
Runtime deprecation for ~3 years. PR-URL: #58706 Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent ce546e4 commit c3b9868

File tree

5 files changed

+28
-137
lines changed

5 files changed

+28
-137
lines changed

doc/api/deprecations.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,9 @@ option, or a non-nullish non-boolean value for `verbatim` option in
32023202

32033203
<!-- YAML
32043204
changes:
3205+
- version: REPLACEME
3206+
pr-url: https://github.com/nodejs/node/pull/58706
3207+
description: End-of-Life.
32053208
- version: v20.0.0
32063209
pr-url: https://github.com/nodejs/node/pull/45653
32073210
description: Runtime deprecation.
@@ -3210,10 +3213,9 @@ changes:
32103213
description: Documentation-only deprecation.
32113214
-->
32123215

3213-
Type: Runtime
3216+
Type: End-of-Life
32143217

3215-
The `'hash'` and `'mgf1Hash'` options are replaced with `'hashAlgorithm'`
3216-
and `'mgf1HashAlgorithm'`.
3218+
Use `'hashAlgorithm'` instead of `'hash'`, and `'mgf1HashAlgorithm'` instead of `'mgf1Hash'`.
32173219

32183220
### DEP0155: Trailing slashes in pattern specifier resolutions
32193221

lib/internal/crypto/keygen.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function createJob(mode, type, options) {
195195
}
196196

197197
const {
198-
hash, mgf1Hash, hashAlgorithm, mgf1HashAlgorithm, saltLength,
198+
hashAlgorithm, mgf1HashAlgorithm, saltLength,
199199
} = options;
200200

201201
if (saltLength !== undefined)
@@ -204,36 +204,36 @@ function createJob(mode, type, options) {
204204
validateString(hashAlgorithm, 'options.hashAlgorithm');
205205
if (mgf1HashAlgorithm !== undefined)
206206
validateString(mgf1HashAlgorithm, 'options.mgf1HashAlgorithm');
207-
if (hash !== undefined) {
208-
process.emitWarning(
209-
'"options.hash" is deprecated, ' +
210-
'use "options.hashAlgorithm" instead.',
211-
'DeprecationWarning',
212-
'DEP0154');
213-
validateString(hash, 'options.hash');
214-
if (hashAlgorithm && hash !== hashAlgorithm) {
215-
throw new ERR_INVALID_ARG_VALUE('options.hash', hash);
216-
}
207+
if (options.hash !== undefined) {
208+
// This API previously accepted a `hash` option that was deprecated
209+
// and removed. However, in order to make the change more visible, we
210+
// opted to throw an error if hash is specified rather than removing it
211+
// entirely.
212+
throw new ERR_INVALID_ARG_VALUE(
213+
'options.hash',
214+
options.hash,
215+
'is no longer supported',
216+
);
217217
}
218-
if (mgf1Hash !== undefined) {
219-
process.emitWarning(
220-
'"options.mgf1Hash" is deprecated, ' +
221-
'use "options.mgf1HashAlgorithm" instead.',
222-
'DeprecationWarning',
223-
'DEP0154');
224-
validateString(mgf1Hash, 'options.mgf1Hash');
225-
if (mgf1HashAlgorithm && mgf1Hash !== mgf1HashAlgorithm) {
226-
throw new ERR_INVALID_ARG_VALUE('options.mgf1Hash', mgf1Hash);
227-
}
218+
if (options.mgf1Hash !== undefined) {
219+
// This API previously accepted a `mgf1Hash` option that was deprecated
220+
// and removed. However, in order to make the change more visible, we
221+
// opted to throw an error if mgf1Hash is specified rather than removing
222+
// it entirely.
223+
throw new ERR_INVALID_ARG_VALUE(
224+
'options.mgf1Hash',
225+
options.mgf1Hash,
226+
'is no longer supported',
227+
);
228228
}
229229

230230
return new RsaKeyPairGenJob(
231231
mode,
232232
kKeyVariantRSA_PSS,
233233
modulusLength,
234234
publicExponent,
235-
hashAlgorithm || hash,
236-
mgf1HashAlgorithm || mgf1Hash,
235+
hashAlgorithm,
236+
mgf1HashAlgorithm,
237237
saltLength,
238238
...encoding);
239239
}

test/parallel/test-crypto-keygen-deprecation.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

test/parallel/test-crypto-keygen-duplicate-deprecated-option.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

test/parallel/test-crypto-keygen.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -800,22 +800,3 @@ const { hasOpenSSL3 } = require('../common/crypto');
800800
message: 'Invalid MGF1 digest: sha2'
801801
});
802802
}
803-
804-
{
805-
// This test makes sure deprecated and new options must
806-
// be the same value.
807-
808-
assert.throws(() => generateKeyPair('rsa-pss', {
809-
modulusLength: 512,
810-
saltLength: 16,
811-
mgf1Hash: 'sha256',
812-
mgf1HashAlgorithm: 'sha1'
813-
}, common.mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE' });
814-
815-
assert.throws(() => generateKeyPair('rsa-pss', {
816-
modulusLength: 512,
817-
saltLength: 16,
818-
hash: 'sha256',
819-
hashAlgorithm: 'sha1'
820-
}, common.mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE' });
821-
}

0 commit comments

Comments
 (0)