1
+ // Flags: --expose-internals
1
2
'use strict' ;
2
3
3
4
const common = require ( '../common' ) ;
@@ -10,8 +11,11 @@ const { types: { isCryptoKey } } = require('util');
10
11
const {
11
12
webcrypto : { subtle, CryptoKey } ,
12
13
createSecretKey,
14
+ KeyObject,
13
15
} = require ( 'crypto' ) ;
14
16
17
+ const { bigIntArrayToUnsignedBigInt } = require ( 'internal/crypto/util' ) ;
18
+
15
19
const allUsages = [
16
20
'encrypt' ,
17
21
'decrypt' ,
@@ -264,10 +268,16 @@ const vectors = {
264
268
assert . strictEqual ( publicKey . algorithm . name , name ) ;
265
269
assert . strictEqual ( publicKey . algorithm . modulusLength , modulusLength ) ;
266
270
assert . deepStrictEqual ( publicKey . algorithm . publicExponent , publicExponent ) ;
271
+ assert . strictEqual (
272
+ KeyObject . from ( publicKey ) . asymmetricKeyDetails . publicExponent ,
273
+ bigIntArrayToUnsignedBigInt ( publicExponent ) ) ;
267
274
assert . strictEqual ( publicKey . algorithm . hash . name , hash ) ;
268
275
assert . strictEqual ( privateKey . algorithm . name , name ) ;
269
276
assert . strictEqual ( privateKey . algorithm . modulusLength , modulusLength ) ;
270
277
assert . deepStrictEqual ( privateKey . algorithm . publicExponent , publicExponent ) ;
278
+ assert . strictEqual (
279
+ KeyObject . from ( privateKey ) . asymmetricKeyDetails . publicExponent ,
280
+ bigIntArrayToUnsignedBigInt ( publicExponent ) ) ;
271
281
assert . strictEqual ( privateKey . algorithm . hash . name , hash ) ;
272
282
273
283
// Missing parameters
@@ -344,6 +354,17 @@ const vectors = {
344
354
code : 'ERR_INVALID_ARG_TYPE'
345
355
} ) ;
346
356
} ) ) ;
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
+ } ) ) ;
347
368
}
348
369
349
370
const kTests = [
0 commit comments