@@ -6,7 +6,11 @@ if (!common.hasCrypto)
6
6
common . skip ( 'missing crypto' ) ;
7
7
8
8
const assert = require ( 'assert' ) ;
9
- const { subtle, CryptoKey } = require ( 'crypto' ) . webcrypto ;
9
+ const { types : { isCryptoKey } } = require ( 'util' ) ;
10
+ const {
11
+ webcrypto : { subtle, CryptoKey } ,
12
+ createSecretKey,
13
+ } = require ( 'crypto' ) ;
10
14
11
15
const allUsages = [
12
16
'encrypt' ,
@@ -220,6 +224,8 @@ const vectors = {
220
224
221
225
assert ( publicKey ) ;
222
226
assert ( privateKey ) ;
227
+ assert ( isCryptoKey ( publicKey ) ) ;
228
+ assert ( isCryptoKey ( privateKey ) ) ;
223
229
224
230
assert ( publicKey instanceof CryptoKey ) ;
225
231
assert ( privateKey instanceof CryptoKey ) ;
@@ -366,6 +372,8 @@ const vectors = {
366
372
367
373
assert ( publicKey ) ;
368
374
assert ( privateKey ) ;
375
+ assert ( isCryptoKey ( publicKey ) ) ;
376
+ assert ( isCryptoKey ( privateKey ) ) ;
369
377
370
378
assert . strictEqual ( publicKey . type , 'public' ) ;
371
379
assert . strictEqual ( privateKey . type , 'private' ) ;
@@ -430,6 +438,7 @@ const vectors = {
430
438
} , true , usages ) ;
431
439
432
440
assert ( key ) ;
441
+ assert ( isCryptoKey ( key ) ) ;
433
442
434
443
assert . strictEqual ( key . type , 'secret' ) ;
435
444
assert . strictEqual ( key . extractable , true ) ;
@@ -488,6 +497,7 @@ const vectors = {
488
497
}
489
498
490
499
assert ( key ) ;
500
+ assert ( isCryptoKey ( key ) ) ;
491
501
492
502
assert . strictEqual ( key . type , 'secret' ) ;
493
503
assert . strictEqual ( key . extractable , true ) ;
@@ -544,6 +554,8 @@ const vectors = {
544
554
545
555
assert ( publicKey ) ;
546
556
assert ( privateKey ) ;
557
+ assert ( isCryptoKey ( publicKey ) ) ;
558
+ assert ( isCryptoKey ( privateKey ) ) ;
547
559
548
560
assert . strictEqual ( publicKey . type , 'public' ) ;
549
561
assert . strictEqual ( privateKey . type , 'private' ) ;
@@ -634,6 +646,8 @@ const vectors = {
634
646
} , true , [ 'deriveKey' ] ) ;
635
647
assert ( publicKey ) ;
636
648
assert ( privateKey ) ;
649
+ assert ( isCryptoKey ( publicKey ) ) ;
650
+ assert ( isCryptoKey ( privateKey ) ) ;
637
651
assert . strictEqual ( publicKey . type , 'public' ) ;
638
652
assert . strictEqual ( privateKey . type , 'private' ) ;
639
653
assert . strictEqual ( publicKey . algorithm . name , 'NODE-DH' ) ;
@@ -646,3 +660,10 @@ const vectors = {
646
660
assert . throws ( ( ) => new CryptoKey ( ) , {
647
661
code : 'ERR_OPERATION_FAILED'
648
662
} ) ;
663
+
664
+ {
665
+ const buffer = Buffer . from ( 'Hello World' ) ;
666
+ const keyObject = createSecretKey ( buffer ) ;
667
+ assert ( ! isCryptoKey ( buffer ) ) ;
668
+ assert ( ! isCryptoKey ( keyObject ) ) ;
669
+ }
0 commit comments