Skip to content

Commit

Permalink
crypto: expose ECDH class
Browse files Browse the repository at this point in the history
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 <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
bengl authored and MylesBorins committed Feb 13, 2018
1 parent d29a620 commit f3b3437
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function toBuf(str, encoding) {
}
exports._toBuf = toBuf;


const assert = require('assert');
const StringDecoder = require('string_decoder').StringDecoder;

Expand Down Expand Up @@ -536,17 +535,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;
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-crypto-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const TEST_CASES = {
'Verify': ['RSA-SHA1'],
'DiffieHellman': [1024],
'DiffieHellmanGroup': ['modp5'],
'ECDH': ['prime256v1'],
'Credentials': []
};

Expand Down

0 comments on commit f3b3437

Please sign in to comment.