11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst {
91cb0ef41Sopenharmony_ci  generateKeyPair,
101cb0ef41Sopenharmony_ci} = require('crypto');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci// 'rsa-pss' should not add a RSASSA-PSS-params sequence by default.
131cb0ef41Sopenharmony_ci// Regression test for: https://github.com/nodejs/node/issues/39936
141cb0ef41Sopenharmony_ci{
151cb0ef41Sopenharmony_ci  generateKeyPair('rsa-pss', {
161cb0ef41Sopenharmony_ci    modulusLength: 512
171cb0ef41Sopenharmony_ci  }, common.mustSucceed((publicKey, privateKey) => {
181cb0ef41Sopenharmony_ci    const expectedKeyDetails = {
191cb0ef41Sopenharmony_ci      modulusLength: 512,
201cb0ef41Sopenharmony_ci      publicExponent: 65537n
211cb0ef41Sopenharmony_ci    };
221cb0ef41Sopenharmony_ci    assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
231cb0ef41Sopenharmony_ci    assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci    // To allow backporting the fix to versions that do not support
261cb0ef41Sopenharmony_ci    // asymmetricKeyDetails for RSA-PSS params, also verify that the exported
271cb0ef41Sopenharmony_ci    // AlgorithmIdentifier member of the SubjectPublicKeyInfo has the expected
281cb0ef41Sopenharmony_ci    // length of 11 bytes (as opposed to > 11 bytes if node added params).
291cb0ef41Sopenharmony_ci    const spki = publicKey.export({ format: 'der', type: 'spki' });
301cb0ef41Sopenharmony_ci    assert.strictEqual(spki[3], 11, spki.toString('hex'));
311cb0ef41Sopenharmony_ci  }));
321cb0ef41Sopenharmony_ci}
33