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.

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 committed Sep 27, 2017
1 parent 611a648 commit 26174fc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ const {
} = require('internal/crypto/util');
const Certificate = require('internal/crypto/certificate');

function createECDH(curve) {
return new ECDH(curve);
}

module.exports = exports = {
// Methods
_toBuf: toBuf,
Expand All @@ -92,7 +88,7 @@ module.exports = exports = {
createDecipheriv: Decipheriv,
createDiffieHellman: DiffieHellman,
createDiffieHellmanGroup: DiffieHellmanGroup,
createECDH,
createECDH: ECDH,
createHash: Hash,
createHmac: Hmac,
createSign: Sign,
Expand Down Expand Up @@ -124,6 +120,7 @@ module.exports = exports = {
Decipheriv,
DiffieHellman,
DiffieHellmanGroup,
ECDH,
Hash,
Hmac,
Sign,
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/crypto/diffiehellman.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ DiffieHellman.prototype.setPrivateKey = function setPrivateKey(key, encoding) {


function ECDH(curve) {
if (!(this instanceof ECDH))
return new ECDH(curve);

if (typeof curve !== 'string')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'curve', 'string');

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 26174fc

Please sign in to comment.