@@ -41,13 +41,14 @@ const {
41
41
const { customPromisifyArgs } = require ( 'internal/util' ) ;
42
42
43
43
const {
44
- isInt32,
45
- isUint32,
44
+ validateBuffer,
46
45
validateCallback,
47
46
validateString,
47
+ validateInt32,
48
48
validateInteger,
49
49
validateObject,
50
50
validateOneOf,
51
+ validateUint32,
51
52
} = require ( 'internal/validators' ) ;
52
53
53
54
const {
@@ -172,16 +173,13 @@ function createJob(mode, type, options) {
172
173
{
173
174
validateObject ( options , 'options' ) ;
174
175
const { modulusLength } = options ;
175
- if ( ! isUint32 ( modulusLength ) )
176
- throw new ERR_INVALID_ARG_VALUE ( 'options.modulusLength' , modulusLength ) ;
176
+ validateUint32 ( modulusLength , 'options.modulusLength' ) ;
177
177
178
178
let { publicExponent } = options ;
179
179
if ( publicExponent == null ) {
180
180
publicExponent = 0x10001 ;
181
- } else if ( ! isUint32 ( publicExponent ) ) {
182
- throw new ERR_INVALID_ARG_VALUE (
183
- 'options.publicExponent' ,
184
- publicExponent ) ;
181
+ } else {
182
+ validateUint32 ( publicExponent , 'options.publicExponent' ) ;
185
183
}
186
184
187
185
if ( type === 'rsa' ) {
@@ -194,12 +192,12 @@ function createJob(mode, type, options) {
194
192
}
195
193
196
194
const { hash, mgf1Hash, saltLength } = options ;
197
- if ( hash !== undefined && typeof hash !== 'string' )
198
- throw new ERR_INVALID_ARG_VALUE ( 'options.hash' , hash ) ;
199
- if ( mgf1Hash !== undefined && typeof mgf1Hash !== 'string' )
200
- throw new ERR_INVALID_ARG_VALUE ( 'options.mgf1Hash' , mgf1Hash ) ;
201
- if ( saltLength !== undefined && ( ! isInt32 ( saltLength ) || saltLength < 0 ) )
202
- throw new ERR_INVALID_ARG_VALUE ( 'options.saltLength' , saltLength ) ;
195
+ if ( hash !== undefined )
196
+ validateString ( hash , 'options.hash' ) ;
197
+ if ( mgf1Hash !== undefined )
198
+ validateString ( mgf1Hash , 'options.mgf1Hash' ) ;
199
+ if ( saltLength !== undefined )
200
+ validateInt32 ( saltLength , 'options.saltLength' , 0 ) ;
203
201
204
202
return new RsaKeyPairGenJob (
205
203
mode ,
@@ -215,15 +213,13 @@ function createJob(mode, type, options) {
215
213
{
216
214
validateObject ( options , 'options' ) ;
217
215
const { modulusLength } = options ;
218
- if ( ! isUint32 ( modulusLength ) )
219
- throw new ERR_INVALID_ARG_VALUE ( 'options.modulusLength' , modulusLength ) ;
216
+ validateUint32 ( modulusLength , 'options.modulusLength' ) ;
220
217
221
218
let { divisorLength } = options ;
222
219
if ( divisorLength == null ) {
223
220
divisorLength = - 1 ;
224
- } else if ( ! isInt32 ( divisorLength ) || divisorLength < 0 ) {
225
- throw new ERR_INVALID_ARG_VALUE ( 'options.divisorLength' , divisorLength ) ;
226
- }
221
+ } else
222
+ validateInt32 ( divisorLength , 'options.divisorLength' , 0 ) ;
227
223
228
224
return new DsaKeyPairGenJob (
229
225
mode ,
@@ -235,8 +231,7 @@ function createJob(mode, type, options) {
235
231
{
236
232
validateObject ( options , 'options' ) ;
237
233
const { namedCurve } = options ;
238
- if ( typeof namedCurve !== 'string' )
239
- throw new ERR_INVALID_ARG_VALUE ( 'options.namedCurve' , namedCurve ) ;
234
+ validateString ( namedCurve , 'options.namedCurve' ) ;
240
235
let { paramEncoding } = options ;
241
236
if ( paramEncoding == null || paramEncoding === 'named' )
242
237
paramEncoding = OPENSSL_EC_NAMED_CURVE ;
@@ -284,28 +279,26 @@ function createJob(mode, type, options) {
284
279
throw new ERR_INCOMPATIBLE_OPTION_PAIR ( 'group' , 'primeLength' ) ;
285
280
if ( generator != null )
286
281
throw new ERR_INCOMPATIBLE_OPTION_PAIR ( 'group' , 'generator' ) ;
287
- if ( typeof group !== 'string' )
288
- throw new ERR_INVALID_ARG_VALUE ( 'options.group' , group ) ;
282
+
283
+ validateString ( group , 'options.group' ) ;
289
284
290
285
return new DhKeyPairGenJob ( mode , group , ...encoding ) ;
291
286
}
292
287
293
288
if ( prime != null ) {
294
289
if ( primeLength != null )
295
290
throw new ERR_INCOMPATIBLE_OPTION_PAIR ( 'prime' , 'primeLength' ) ;
296
- if ( ! isArrayBufferView ( prime ) )
297
- throw new ERR_INVALID_ARG_VALUE ( 'options.prime' , prime ) ;
291
+
292
+ validateBuffer ( prime , 'options.prime' ) ;
298
293
} else if ( primeLength != null ) {
299
- if ( ! isInt32 ( primeLength ) || primeLength < 0 )
300
- throw new ERR_INVALID_ARG_VALUE ( 'options.primeLength' , primeLength ) ;
294
+ validateInt32 ( primeLength , 'options.primeLength' , 0 ) ;
301
295
} else {
302
296
throw new ERR_MISSING_OPTION (
303
297
'At least one of the group, prime, or primeLength options' ) ;
304
298
}
305
299
306
300
if ( generator != null ) {
307
- if ( ! isInt32 ( generator ) || generator < 0 )
308
- throw new ERR_INVALID_ARG_VALUE ( 'options.generator' , generator ) ;
301
+ validateInt32 ( generator , 'options.generator' , 0 ) ;
309
302
}
310
303
return new DhKeyPairGenJob (
311
304
mode ,
0 commit comments