Skip to content

Commit 933d8eb

Browse files
committed
crypto: move createCipher to runtime deprecation
PR-URL: #22089 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Yihong Wang <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 28c70ac commit 933d8eb

5 files changed

+32
-12
lines changed

Diff for: doc/api/deprecations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ Type: End-of-Life
954954
<a id="DEP0106"></a>
955955
### DEP0106: crypto.createCipher and crypto.createDecipher
956956
957-
Type: Documentation-only
957+
Type: Runtime
958958
959959
Using [`crypto.createCipher()`][] and [`crypto.createDecipher()`][] should be
960960
avoided as they use a weak key derivation function (MD5 with no salt) and static

Diff for: lib/crypto.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ function createVerify(algorithm, options) {
140140
module.exports = exports = {
141141
// Methods
142142
_toBuf: toBuf,
143-
createCipher,
144143
createCipheriv,
145-
createDecipher,
146144
createDecipheriv,
147145
createDiffieHellman,
148146
createDiffieHellmanGroup,
@@ -209,6 +207,16 @@ function getFipsForced() {
209207
}
210208

211209
Object.defineProperties(exports, {
210+
createCipher: {
211+
enumerable: false,
212+
value: deprecate(createCipher,
213+
'crypto.createCipher is deprecated.', 'DEP0106')
214+
},
215+
createDecipher: {
216+
enumerable: false,
217+
value: deprecate(createDecipher,
218+
'crypto.createDecipher is deprecated.', 'DEP0106')
219+
},
212220
// crypto.fips is deprecated. DEP0093. Use crypto.getFips()/crypto.setFips()
213221
fips: {
214222
get: !fipsMode ? getFipsDisabled :

Diff for: test/parallel/test-crypto-authenticated.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ const expectedWarnings = common.hasFipsCrypto ?
7171
['Use Cipheriv for counter mode of aes-256-ccm', common.noWarnCode]
7272
];
7373

74-
const expectedDeprecationWarnings = ['crypto.DEFAULT_ENCODING is deprecated.',
75-
'DEP0091'];
74+
const expectedDeprecationWarnings = [
75+
['crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091'],
76+
['crypto.createCipher is deprecated.', 'DEP0106']
77+
];
7678

7779
common.expectWarning({
7880
Warning: expectedWarnings,

Diff for: test/parallel/test-crypto-cipher-decipher.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ if (common.hasFipsCrypto)
1010
const crypto = require('crypto');
1111
const assert = require('assert');
1212

13+
common.expectWarning({
14+
Warning: [
15+
['Use Cipheriv for counter mode of aes-256-gcm', common.noWarnCode]
16+
],
17+
DeprecationWarning: [
18+
['crypto.createCipher is deprecated.', 'DEP0106']
19+
]
20+
});
21+
1322
function testCipher1(key) {
1423
// Test encryption and decryption
1524
const plaintext = 'Keep this a secret? No! Tell everyone about node.js!';
@@ -235,10 +244,6 @@ testCipher2(Buffer.from('0123456789abcdef'));
235244
const aadbuf = Buffer.from('aadbuf');
236245
const data = Buffer.from('test-crypto-cipher-decipher');
237246

238-
common.expectWarning('Warning',
239-
'Use Cipheriv for counter mode of aes-256-gcm',
240-
common.noWarnCode);
241-
242247
const cipher = crypto.createCipher('aes-256-gcm', key);
243248
cipher.setAAD(aadbuf);
244249
cipher.setAutoPadding();

Diff for: test/parallel/test-process-emit-warning-from-native.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ const crypto = require('crypto');
1111
const key = '0123456789';
1212

1313
{
14-
common.expectWarning('Warning',
15-
'Use Cipheriv for counter mode of aes-256-gcm',
16-
common.noWarnCode);
14+
common.expectWarning({
15+
DeprecationWarning: [
16+
['crypto.createCipher is deprecated.', 'DEP0106']
17+
],
18+
Warning: [
19+
['Use Cipheriv for counter mode of aes-256-gcm', common.noWarnCode]
20+
]
21+
});
1722

1823
// Emits regular warning expected by expectWarning()
1924
crypto.createCipher('aes-256-gcm', key);

0 commit comments

Comments
 (0)