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 <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
bengl authored and evanlucas committed Oct 23, 2017
1 parent 8f778d2 commit a5c3143
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 @@ -70,7 +70,6 @@ function toBuf(str, encoding) {
}
exports._toBuf = toBuf;


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

Expand Down Expand Up @@ -562,17 +561,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 a5c3143

Please sign in to comment.