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 Jan 17, 2018
1 parent d7ac63e commit 809858c
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
Expand Up @@ -66,7 +66,6 @@ function toBuf(str, encoding) {
}
exports._toBuf = toBuf;


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

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-crypto-classes.js
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 809858c

Please sign in to comment.