mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: https://github.com/nodejs/node/pull/64960 Fixes: https://github.com/nodejs/node/issues/48379 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const crypto = require('crypto');
|
|
const { hasOpenSSL, hasFIPS } = require('../common/crypto');
|
|
|
|
const size = hasFIPS(3) ?
|
|
2048 : (crypto.getFips() === 1 || hasOpenSSL(3) ? 1024 : 256);
|
|
const dh1 = crypto.createDiffieHellman(size);
|
|
const p1 = dh1.getPrime('buffer');
|
|
|
|
{
|
|
const DiffieHellman = crypto.DiffieHellman;
|
|
|
|
const dh = DiffieHellman(p1, 'buffer');
|
|
assert(dh instanceof DiffieHellman, 'DiffieHellman is expected to return a ' +
|
|
'new instance when called without `new`');
|
|
}
|
|
|
|
{
|
|
const DiffieHellmanGroup = crypto.DiffieHellmanGroup;
|
|
const dhg = DiffieHellmanGroup(hasFIPS(3) ? 'modp14' : 'modp5');
|
|
assert(dhg instanceof DiffieHellmanGroup, 'DiffieHellmanGroup is expected ' +
|
|
'to return a new instance when ' +
|
|
'called without `new`');
|
|
}
|
|
|
|
{
|
|
const ECDH = crypto.ECDH;
|
|
const ecdh = ECDH('prime256v1');
|
|
assert(ecdh instanceof ECDH, 'ECDH is expected to return a new instance ' +
|
|
'when called without `new`');
|
|
}
|