@@ -16,7 +16,7 @@ const {
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 } ) , {
706706 name : 'TypeError' ,
707707 code : '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.
714714 for ( const format of [ undefined , null , 0 , false , 'a' , { } ] ) {
715+ const expected = typeof format === 'string' ? format : inspect ( format ) ;
715716 assert . throws ( ( ) => generateKeyPairSync ( 'rsa' , {
716717 modulusLength : 4096 ,
717718 publicKeyEncoding : {
@@ -725,7 +726,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
725726 } ) , {
726727 name : 'TypeError' ,
727728 code : '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 } ) , {
762763 name : 'TypeError' ,
763764 code : '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.
770771 for ( const format of [ undefined , null , 0 , false , 'a' , { } ] ) {
772+ const expected = typeof format === 'string' ? format : inspect ( format ) ;
771773 assert . throws ( ( ) => generateKeyPairSync ( 'rsa' , {
772774 modulusLength : 4096 ,
773775 publicKeyEncoding : {
@@ -781,7 +783,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
781783 } ) , {
782784 name : 'TypeError' ,
783785 code : '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 } ) , {
803805 name : 'TypeError' ,
804806 code : '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.
867869 for ( const modulusLength of [ undefined , null , 'a' , true , { } , [ ] , 512.1 , - 1 ] ) {
870+ const expected = typeof modulusLength === 'string' ?
871+ modulusLength : inspect ( modulusLength ) ;
868872 assert . throws ( ( ) => generateKeyPair ( 'rsa' , {
869873 modulusLength
870874 } ) , {
871875 name : 'TypeError' ,
872876 code : '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.
879883 for ( const publicExponent of [ 'a' , true , { } , [ ] , 3.5 , - 1 ] ) {
884+ const expected = typeof publicExponent === 'string' ?
885+ publicExponent : inspect ( publicExponent ) ;
880886 assert . throws ( ( ) => generateKeyPair ( 'rsa' , {
881887 modulusLength : 4096 ,
882888 publicExponent
883889 } ) , {
884890 name : 'TypeError' ,
885891 code : '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.
895901 for ( const modulusLength of [ undefined , null , 'a' , true , { } , [ ] , 4096.1 ] ) {
902+ const expected = typeof modulusLength === 'string' ?
903+ modulusLength : inspect ( modulusLength ) ;
896904 assert . throws ( ( ) => generateKeyPair ( 'dsa' , {
897905 modulusLength
898906 } ) , {
899907 name : 'TypeError' ,
900908 code : '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.
907915 for ( const divisorLength of [ 'a' , true , { } , [ ] , 4096.1 ] ) {
916+ const expected = typeof divisorLength === 'string' ?
917+ divisorLength : inspect ( divisorLength ) ;
908918 assert . throws ( ( ) => generateKeyPair ( 'dsa' , {
909919 modulusLength : 2048 ,
910920 divisorLength
911921 } ) , {
912922 name : 'TypeError' ,
913923 code : '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 } , {
943953 name : 'TypeError' ,
944954 code : '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 } , {
10801090 name : 'TypeError' ,
10811091 code : '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
11841194 for ( const mgf1Hash of [ null , 0 , false , { } , [ ] ] ) {
1195+ const expected = inspect ( mgf1Hash ) ;
11851196 assert . throws (
11861197 ( ) => {
11871198 generateKeyPair ( 'rsa-pss' , {
@@ -1194,7 +1205,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
11941205 {
11951206 name : 'TypeError' ,
11961207 code : '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