@@ -526,14 +526,18 @@ function prepareAsymmetricKey(key, ctx) {
526526 return { format : kKeyFormatPEM , data : getArrayBufferOrView ( key , 'key' ) } ;
527527 } else if ( typeof key === 'object' ) {
528528 const { key : data , encoding, format } = key ;
529+
529530 // The 'key' property can be a KeyObject as well to allow specifying
530531 // additional options such as padding along with the key.
531532 if ( isKeyObject ( data ) )
532533 return { data : getKeyObjectHandle ( data , ctx ) } ;
533534 else if ( isCryptoKey ( data ) )
534535 return { data : getKeyObjectHandle ( data [ kKeyObject ] , ctx ) } ;
535- else if ( isJwk ( data ) && format === 'jwk' )
536+ else if ( format === 'jwk' ) {
537+ validateObject ( data , 'key.key' ) ;
536538 return { data : getKeyObjectHandleFromJwk ( data , ctx ) , format : 'jwk' } ;
539+ }
540+
537541 // Either PEM or DER using PKCS#1 or SPKI.
538542 if ( ! isStringOrBuffer ( data ) ) {
539543 throw new ERR_INVALID_ARG_TYPE (
@@ -723,10 +727,6 @@ function isCryptoKey(obj) {
723727 return obj != null && obj [ kKeyObject ] !== undefined ;
724728}
725729
726- function isJwk ( obj ) {
727- return obj != null && obj . kty !== undefined ;
728- }
729-
730730module . exports = {
731731 // Public API.
732732 createSecretKey,
@@ -748,5 +748,4 @@ module.exports = {
748748 PrivateKeyObject,
749749 isKeyObject,
750750 isCryptoKey,
751- isJwk,
752751} ;
0 commit comments