@@ -217,7 +217,7 @@ const {
217217throw lazyDOMException ( 'Unrecognized algorithm name' , 'NotSupportedError' ) ;
218218}
219219
220- if ( result . usages . length === 0 ) {
220+ if ( result [ kKeyUsages ] . length === 0 ) {
221221throw lazyDOMException (
222222`Usages cannot be empty when importing a ${ result . type } key.` ,
223223'SyntaxError' ) ;
@@ -309,7 +309,7 @@ const {
309309throw lazyDOMException ( 'Unrecognized algorithm name' , 'NotSupportedError' ) ;
310310}
311311
312- if ( result . type === 'private' && result . usages . length === 0 ) {
312+ if ( result . type === 'private' && result [ kKeyUsages ] . length === 0 ) {
313313throw lazyDOMException (
314314`Usages cannot be empty when importing a ${ result . type } key.` ,
315315'SyntaxError' ) ;
@@ -735,8 +735,8 @@ function prepareSecretKey(key, encoding, bufferOnly = false) {
735735throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE ( key . type , 'secret' ) ;
736736return key [ kHandle ] ;
737737} else if ( isCryptoKey ( key ) ) {
738- if ( key . type !== 'secret' )
739- throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE ( key . type , 'secret' ) ;
738+ if ( key [ kKeyType ] !== 'secret' )
739+ throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE ( key [ kKeyType ] , 'secret' ) ;
740740return key [ kKeyObject ] [ kHandle ] ;
741741}
742742}
@@ -785,7 +785,7 @@ function createPrivateKey(key) {
785785}
786786
787787function isKeyObject ( obj ) {
788- return obj != null && obj [ kKeyType ] !== undefined ;
788+ return obj != null && obj [ kKeyType ] !== undefined && obj [ kKeyObject ] === undefined ;
789789}
790790
791791// Our implementation of CryptoKey is a simple wrapper around a KeyObject
@@ -809,17 +809,21 @@ class CryptoKey {
809809} ;
810810
811811return `CryptoKey ${ inspect ( {
812- type : this . type ,
813- extractable : this . extractable ,
814- algorithm : this . algorithm ,
815- usages : this . usages ,
812+ type : this [ kKeyType ] ,
813+ extractable : this [ kExtractable ] ,
814+ algorithm : this [ kAlgorithm ] ,
815+ usages : this [ kKeyUsages ] ,
816816} , opts ) } `;
817817}
818818
819+ get [ kKeyType ] ( ) {
820+ return this [ kKeyObject ] . type ;
821+ }
822+
819823get type ( ) {
820824if ( ! ( this instanceof CryptoKey ) )
821825throw new ERR_INVALID_THIS ( 'CryptoKey' ) ;
822- return this [ kKeyObject ] . type ;
826+ return this [ kKeyType ] ;
823827}
824828
825829get extractable ( ) {
@@ -1008,4 +1012,8 @@ module.exports = {
10081012 isKeyObject,
10091013 isCryptoKey,
10101014 importGenericSecretKey,
1015+ kAlgorithm,
1016+ kExtractable,
1017+ kKeyType,
1018+ kKeyUsages,
10111019} ;
0 commit comments