Skip to content

Commit 6663264

Browse files
authored
crypto: runtime deprecate ECDH.setPublicKey()
It's been "pending" deprecation since 6.12.0. I think that's long enough. PR-URL: #58620 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 308b6bc commit 6663264

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

doc/api/deprecations.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,9 @@ The `SlowBuffer` class has been removed. Please use
718718

719719
<!-- YAML
720720
changes:
721+
- version: REPLACEME
722+
pr-url: https://github.com/nodejs/node/pull/58620
723+
description: Runtime deprecation.
721724
- version: v6.12.0
722725
pr-url: https://github.com/nodejs/node/pull/10116
723726
description: A deprecation code has been assigned.
@@ -726,10 +729,10 @@ changes:
726729
description: Documentation-only deprecation.
727730
-->
728731

729-
Type: Documentation-only
732+
Type: Runtime
730733

731-
The [`ecdh.setPublicKey()`][] method is now deprecated as its inclusion in the
732-
API is not useful.
734+
The [`ecdh.setPublicKey()`][] method is now deprecated as its inclusion in
735+
the API is not useful.
733736

734737
### DEP0032: `node:domain` module
735738

lib/internal/crypto/diffiehellman.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const {
4646
} = require('internal/util/types');
4747

4848
const {
49+
deprecate,
4950
lazyDOMException,
5051
} = require('internal/util');
5152

@@ -228,7 +229,9 @@ function ECDH(curve) {
228229

229230
ECDH.prototype.computeSecret = DiffieHellman.prototype.computeSecret;
230231
ECDH.prototype.setPrivateKey = DiffieHellman.prototype.setPrivateKey;
231-
ECDH.prototype.setPublicKey = DiffieHellman.prototype.setPublicKey;
232+
ECDH.prototype.setPublicKey = deprecate(DiffieHellman.prototype.setPublicKey,
233+
'ecdh.setPublicKey() is deprecated.',
234+
'DEP0031');
232235
ECDH.prototype.getPrivateKey = DiffieHellman.prototype.getPrivateKey;
233236

234237
ECDH.prototype.generateKeys = function generateKeys(encoding, format) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Flags: --no-warnings
2+
'use strict';
3+
4+
const common = require('../common');
5+
6+
if (!common.hasCrypto) {
7+
common.skip('missing crypto');
8+
}
9+
10+
const crypto = require('crypto');
11+
12+
common.expectWarning(
13+
'DeprecationWarning',
14+
'ecdh.setPublicKey() is deprecated.', 'DEP0031');
15+
16+
const ec = crypto.createECDH('secp256k1');
17+
try {
18+
// This will throw but we don't care about the error,
19+
// we just want to verify that the deprecation warning
20+
// is emitted.
21+
ec.setPublicKey(Buffer.from([123]));
22+
} catch {
23+
// Intentionally ignore the error
24+
}

0 commit comments

Comments
 (0)