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  generateKeyPairSync,
111cb0ef41Sopenharmony_ci  getCurves,
121cb0ef41Sopenharmony_ci} = require('crypto');
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci// This test creates EC key pairs on curves without associated OIDs.
151cb0ef41Sopenharmony_ci// Specifying a key encoding should not crash.
161cb0ef41Sopenharmony_ci{
171cb0ef41Sopenharmony_ci  if (process.versions.openssl >= '1.1.1i') {
181cb0ef41Sopenharmony_ci    for (const namedCurve of ['Oakley-EC2N-3', 'Oakley-EC2N-4']) {
191cb0ef41Sopenharmony_ci      if (!getCurves().includes(namedCurve))
201cb0ef41Sopenharmony_ci        continue;
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci      const expectedErrorCode =
231cb0ef41Sopenharmony_ci        common.hasOpenSSL3 ? 'ERR_OSSL_MISSING_OID' : 'ERR_OSSL_EC_MISSING_OID';
241cb0ef41Sopenharmony_ci      const params = {
251cb0ef41Sopenharmony_ci        namedCurve,
261cb0ef41Sopenharmony_ci        publicKeyEncoding: {
271cb0ef41Sopenharmony_ci          format: 'der',
281cb0ef41Sopenharmony_ci          type: 'spki'
291cb0ef41Sopenharmony_ci        }
301cb0ef41Sopenharmony_ci      };
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci      assert.throws(() => {
331cb0ef41Sopenharmony_ci        generateKeyPairSync('ec', params);
341cb0ef41Sopenharmony_ci      }, {
351cb0ef41Sopenharmony_ci        code: expectedErrorCode
361cb0ef41Sopenharmony_ci      });
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci      generateKeyPair('ec', params, common.mustCall((err) => {
391cb0ef41Sopenharmony_ci        assert.strictEqual(err.code, expectedErrorCode);
401cb0ef41Sopenharmony_ci      }));
411cb0ef41Sopenharmony_ci    }
421cb0ef41Sopenharmony_ci  }
431cb0ef41Sopenharmony_ci}
44