@@ -467,9 +467,9 @@ function parseKeyType(typeStr, required, keyType, isPublic, optionName) {
467467 throw new ERR_INVALID_ARG_VALUE ( optionName , typeStr ) ;
468468}
469469
470- function option ( name , objName ) {
471- return objName === undefined ?
472- `options.${ name } ` : `options. ${ objName } .${ name } ` ;
470+ function option ( name , prefix ) {
471+ return prefix === undefined ?
472+ `options.${ name } ` : `${ prefix } .${ name } ` ;
473473}
474474
475475function parseKeyFormatAndType ( enc , keyType , isPublic , objName ) {
@@ -629,7 +629,7 @@ function getKeyTypes(allowKeyObject, bufferOnly = false) {
629629}
630630
631631
632- function prepareAsymmetricKey ( key , ctx ) {
632+ function prepareAsymmetricKey ( key , ctx , name = 'key' ) {
633633 if ( isKeyObject ( key ) ) {
634634 // Best case: A key object, as simple as that.
635635 return { data : getKeyObjectHandle ( key , ctx ) } ;
@@ -640,7 +640,7 @@ function prepareAsymmetricKey(key, ctx) {
640640 }
641641 if ( isStringOrBuffer ( key ) ) {
642642 // Expect PEM by default, mostly for backward compatibility.
643- return { format : kKeyFormatPEM , data : getArrayBufferOrView ( key , 'key' ) } ;
643+ return { format : kKeyFormatPEM , data : getArrayBufferOrView ( key , name ) } ;
644644 }
645645 if ( typeof key === 'object' ) {
646646 const { key : data , encoding, format } = key ;
@@ -655,7 +655,7 @@ function prepareAsymmetricKey(key, ctx) {
655655 return { data : getKeyObjectHandle ( data [ kKeyObject ] , ctx ) } ;
656656 }
657657 if ( format === 'jwk' ) {
658- validateObject ( data , 'key .key' ) ;
658+ validateObject ( data , ` ${ name } .key` ) ;
659659 return { data, format : kKeyFormatJWK } ;
660660 } else if ( format === 'raw-public' || format === 'raw-private' ||
661661 format === 'raw-seed' ) {
@@ -681,31 +681,31 @@ function prepareAsymmetricKey(key, ctx) {
681681 // Either PEM or DER using PKCS#1 or SPKI.
682682 if ( ! isStringOrBuffer ( data ) ) {
683683 throw new ERR_INVALID_ARG_TYPE (
684- 'key .key' ,
684+ ` ${ name } .key` ,
685685 getKeyTypes ( ctx !== kCreatePrivate ) ,
686686 data ) ;
687687 }
688688
689689 const isPublic =
690690 ( ctx === kConsumePrivate || ctx === kCreatePrivate ) ? false : undefined ;
691691 return {
692- data : getArrayBufferOrView ( data , ' key' , encoding ) ,
693- ...parseKeyEncoding ( key , undefined , isPublic ) ,
692+ data : getArrayBufferOrView ( data , ` ${ name } . key` , encoding ) ,
693+ ...parseKeyEncoding ( key , undefined , isPublic , name ) ,
694694 } ;
695695 }
696696
697697 throw new ERR_INVALID_ARG_TYPE (
698- 'key' ,
698+ name ,
699699 getKeyTypes ( ctx !== kCreatePrivate ) ,
700700 key ) ;
701701}
702702
703- function preparePrivateKey ( key ) {
704- return prepareAsymmetricKey ( key , kConsumePrivate ) ;
703+ function preparePrivateKey ( key , name ) {
704+ return prepareAsymmetricKey ( key , kConsumePrivate , name ) ;
705705}
706706
707- function preparePublicOrPrivateKey ( key ) {
708- return prepareAsymmetricKey ( key , kConsumePublic ) ;
707+ function preparePublicOrPrivateKey ( key , name ) {
708+ return prepareAsymmetricKey ( key , kConsumePublic , name ) ;
709709}
710710
711711function prepareSecretKey ( key , encoding , bufferOnly = false ) {
0 commit comments