crypto: normalize RsaHashedKeyParams publicExponent · nodejs/node@4276516

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -397,7 +397,9 @@ const kSupportedAlgorithms = createSupportedAlgorithms(kAlgorithmDefinitions);

397397
398398

const simpleAlgorithmDictionaries = {

399399

AeadParams: { iv: 'BufferSource', additionalData: 'BufferSource' },

400-

RsaHashedKeyGenParams: { hash: 'HashAlgorithmIdentifier' },

400+

// publicExponent is not strictly a BufferSource but it is a Uint8Array that we normalize

401+

// this way

402+

RsaHashedKeyGenParams: { hash: 'HashAlgorithmIdentifier', publicExponent: 'BufferSource' },

401403

EcKeyGenParams: {},

402404

HmacKeyGenParams: { hash: 'HashAlgorithmIdentifier' },

403405

RsaPssParams: {},

Original file line numberDiff line numberDiff line change

@@ -311,14 +311,20 @@ if (hasOpenSSL(3, 5)) {

311311

assert.deepStrictEqual(privateKey.usages, privateUsages);

312312

assert.strictEqual(publicKey.algorithm.name, name);

313313

assert.strictEqual(publicKey.algorithm.modulusLength, modulusLength);

314-

assert.deepStrictEqual(publicKey.algorithm.publicExponent, publicExponent);

314+

assert(publicKey.algorithm.publicExponent instanceof Uint8Array);

315+

assert.notStrictEqual(publicKey.algorithm.publicExponent, publicExponent);

316+

assert(!Buffer.isBuffer(publicKey.algorithm.publicExponent));

317+

assert.deepStrictEqual(publicKey.algorithm.publicExponent, new Uint8Array(publicExponent));

315318

assert.strictEqual(

316319

KeyObject.from(publicKey).asymmetricKeyDetails.publicExponent,

317320

bigIntArrayToUnsignedBigInt(publicExponent));

318321

assert.strictEqual(publicKey.algorithm.hash.name, hash);

319322

assert.strictEqual(privateKey.algorithm.name, name);

320323

assert.strictEqual(privateKey.algorithm.modulusLength, modulusLength);

321-

assert.deepStrictEqual(privateKey.algorithm.publicExponent, publicExponent);

324+

assert(privateKey.algorithm.publicExponent instanceof Uint8Array);

325+

assert.notStrictEqual(privateKey.algorithm.publicExponent, publicExponent);

326+

assert(!Buffer.isBuffer(privateKey.algorithm.publicExponent));

327+

assert.deepStrictEqual(privateKey.algorithm.publicExponent, new Uint8Array(publicExponent));

322328

assert.strictEqual(

323329

KeyObject.from(privateKey).asymmetricKeyDetails.publicExponent,

324330

bigIntArrayToUnsignedBigInt(publicExponent));