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_ciconst { 121cb0ef41Sopenharmony_ci assertApproximateSize, 131cb0ef41Sopenharmony_ci testEncryptDecrypt, 141cb0ef41Sopenharmony_ci testSignVerify, 151cb0ef41Sopenharmony_ci pkcs1PubExp, 161cb0ef41Sopenharmony_ci pkcs1PrivExp, 171cb0ef41Sopenharmony_ci} = require('../common/crypto'); 181cb0ef41Sopenharmony_ciconst { promisify } = require('util'); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci// Test the util.promisified API with async RSA key generation. 211cb0ef41Sopenharmony_ci{ 221cb0ef41Sopenharmony_ci promisify(generateKeyPair)('rsa', { 231cb0ef41Sopenharmony_ci publicExponent: 0x10001, 241cb0ef41Sopenharmony_ci modulusLength: 512, 251cb0ef41Sopenharmony_ci publicKeyEncoding: { 261cb0ef41Sopenharmony_ci type: 'pkcs1', 271cb0ef41Sopenharmony_ci format: 'pem' 281cb0ef41Sopenharmony_ci }, 291cb0ef41Sopenharmony_ci privateKeyEncoding: { 301cb0ef41Sopenharmony_ci type: 'pkcs1', 311cb0ef41Sopenharmony_ci format: 'pem' 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci }).then(common.mustCall((keys) => { 341cb0ef41Sopenharmony_ci const { publicKey, privateKey } = keys; 351cb0ef41Sopenharmony_ci assert.strictEqual(typeof publicKey, 'string'); 361cb0ef41Sopenharmony_ci assert.match(publicKey, pkcs1PubExp); 371cb0ef41Sopenharmony_ci assertApproximateSize(publicKey, 180); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci assert.strictEqual(typeof privateKey, 'string'); 401cb0ef41Sopenharmony_ci assert.match(privateKey, pkcs1PrivExp); 411cb0ef41Sopenharmony_ci assertApproximateSize(privateKey, 512); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci testEncryptDecrypt(publicKey, privateKey); 441cb0ef41Sopenharmony_ci testSignVerify(publicKey, privateKey); 451cb0ef41Sopenharmony_ci })); 461cb0ef41Sopenharmony_ci} 47