Skip to content

Commit f3b3437

Browse files
benglMylesBorins
authored andcommitted
crypto: expose ECDH class
For consistency with the rest of the crypto classes, exposes the ECDH class. Originally, only the createECDH function was exposed, and there was no real reason to hide the class. Backport-PR-URL: #16245 PR-URL: #8188 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent d29a620 commit f3b3437

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

lib/crypto.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ function toBuf(str, encoding) {
4646
}
4747
exports._toBuf = toBuf;
4848

49-
5049
const assert = require('assert');
5150
const StringDecoder = require('string_decoder').StringDecoder;
5251

@@ -536,17 +535,16 @@ DiffieHellman.prototype.setPrivateKey = function setPrivateKey(key, encoding) {
536535
};
537536

538537

538+
exports.createECDH = exports.ECDH = ECDH;
539539
function ECDH(curve) {
540+
if (!(this instanceof ECDH))
541+
return new ECDH(curve);
540542
if (typeof curve !== 'string')
541543
throw new TypeError('"curve" argument should be a string');
542544

543545
this._handle = new binding.ECDH(curve);
544546
}
545547

546-
exports.createECDH = function createECDH(curve) {
547-
return new ECDH(curve);
548-
};
549-
550548
ECDH.prototype.computeSecret = DiffieHellman.prototype.computeSecret;
551549
ECDH.prototype.setPrivateKey = DiffieHellman.prototype.setPrivateKey;
552550
ECDH.prototype.setPublicKey = DiffieHellman.prototype.setPublicKey;

test/parallel/test-crypto-classes.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const TEST_CASES = {
1818
'Verify': ['RSA-SHA1'],
1919
'DiffieHellman': [1024],
2020
'DiffieHellmanGroup': ['modp5'],
21+
'ECDH': ['prime256v1'],
2122
'Credentials': []
2223
};
2324

0 commit comments

Comments
 (0)