@@ -958,7 +958,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
958958 }
959959
960960 // Test invalid divisor lengths.
961- for ( const divisorLength of [ 'a' , true , { } , [ ] , 4096.1 ] ) {
961+ for ( const divisorLength of [ 'a' , true , { } , [ ] , 4096.1 , 2147483648 , - 1 ] ) {
962962 assert . throws ( ( ) => generateKeyPair ( 'dsa' , {
963963 modulusLength : 2048 ,
964964 divisorLength
@@ -1081,6 +1081,52 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
10811081 message : 'Unknown DH group'
10821082 } ) ;
10831083
1084+ assert . throws ( ( ) => {
1085+ generateKeyPair ( 'dh' , {
1086+ primeLength : 2147483648
1087+ } , common . mustNotCall ( ) ) ;
1088+ } , {
1089+ name : 'TypeError' ,
1090+ code : 'ERR_INVALID_ARG_VALUE' ,
1091+ message : "The property 'options.primeLength' is invalid. " +
1092+ 'Received 2147483648' ,
1093+ } ) ;
1094+
1095+ assert . throws ( ( ) => {
1096+ generateKeyPair ( 'dh' , {
1097+ primeLength : - 1
1098+ } , common . mustNotCall ( ) ) ;
1099+ } , {
1100+ name : 'TypeError' ,
1101+ code : 'ERR_INVALID_ARG_VALUE' ,
1102+ message : "The property 'options.primeLength' is invalid. " +
1103+ 'Received -1' ,
1104+ } ) ;
1105+
1106+ assert . throws ( ( ) => {
1107+ generateKeyPair ( 'dh' , {
1108+ primeLength : 2 ,
1109+ generator : 2147483648 ,
1110+ } , common . mustNotCall ( ) ) ;
1111+ } , {
1112+ name : 'TypeError' ,
1113+ code : 'ERR_INVALID_ARG_VALUE' ,
1114+ message : "The property 'options.generator' is invalid. " +
1115+ 'Received 2147483648' ,
1116+ } ) ;
1117+
1118+ assert . throws ( ( ) => {
1119+ generateKeyPair ( 'dh' , {
1120+ primeLength : 2 ,
1121+ generator : - 1 ,
1122+ } , common . mustNotCall ( ) ) ;
1123+ } , {
1124+ name : 'TypeError' ,
1125+ code : 'ERR_INVALID_ARG_VALUE' ,
1126+ message : "The property 'options.generator' is invalid. " +
1127+ 'Received -1' ,
1128+ } ) ;
1129+
10841130 // Test incompatible options.
10851131 const allOpts = {
10861132 group : 'modp5' ,
@@ -1142,6 +1188,35 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
11421188 } ) ;
11431189 }
11441190
1191+ // too long salt length
1192+ assert . throws ( ( ) => {
1193+ generateKeyPair ( 'rsa-pss' , {
1194+ modulusLength : 512 ,
1195+ saltLength : 2147483648 ,
1196+ hash : 'sha256' ,
1197+ mgf1Hash : 'sha256'
1198+ } , common . mustNotCall ( ) ) ;
1199+ } , {
1200+ name : 'TypeError' ,
1201+ code : 'ERR_INVALID_ARG_VALUE' ,
1202+ message : "The property 'options.saltLength' is invalid. " +
1203+ 'Received 2147483648'
1204+ } ) ;
1205+
1206+ assert . throws ( ( ) => {
1207+ generateKeyPair ( 'rsa-pss' , {
1208+ modulusLength : 512 ,
1209+ saltLength : - 1 ,
1210+ hash : 'sha256' ,
1211+ mgf1Hash : 'sha256'
1212+ } , common . mustNotCall ( ) ) ;
1213+ } , {
1214+ name : 'TypeError' ,
1215+ code : 'ERR_INVALID_ARG_VALUE' ,
1216+ message : "The property 'options.saltLength' is invalid. " +
1217+ 'Received -1'
1218+ } ) ;
1219+
11451220 // Invalid private key type.
11461221 for ( const type of [ 'foo' , 'spki' ] ) {
11471222 assert . throws ( ( ) => {
0 commit comments