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 testEncryptDecrypt, 131cb0ef41Sopenharmony_ci testSignVerify, 141cb0ef41Sopenharmony_ci} = require('../common/crypto'); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci// Tests key objects are returned when key encodings are not specified. 171cb0ef41Sopenharmony_ci{ 181cb0ef41Sopenharmony_ci // If no publicKeyEncoding is specified, a key object should be returned. 191cb0ef41Sopenharmony_ci generateKeyPair('rsa', { 201cb0ef41Sopenharmony_ci modulusLength: 1024, 211cb0ef41Sopenharmony_ci privateKeyEncoding: { 221cb0ef41Sopenharmony_ci type: 'pkcs1', 231cb0ef41Sopenharmony_ci format: 'pem' 241cb0ef41Sopenharmony_ci } 251cb0ef41Sopenharmony_ci }, common.mustSucceed((publicKey, privateKey) => { 261cb0ef41Sopenharmony_ci assert.strictEqual(typeof publicKey, 'object'); 271cb0ef41Sopenharmony_ci assert.strictEqual(publicKey.type, 'public'); 281cb0ef41Sopenharmony_ci assert.strictEqual(publicKey.asymmetricKeyType, 'rsa'); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci // The private key should still be a string. 311cb0ef41Sopenharmony_ci assert.strictEqual(typeof privateKey, 'string'); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci testEncryptDecrypt(publicKey, privateKey); 341cb0ef41Sopenharmony_ci testSignVerify(publicKey, privateKey); 351cb0ef41Sopenharmony_ci })); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci // If no privateKeyEncoding is specified, a key object should be returned. 381cb0ef41Sopenharmony_ci generateKeyPair('rsa', { 391cb0ef41Sopenharmony_ci modulusLength: 1024, 401cb0ef41Sopenharmony_ci publicKeyEncoding: { 411cb0ef41Sopenharmony_ci type: 'pkcs1', 421cb0ef41Sopenharmony_ci format: 'pem' 431cb0ef41Sopenharmony_ci } 441cb0ef41Sopenharmony_ci }, common.mustSucceed((publicKey, privateKey) => { 451cb0ef41Sopenharmony_ci // The public key should still be a string. 461cb0ef41Sopenharmony_ci assert.strictEqual(typeof publicKey, 'string'); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci assert.strictEqual(typeof privateKey, 'object'); 491cb0ef41Sopenharmony_ci assert.strictEqual(privateKey.type, 'private'); 501cb0ef41Sopenharmony_ci assert.strictEqual(privateKey.asymmetricKeyType, 'rsa'); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci testEncryptDecrypt(publicKey, privateKey); 531cb0ef41Sopenharmony_ci testSignVerify(publicKey, privateKey); 541cb0ef41Sopenharmony_ci })); 551cb0ef41Sopenharmony_ci} 56