@@ -16,7 +16,7 @@ const {
16
16
sign,
17
17
verify
18
18
} = require ( 'crypto' ) ;
19
- const { promisify } = require ( 'util' ) ;
19
+ const { inspect , promisify } = require ( 'util' ) ;
20
20
21
21
// Asserts that the size of the given key (in chars or bytes) is within 10% of
22
22
// the expected size.
@@ -705,13 +705,14 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
705
705
} ) , {
706
706
name : 'TypeError' ,
707
707
code : 'ERR_INVALID_OPT_VALUE' ,
708
- message : `The value "${ type } " is invalid for option ` +
708
+ message : `The value "${ inspect ( type ) } " is invalid for option ` +
709
709
'"publicKeyEncoding.type"'
710
710
} ) ;
711
711
}
712
712
713
713
// Missing / invalid publicKeyEncoding.format.
714
714
for ( const format of [ undefined , null , 0 , false , 'a' , { } ] ) {
715
+ const expected = typeof format === 'string' ? format : inspect ( format ) ;
715
716
assert . throws ( ( ) => generateKeyPairSync ( 'rsa' , {
716
717
modulusLength : 4096 ,
717
718
publicKeyEncoding : {
@@ -725,7 +726,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
725
726
} ) , {
726
727
name : 'TypeError' ,
727
728
code : 'ERR_INVALID_OPT_VALUE' ,
728
- message : `The value "${ format } " is invalid for option ` +
729
+ message : `The value "${ expected } " is invalid for option ` +
729
730
'"publicKeyEncoding.format"'
730
731
} ) ;
731
732
}
@@ -761,13 +762,14 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
761
762
} ) , {
762
763
name : 'TypeError' ,
763
764
code : 'ERR_INVALID_OPT_VALUE' ,
764
- message : `The value "${ type } " is invalid for option ` +
765
+ message : `The value "${ inspect ( type ) } " is invalid for option ` +
765
766
'"privateKeyEncoding.type"'
766
767
} ) ;
767
768
}
768
769
769
770
// Missing / invalid privateKeyEncoding.format.
770
771
for ( const format of [ undefined , null , 0 , false , 'a' , { } ] ) {
772
+ const expected = typeof format === 'string' ? format : inspect ( format ) ;
771
773
assert . throws ( ( ) => generateKeyPairSync ( 'rsa' , {
772
774
modulusLength : 4096 ,
773
775
publicKeyEncoding : {
@@ -781,7 +783,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
781
783
} ) , {
782
784
name : 'TypeError' ,
783
785
code : 'ERR_INVALID_OPT_VALUE' ,
784
- message : `The value "${ format } " is invalid for option ` +
786
+ message : `The value "${ expected } " is invalid for option ` +
785
787
'"privateKeyEncoding.format"'
786
788
} ) ;
787
789
}
@@ -802,7 +804,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
802
804
} ) , {
803
805
name : 'TypeError' ,
804
806
code : 'ERR_INVALID_OPT_VALUE' ,
805
- message : `The value "${ cipher } " is invalid for option ` +
807
+ message : `The value "${ inspect ( cipher ) } " is invalid for option ` +
806
808
'"privateKeyEncoding.cipher"'
807
809
} ) ;
808
810
}
@@ -865,25 +867,29 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
865
867
{
866
868
// Test invalid modulus lengths.
867
869
for ( const modulusLength of [ undefined , null , 'a' , true , { } , [ ] , 512.1 , - 1 ] ) {
870
+ const expected = typeof modulusLength === 'string' ?
871
+ modulusLength : inspect ( modulusLength ) ;
868
872
assert . throws ( ( ) => generateKeyPair ( 'rsa' , {
869
873
modulusLength
870
874
} ) , {
871
875
name : 'TypeError' ,
872
876
code : 'ERR_INVALID_OPT_VALUE' ,
873
- message : `The value "${ modulusLength } " is invalid for option ` +
877
+ message : `The value "${ expected } " is invalid for option ` +
874
878
'"modulusLength"'
875
879
} ) ;
876
880
}
877
881
878
882
// Test invalid exponents.
879
883
for ( const publicExponent of [ 'a' , true , { } , [ ] , 3.5 , - 1 ] ) {
884
+ const expected = typeof publicExponent === 'string' ?
885
+ publicExponent : inspect ( publicExponent ) ;
880
886
assert . throws ( ( ) => generateKeyPair ( 'rsa' , {
881
887
modulusLength : 4096 ,
882
888
publicExponent
883
889
} ) , {
884
890
name : 'TypeError' ,
885
891
code : 'ERR_INVALID_OPT_VALUE' ,
886
- message : `The value "${ publicExponent } " is invalid for option ` +
892
+ message : `The value "${ expected } " is invalid for option ` +
887
893
'"publicExponent"'
888
894
} ) ;
889
895
}
@@ -893,25 +899,29 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
893
899
{
894
900
// Test invalid modulus lengths.
895
901
for ( const modulusLength of [ undefined , null , 'a' , true , { } , [ ] , 4096.1 ] ) {
902
+ const expected = typeof modulusLength === 'string' ?
903
+ modulusLength : inspect ( modulusLength ) ;
896
904
assert . throws ( ( ) => generateKeyPair ( 'dsa' , {
897
905
modulusLength
898
906
} ) , {
899
907
name : 'TypeError' ,
900
908
code : 'ERR_INVALID_OPT_VALUE' ,
901
- message : `The value "${ modulusLength } " is invalid for option ` +
909
+ message : `The value "${ expected } " is invalid for option ` +
902
910
'"modulusLength"'
903
911
} ) ;
904
912
}
905
913
906
914
// Test invalid divisor lengths.
907
915
for ( const divisorLength of [ 'a' , true , { } , [ ] , 4096.1 ] ) {
916
+ const expected = typeof divisorLength === 'string' ?
917
+ divisorLength : inspect ( divisorLength ) ;
908
918
assert . throws ( ( ) => generateKeyPair ( 'dsa' , {
909
919
modulusLength : 2048 ,
910
920
divisorLength
911
921
} ) , {
912
922
name : 'TypeError' ,
913
923
code : 'ERR_INVALID_OPT_VALUE' ,
914
- message : `The value "${ divisorLength } " is invalid for option ` +
924
+ message : `The value "${ expected } " is invalid for option ` +
915
925
'"divisorLength"'
916
926
} ) ;
917
927
}
@@ -942,7 +952,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
942
952
} , {
943
953
name : 'TypeError' ,
944
954
code : 'ERR_INVALID_OPT_VALUE' ,
945
- message : `The value "${ namedCurve } " is invalid for option ` +
955
+ message : `The value "${ inspect ( namedCurve ) } " is invalid for option ` +
946
956
'"namedCurve"'
947
957
} ) ;
948
958
}
@@ -1079,7 +1089,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
1079
1089
} , {
1080
1090
name : 'TypeError' ,
1081
1091
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"`
1083
1093
} ) ;
1084
1094
}
1085
1095
@@ -1182,6 +1192,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
1182
1192
) ;
1183
1193
1184
1194
for ( const mgf1Hash of [ null , 0 , false , { } , [ ] ] ) {
1195
+ const expected = inspect ( mgf1Hash ) ;
1185
1196
assert . throws (
1186
1197
( ) => {
1187
1198
generateKeyPair ( 'rsa-pss' , {
@@ -1194,7 +1205,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
1194
1205
{
1195
1206
name : 'TypeError' ,
1196
1207
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"`
1198
1209
}
1199
1210
) ;
1200
1211
}
0 commit comments