1+ // Flags: --expose-internals
12'use strict' ;
23
34const common = require ( '../common' ) ;
@@ -10,8 +11,11 @@ const { types: { isCryptoKey } } = require('util');
1011const {
1112 webcrypto : { subtle, CryptoKey } ,
1213 createSecretKey,
14+ KeyObject,
1315} = require ( 'crypto' ) ;
1416
17+ const { bigIntArrayToUnsignedBigInt } = require ( 'internal/crypto/util' ) ;
18+
1519const allUsages = [
1620 'encrypt' ,
1721 'decrypt' ,
@@ -264,10 +268,16 @@ const vectors = {
264268 assert . strictEqual ( publicKey . algorithm . name , name ) ;
265269 assert . strictEqual ( publicKey . algorithm . modulusLength , modulusLength ) ;
266270 assert . deepStrictEqual ( publicKey . algorithm . publicExponent , publicExponent ) ;
271+ assert . strictEqual (
272+ KeyObject . from ( publicKey ) . asymmetricKeyDetails . publicExponent ,
273+ bigIntArrayToUnsignedBigInt ( publicExponent ) ) ;
267274 assert . strictEqual ( publicKey . algorithm . hash . name , hash ) ;
268275 assert . strictEqual ( privateKey . algorithm . name , name ) ;
269276 assert . strictEqual ( privateKey . algorithm . modulusLength , modulusLength ) ;
270277 assert . deepStrictEqual ( privateKey . algorithm . publicExponent , publicExponent ) ;
278+ assert . strictEqual (
279+ KeyObject . from ( privateKey ) . asymmetricKeyDetails . publicExponent ,
280+ bigIntArrayToUnsignedBigInt ( publicExponent ) ) ;
271281 assert . strictEqual ( privateKey . algorithm . hash . name , hash ) ;
272282
273283 // Missing parameters
@@ -344,6 +354,17 @@ const vectors = {
344354 code : 'ERR_INVALID_ARG_TYPE'
345355 } ) ;
346356 } ) ) ;
357+
358+ await Promise . all ( [ [ 1 ] , [ 1 , 0 , 0 ] ] . map ( ( publicExponent ) => {
359+ return assert . rejects ( subtle . generateKey ( {
360+ name,
361+ modulusLength,
362+ publicExponent : new Uint8Array ( publicExponent ) ,
363+ hash
364+ } , true , usages ) , {
365+ name : 'OperationError' ,
366+ } ) ;
367+ } ) ) ;
347368 }
348369
349370 const kTests = [
0 commit comments