1616 sign,
1717 verify
1818} = require ( 'crypto' ) ;
19- const { promisify } = require ( 'util' ) ;
19+ const { inspect , promisify } = require ( 'util' ) ;
2020
2121// Asserts that the size of the given key (in chars or bytes) is within 10% of
2222// the expected size.
@@ -705,13 +705,14 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
705705} ) , {
706706name : 'TypeError' ,
707707code : 'ERR_INVALID_OPT_VALUE' ,
708- message : `The value "${ type } " is invalid for option ` +
708+ message : `The value "${ inspect ( type ) } " is invalid for option ` +
709709'"publicKeyEncoding.type"'
710710} ) ;
711711}
712712
713713// Missing / invalid publicKeyEncoding.format.
714714for ( const format of [ undefined , null , 0 , false , 'a' , { } ] ) {
715+ const expected = typeof format === 'string' ? format : inspect ( format ) ;
715716assert . throws ( ( ) => generateKeyPairSync ( 'rsa' , {
716717modulusLength : 4096 ,
717718publicKeyEncoding : {
@@ -725,7 +726,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
725726} ) , {
726727name : 'TypeError' ,
727728code : 'ERR_INVALID_OPT_VALUE' ,
728- message : `The value "${ format } " is invalid for option ` +
729+ message : `The value "${ expected } " is invalid for option ` +
729730'"publicKeyEncoding.format"'
730731} ) ;
731732}
@@ -761,13 +762,14 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
761762} ) , {
762763name : 'TypeError' ,
763764code : 'ERR_INVALID_OPT_VALUE' ,
764- message : `The value "${ type } " is invalid for option ` +
765+ message : `The value "${ inspect ( type ) } " is invalid for option ` +
765766'"privateKeyEncoding.type"'
766767} ) ;
767768}
768769
769770// Missing / invalid privateKeyEncoding.format.
770771for ( const format of [ undefined , null , 0 , false , 'a' , { } ] ) {
772+ const expected = typeof format === 'string' ? format : inspect ( format ) ;
771773assert . throws ( ( ) => generateKeyPairSync ( 'rsa' , {
772774modulusLength : 4096 ,
773775publicKeyEncoding : {
@@ -781,7 +783,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
781783} ) , {
782784name : 'TypeError' ,
783785code : 'ERR_INVALID_OPT_VALUE' ,
784- message : `The value "${ format } " is invalid for option ` +
786+ message : `The value "${ expected } " is invalid for option ` +
785787'"privateKeyEncoding.format"'
786788} ) ;
787789}
@@ -802,7 +804,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
802804} ) , {
803805name : 'TypeError' ,
804806code : 'ERR_INVALID_OPT_VALUE' ,
805- message : `The value "${ cipher } " is invalid for option ` +
807+ message : `The value "${ inspect ( cipher ) } " is invalid for option ` +
806808'"privateKeyEncoding.cipher"'
807809} ) ;
808810}
@@ -865,25 +867,29 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
865867{
866868// Test invalid modulus lengths.
867869for ( const modulusLength of [ undefined , null , 'a' , true , { } , [ ] , 512.1 , - 1 ] ) {
870+ const expected = typeof modulusLength === 'string' ?
871+ modulusLength : inspect ( modulusLength ) ;
868872assert . throws ( ( ) => generateKeyPair ( 'rsa' , {
869873 modulusLength
870874} ) , {
871875name : 'TypeError' ,
872876code : 'ERR_INVALID_OPT_VALUE' ,
873- message : `The value "${ modulusLength } " is invalid for option ` +
877+ message : `The value "${ expected } " is invalid for option ` +
874878'"modulusLength"'
875879} ) ;
876880}
877881
878882// Test invalid exponents.
879883for ( const publicExponent of [ 'a' , true , { } , [ ] , 3.5 , - 1 ] ) {
884+ const expected = typeof publicExponent === 'string' ?
885+ publicExponent : inspect ( publicExponent ) ;
880886assert . throws ( ( ) => generateKeyPair ( 'rsa' , {
881887modulusLength : 4096 ,
882888 publicExponent
883889} ) , {
884890name : 'TypeError' ,
885891code : 'ERR_INVALID_OPT_VALUE' ,
886- message : `The value "${ publicExponent } " is invalid for option ` +
892+ message : `The value "${ expected } " is invalid for option ` +
887893'"publicExponent"'
888894} ) ;
889895}
@@ -893,25 +899,29 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
893899{
894900// Test invalid modulus lengths.
895901for ( const modulusLength of [ undefined , null , 'a' , true , { } , [ ] , 4096.1 ] ) {
902+ const expected = typeof modulusLength === 'string' ?
903+ modulusLength : inspect ( modulusLength ) ;
896904assert . throws ( ( ) => generateKeyPair ( 'dsa' , {
897905 modulusLength
898906} ) , {
899907name : 'TypeError' ,
900908code : 'ERR_INVALID_OPT_VALUE' ,
901- message : `The value "${ modulusLength } " is invalid for option ` +
909+ message : `The value "${ expected } " is invalid for option ` +
902910'"modulusLength"'
903911} ) ;
904912}
905913
906914// Test invalid divisor lengths.
907915for ( const divisorLength of [ 'a' , true , { } , [ ] , 4096.1 ] ) {
916+ const expected = typeof divisorLength === 'string' ?
917+ divisorLength : inspect ( divisorLength ) ;
908918assert . throws ( ( ) => generateKeyPair ( 'dsa' , {
909919modulusLength : 2048 ,
910920 divisorLength
911921} ) , {
912922name : 'TypeError' ,
913923code : 'ERR_INVALID_OPT_VALUE' ,
914- message : `The value "${ divisorLength } " is invalid for option ` +
924+ message : `The value "${ expected } " is invalid for option ` +
915925'"divisorLength"'
916926} ) ;
917927}
@@ -942,7 +952,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
942952} , {
943953name : 'TypeError' ,
944954code : 'ERR_INVALID_OPT_VALUE' ,
945- message : `The value "${ namedCurve } " is invalid for option ` +
955+ message : `The value "${ inspect ( namedCurve ) } " is invalid for option ` +
946956'"namedCurve"'
947957} ) ;
948958}
@@ -1079,7 +1089,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
10791089} , {
10801090name : 'TypeError' ,
10811091code : 'ERR_INVALID_OPT_VALUE' ,
1082- message : `The value "${ hashValue } " is invalid for option "hash"`
1092+ message : `The value "${ inspect ( hashValue ) } " is invalid for option "hash"`
10831093} ) ;
10841094}
10851095
@@ -1182,6 +1192,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
11821192) ;
11831193
11841194for ( const mgf1Hash of [ null , 0 , false , { } , [ ] ] ) {
1195+ const expected = inspect ( mgf1Hash ) ;
11851196assert . throws (
11861197( ) => {
11871198generateKeyPair ( 'rsa-pss' , {
@@ -1194,7 +1205,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
11941205{
11951206name : 'TypeError' ,
11961207code : 'ERR_INVALID_OPT_VALUE' ,
1197- message : `The value "${ mgf1Hash } " is invalid for option "mgf1Hash"`
1208+ message : `The value "${ expected } " is invalid for option "mgf1Hash"`
11981209}
11991210) ;
12001211}
0 commit comments