node/test/parallel/test-crypto-keygen-bit-length.js
James M Snell 761de815c5
test: move crypto related common utilities in common/crypto
Since `common/crypto` already exists, it makes sense to keep
crypto-related utilities there. The only exception being
common.hasCrypto which is needed up front to determine
if tests should be skipped.

Eliminate the redundant check in hasFipsCrypto and just
use crypto.getFips() directly where needed.

PR-URL: https://github.com/nodejs/node/pull/56714
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2025-01-25 00:58:32 +00:00

41 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
const { hasOpenSSL3 } = require('../common/crypto');
// This tests check that generateKeyPair returns correct bit length in
// KeyObject's asymmetricKeyDetails.
// https://github.com/nodejs/node/issues/46102#issuecomment-1372153541
{
generateKeyPair('rsa', {
modulusLength: 513,
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(privateKey.asymmetricKeyDetails.modulusLength, 513);
assert.strictEqual(publicKey.asymmetricKeyDetails.modulusLength, 513);
}));
generateKeyPair('rsa-pss', {
modulusLength: 513,
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(privateKey.asymmetricKeyDetails.modulusLength, 513);
assert.strictEqual(publicKey.asymmetricKeyDetails.modulusLength, 513);
}));
if (hasOpenSSL3) {
generateKeyPair('dsa', {
modulusLength: 2049,
divisorLength: 256,
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(privateKey.asymmetricKeyDetails.modulusLength, 2049);
assert.strictEqual(publicKey.asymmetricKeyDetails.modulusLength, 2049);
}));
}
}