diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 85922499d42..83a3ca25ea4 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -718,6 +718,9 @@ The `SlowBuffer` class has been removed. Please use -Type: Documentation-only +Type: Runtime -The [`ecdh.setPublicKey()`][] method is now deprecated as its inclusion in the -API is not useful. +The [`ecdh.setPublicKey()`][] method is now deprecated as its inclusion in +the API is not useful. ### DEP0032: `node:domain` module diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index 24ff71fca83..c01427f889f 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -46,6 +46,7 @@ const { } = require('internal/util/types'); const { + deprecate, lazyDOMException, } = require('internal/util'); @@ -228,7 +229,9 @@ function ECDH(curve) { ECDH.prototype.computeSecret = DiffieHellman.prototype.computeSecret; ECDH.prototype.setPrivateKey = DiffieHellman.prototype.setPrivateKey; -ECDH.prototype.setPublicKey = DiffieHellman.prototype.setPublicKey; +ECDH.prototype.setPublicKey = deprecate(DiffieHellman.prototype.setPublicKey, + 'ecdh.setPublicKey() is deprecated.', + 'DEP0031'); ECDH.prototype.getPrivateKey = DiffieHellman.prototype.getPrivateKey; ECDH.prototype.generateKeys = function generateKeys(encoding, format) { diff --git a/test/parallel/test-crypto-ecdh-setpublickey-deprecation.js b/test/parallel/test-crypto-ecdh-setpublickey-deprecation.js new file mode 100644 index 00000000000..81ee561c4ef --- /dev/null +++ b/test/parallel/test-crypto-ecdh-setpublickey-deprecation.js @@ -0,0 +1,24 @@ +// Flags: --no-warnings +'use strict'; + +const common = require('../common'); + +if (!common.hasCrypto) { + common.skip('missing crypto'); +} + +const crypto = require('crypto'); + +common.expectWarning( + 'DeprecationWarning', + 'ecdh.setPublicKey() is deprecated.', 'DEP0031'); + +const ec = crypto.createECDH('secp256k1'); +try { + // This will throw but we don't care about the error, + // we just want to verify that the deprecation warning + // is emitted. + ec.setPublicKey(Buffer.from([123])); +} catch { + // Intentionally ignore the error +}