Skip to content

Commit 809858c

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 d7ac63e commit 809858c

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
@@ -66,7 +66,6 @@ function toBuf(str, encoding) {
6666
}
6767
exports._toBuf = toBuf;
6868

69-
7069
const assert = require('assert');
7170
const StringDecoder = require('string_decoder').StringDecoder;
7271

@@ -556,17 +555,16 @@ DiffieHellman.prototype.setPrivateKey = function setPrivateKey(key, encoding) {
556555
};
557556

558557

558+
exports.createECDH = exports.ECDH = ECDH;
559559
function ECDH(curve) {
560+
if (!(this instanceof ECDH))
561+
return new ECDH(curve);
560562
if (typeof curve !== 'string')
561563
throw new TypeError('"curve" argument should be a string');
562564

563565
this._handle = new binding.ECDH(curve);
564566
}
565567

566-
exports.createECDH = function createECDH(curve) {
567-
return new ECDH(curve);
568-
};
569-
570568
ECDH.prototype.computeSecret = DiffieHellman.prototype.computeSecret;
571569
ECDH.prototype.setPrivateKey = DiffieHellman.prototype.setPrivateKey;
572570
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)