1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const assert = require('assert');
8const {
9  generateKeyPair,
10} = require('crypto');
11const {
12  testSignVerify,
13  spkiExp,
14  sec1Exp,
15} = require('../common/crypto');
16
17// Test async explicit elliptic curve key generation, e.g. for ECDSA,
18// with a SEC1 private key with paramEncoding explicit.
19{
20  generateKeyPair('ec', {
21    namedCurve: 'prime256v1',
22    paramEncoding: 'explicit',
23    publicKeyEncoding: {
24      type: 'spki',
25      format: 'pem'
26    },
27    privateKeyEncoding: {
28      type: 'sec1',
29      format: 'pem'
30    }
31  }, common.mustSucceed((publicKey, privateKey) => {
32    assert.strictEqual(typeof publicKey, 'string');
33    assert.match(publicKey, spkiExp);
34    assert.strictEqual(typeof privateKey, 'string');
35    assert.match(privateKey, sec1Exp);
36
37    testSignVerify(publicKey, privateKey);
38  }));
39}
40