@@ -6,7 +6,11 @@ if (!common.hasCrypto)
66 common . skip ( 'missing crypto' ) ;
77
88const 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' ) ;
1014
1115const allUsages = [
1216 'encrypt' ,
@@ -220,6 +224,8 @@ const vectors = {
220224
221225 assert ( publicKey ) ;
222226 assert ( privateKey ) ;
227+ assert ( isCryptoKey ( publicKey ) ) ;
228+ assert ( isCryptoKey ( privateKey ) ) ;
223229
224230 assert ( publicKey instanceof CryptoKey ) ;
225231 assert ( privateKey instanceof CryptoKey ) ;
@@ -366,6 +372,8 @@ const vectors = {
366372
367373 assert ( publicKey ) ;
368374 assert ( privateKey ) ;
375+ assert ( isCryptoKey ( publicKey ) ) ;
376+ assert ( isCryptoKey ( privateKey ) ) ;
369377
370378 assert . strictEqual ( publicKey . type , 'public' ) ;
371379 assert . strictEqual ( privateKey . type , 'private' ) ;
@@ -430,6 +438,7 @@ const vectors = {
430438 } , true , usages ) ;
431439
432440 assert ( key ) ;
441+ assert ( isCryptoKey ( key ) ) ;
433442
434443 assert . strictEqual ( key . type , 'secret' ) ;
435444 assert . strictEqual ( key . extractable , true ) ;
@@ -488,6 +497,7 @@ const vectors = {
488497 }
489498
490499 assert ( key ) ;
500+ assert ( isCryptoKey ( key ) ) ;
491501
492502 assert . strictEqual ( key . type , 'secret' ) ;
493503 assert . strictEqual ( key . extractable , true ) ;
@@ -544,6 +554,8 @@ const vectors = {
544554
545555 assert ( publicKey ) ;
546556 assert ( privateKey ) ;
557+ assert ( isCryptoKey ( publicKey ) ) ;
558+ assert ( isCryptoKey ( privateKey ) ) ;
547559
548560 assert . strictEqual ( publicKey . type , 'public' ) ;
549561 assert . strictEqual ( privateKey . type , 'private' ) ;
@@ -634,6 +646,8 @@ const vectors = {
634646 } , true , [ 'deriveKey' ] ) ;
635647 assert ( publicKey ) ;
636648 assert ( privateKey ) ;
649+ assert ( isCryptoKey ( publicKey ) ) ;
650+ assert ( isCryptoKey ( privateKey ) ) ;
637651 assert . strictEqual ( publicKey . type , 'public' ) ;
638652 assert . strictEqual ( privateKey . type , 'private' ) ;
639653 assert . strictEqual ( publicKey . algorithm . name , 'NODE-DH' ) ;
@@ -646,3 +660,10 @@ const vectors = {
646660assert . throws ( ( ) => new CryptoKey ( ) , {
647661 code : 'ERR_OPERATION_FAILED'
648662} ) ;
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