diff --git a/lib/crypto.js b/lib/crypto.js index 53e9d8dc92d4bd..52c29830a473e9 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -66,7 +66,6 @@ function toBuf(str, encoding) { } exports._toBuf = toBuf; - const assert = require('assert'); const StringDecoder = require('string_decoder').StringDecoder; @@ -556,17 +555,16 @@ DiffieHellman.prototype.setPrivateKey = function setPrivateKey(key, encoding) { }; +exports.createECDH = exports.ECDH = ECDH; function ECDH(curve) { + if (!(this instanceof ECDH)) + return new ECDH(curve); if (typeof curve !== 'string') throw new TypeError('"curve" argument should be a string'); this._handle = new binding.ECDH(curve); } -exports.createECDH = function createECDH(curve) { - return new ECDH(curve); -}; - ECDH.prototype.computeSecret = DiffieHellman.prototype.computeSecret; ECDH.prototype.setPrivateKey = DiffieHellman.prototype.setPrivateKey; ECDH.prototype.setPublicKey = DiffieHellman.prototype.setPublicKey; diff --git a/test/parallel/test-crypto-classes.js b/test/parallel/test-crypto-classes.js index 55d76a607e5066..4b63d1b5fab2bf 100644 --- a/test/parallel/test-crypto-classes.js +++ b/test/parallel/test-crypto-classes.js @@ -18,6 +18,7 @@ const TEST_CASES = { 'Verify': ['RSA-SHA1'], 'DiffieHellman': [1024], 'DiffieHellmanGroup': ['modp5'], + 'ECDH': ['prime256v1'], 'Credentials': [] };