@@ -628,7 +628,7 @@ function getKeyTypes(allowKeyObject, bufferOnly = false) {
628628}
629629
630630
631- function prepareAsymmetricKey ( key , ctx ) {
631+ function prepareAsymmetricKey ( key , ctx , name = 'key' ) {
632632 if ( isKeyObject ( key ) ) {
633633 // Best case: A key object, as simple as that.
634634 return { data : getKeyObjectHandle ( key , ctx ) } ;
@@ -639,7 +639,7 @@ function prepareAsymmetricKey(key, ctx) {
639639 }
640640 if ( isStringOrBuffer ( key ) ) {
641641 // Expect PEM by default, mostly for backward compatibility.
642- return { format : kKeyFormatPEM , data : getArrayBufferOrView ( key , 'key' ) } ;
642+ return { format : kKeyFormatPEM , data : getArrayBufferOrView ( key , name ) } ;
643643 }
644644 if ( typeof key === 'object' ) {
645645 const { key : data , encoding, format } = key ;
@@ -654,23 +654,23 @@ function prepareAsymmetricKey(key, ctx) {
654654 return { data : getKeyObjectHandle ( data [ kKeyObject ] , ctx ) } ;
655655 }
656656 if ( format === 'jwk' ) {
657- validateObject ( data , 'key .key' ) ;
657+ validateObject ( data , ` ${ name } .key` ) ;
658658 return { data, format : kKeyFormatJWK } ;
659659 } else if ( format === 'raw-public' || format === 'raw-private' ||
660660 format === 'raw-seed' ) {
661661 if ( ! isStringOrBuffer ( data ) ) {
662662 throw new ERR_INVALID_ARG_TYPE (
663- 'key .key' ,
663+ ` ${ name } .key` ,
664664 [ 'ArrayBuffer' , 'Buffer' , 'TypedArray' , 'DataView' ] ,
665665 data ) ;
666666 }
667- validateString ( key . asymmetricKeyType , 'key .asymmetricKeyType' ) ;
667+ validateString ( key . asymmetricKeyType , ` ${ name } .asymmetricKeyType` ) ;
668668 if ( key . asymmetricKeyType === 'ec' ) {
669- validateString ( key . namedCurve , 'key .namedCurve' ) ;
669+ validateString ( key . namedCurve , ` ${ name } .namedCurve` ) ;
670670 }
671671 const rawFormat = parseKeyFormat ( format , undefined , 'options.format' ) ;
672672 return {
673- data : getArrayBufferOrView ( data , 'key .key' ) ,
673+ data : getArrayBufferOrView ( data , ` ${ name } .key` ) ,
674674 format : rawFormat ,
675675 type : key . asymmetricKeyType ,
676676 namedCurve : key . namedCurve ?? null ,
@@ -680,31 +680,31 @@ function prepareAsymmetricKey(key, ctx) {
680680 // Either PEM or DER using PKCS#1 or SPKI.
681681 if ( ! isStringOrBuffer ( data ) ) {
682682 throw new ERR_INVALID_ARG_TYPE (
683- 'key .key' ,
683+ ` ${ name } .key` ,
684684 getKeyTypes ( ctx !== kCreatePrivate ) ,
685685 data ) ;
686686 }
687687
688688 const isPublic =
689689 ( ctx === kConsumePrivate || ctx === kCreatePrivate ) ? false : undefined ;
690690 return {
691- data : getArrayBufferOrView ( data , ' key' , encoding ) ,
691+ data : getArrayBufferOrView ( data , ` ${ name } . key` , encoding ) ,
692692 ...parseKeyEncoding ( key , undefined , isPublic ) ,
693693 } ;
694694 }
695695
696696 throw new ERR_INVALID_ARG_TYPE (
697- 'key' ,
697+ name ,
698698 getKeyTypes ( ctx !== kCreatePrivate ) ,
699699 key ) ;
700700}
701701
702- function preparePrivateKey ( key ) {
703- return prepareAsymmetricKey ( key , kConsumePrivate ) ;
702+ function preparePrivateKey ( key , name ) {
703+ return prepareAsymmetricKey ( key , kConsumePrivate , name ) ;
704704}
705705
706- function preparePublicOrPrivateKey ( key ) {
707- return prepareAsymmetricKey ( key , kConsumePublic ) ;
706+ function preparePublicOrPrivateKey ( key , name ) {
707+ return prepareAsymmetricKey ( key , kConsumePublic , name ) ;
708708}
709709
710710function prepareSecretKey ( key , encoding , bufferOnly = false ) {
0 commit comments