@@ -525,14 +525,18 @@ function prepareAsymmetricKey(key, ctx) {
525525 return { format : kKeyFormatPEM , data : getArrayBufferOrView ( key , 'key' ) } ;
526526 } else if ( typeof key === 'object' ) {
527527 const { key : data , encoding, format } = key ;
528+
528529 // The 'key' property can be a KeyObject as well to allow specifying
529530 // additional options such as padding along with the key.
530531 if ( isKeyObject ( data ) )
531532 return { data : getKeyObjectHandle ( data , ctx ) } ;
532533 else if ( isCryptoKey ( data ) )
533534 return { data : getKeyObjectHandle ( data [ kKeyObject ] , ctx ) } ;
534- else if ( isJwk ( data ) && format === 'jwk' )
535+ else if ( format === 'jwk' ) {
536+ validateObject ( data , 'key.key' ) ;
535537 return { data : getKeyObjectHandleFromJwk ( data , ctx ) , format : 'jwk' } ;
538+ }
539+
536540 // Either PEM or DER using PKCS#1 or SPKI.
537541 if ( ! isStringOrBuffer ( data ) ) {
538542 throw new ERR_INVALID_ARG_TYPE (
@@ -720,10 +724,6 @@ function isCryptoKey(obj) {
720724 return obj != null && obj [ kKeyObject ] !== undefined ;
721725}
722726
723- function isJwk ( obj ) {
724- return obj != null && obj . kty !== undefined ;
725- }
726-
727727module . exports = {
728728 // Public API.
729729 createSecretKey,
@@ -745,5 +745,4 @@ module.exports = {
745745 PrivateKeyObject,
746746 isKeyObject,
747747 isCryptoKey,
748- isJwk,
749748} ;
0 commit comments