@@ -40,8 +40,6 @@ const {
40
40
} = require ( 'internal/errors' ) . codes ;
41
41
const constants = internalBinding ( 'constants' ) . crypto ;
42
42
const { getOptionValue } = require ( 'internal/options' ) ;
43
- const pendingDeprecation = getOptionValue ( '--pending-deprecation' ) ;
44
- const fipsForced = getOptionValue ( '--force-fips' ) ;
45
43
const {
46
44
getFipsCrypto,
47
45
setFipsCrypto,
@@ -221,8 +219,8 @@ module.exports = {
221
219
sign : signOneShot ,
222
220
setEngine,
223
221
timingSafeEqual,
224
- getFips : fipsForced ? getFipsForced : getFipsCrypto ,
225
- setFips : fipsForced ? setFipsForced : setFipsCrypto ,
222
+ getFips,
223
+ setFips,
226
224
verify : verifyOneShot ,
227
225
228
226
// Classes
@@ -243,23 +241,87 @@ module.exports = {
243
241
secureHeapUsed,
244
242
} ;
245
243
246
- function setFipsForced ( val ) {
247
- if ( val ) return ;
248
- throw new ERR_CRYPTO_FIPS_FORCED ( ) ;
244
+ function getFips ( ) {
245
+ return getOptionValue ( '--force-fips' ) ? 1 : getFipsCrypto ( ) ;
249
246
}
250
247
251
- function getFipsForced ( ) {
252
- return 1 ;
248
+ function setFips ( val ) {
249
+ if ( getOptionValue ( '--force-fips' ) ) {
250
+ if ( val ) return ;
251
+ throw new ERR_CRYPTO_FIPS_FORCED ( ) ;
252
+ } else {
253
+ setFipsCrypto ( val ) ;
254
+ }
253
255
}
254
256
255
257
function getRandomValues ( array ) {
256
258
return lazyWebCrypto ( ) . crypto . getRandomValues ( array ) ;
257
259
}
258
260
259
261
ObjectDefineProperty ( constants , 'defaultCipherList' , {
260
- value : getOptionValue ( '--tls-cipher-list' )
262
+ get ( ) {
263
+ const value = getOptionValue ( '--tls-cipher-list' ) ;
264
+ ObjectDefineProperty ( this , 'defaultCipherList' , {
265
+ writable : true ,
266
+ configurable : true ,
267
+ enumerable : true ,
268
+ value
269
+ } ) ;
270
+ return value ;
271
+ } ,
272
+ set ( val ) {
273
+ ObjectDefineProperty ( this , 'defaultCipherList' , {
274
+ writable : true ,
275
+ configurable : true ,
276
+ enumerable : true ,
277
+ value : val
278
+ } ) ;
279
+ } ,
280
+ configurable : true ,
281
+ enumerable : true ,
261
282
} ) ;
262
283
284
+ function getRandomBytesAlias ( key ) {
285
+ return {
286
+ enumerable : false ,
287
+ configurable : true ,
288
+ get ( ) {
289
+ let value ;
290
+ if ( getOptionValue ( '--pending-deprecation' ) ) {
291
+ value = deprecate (
292
+ randomBytes ,
293
+ `crypto.${ key } is deprecated.` ,
294
+ 'DEP0115' ) ;
295
+ } else {
296
+ value = randomBytes ;
297
+ }
298
+ ObjectDefineProperty (
299
+ this ,
300
+ key ,
301
+ {
302
+ enumerable : false ,
303
+ configurable : true ,
304
+ writable : true ,
305
+ value : value
306
+ }
307
+ ) ;
308
+ return value ;
309
+ } ,
310
+ set ( value ) {
311
+ ObjectDefineProperty (
312
+ this ,
313
+ key ,
314
+ {
315
+ enumerable : true ,
316
+ configurable : true ,
317
+ writable : true ,
318
+ value
319
+ }
320
+ ) ;
321
+ }
322
+ } ;
323
+ }
324
+
263
325
ObjectDefineProperties ( module . exports , {
264
326
createCipher : {
265
327
enumerable : false ,
@@ -273,8 +335,8 @@ ObjectDefineProperties(module.exports, {
273
335
} ,
274
336
// crypto.fips is deprecated. DEP0093. Use crypto.getFips()/crypto.setFips()
275
337
fips : {
276
- get : fipsForced ? getFipsForced : getFipsCrypto ,
277
- set : fipsForced ? setFipsForced : setFipsCrypto
338
+ get : getFips ,
339
+ set : setFips ,
278
340
} ,
279
341
DEFAULT_ENCODING : {
280
342
enumerable : false ,
@@ -313,29 +375,7 @@ ObjectDefineProperties(module.exports, {
313
375
314
376
// Aliases for randomBytes are deprecated.
315
377
// The ecosystem needs those to exist for backwards compatibility.
316
- prng : {
317
- enumerable : false ,
318
- configurable : true ,
319
- writable : true ,
320
- value : pendingDeprecation ?
321
- deprecate ( randomBytes , 'crypto.prng is deprecated.' , 'DEP0115' ) :
322
- randomBytes
323
- } ,
324
- pseudoRandomBytes : {
325
- enumerable : false ,
326
- configurable : true ,
327
- writable : true ,
328
- value : pendingDeprecation ?
329
- deprecate ( randomBytes ,
330
- 'crypto.pseudoRandomBytes is deprecated.' , 'DEP0115' ) :
331
- randomBytes
332
- } ,
333
- rng : {
334
- enumerable : false ,
335
- configurable : true ,
336
- writable : true ,
337
- value : pendingDeprecation ?
338
- deprecate ( randomBytes , 'crypto.rng is deprecated.' , 'DEP0115' ) :
339
- randomBytes
340
- }
378
+ prng : getRandomBytesAlias ( 'prng' ) ,
379
+ pseudoRandomBytes : getRandomBytesAlias ( 'pseudoRandomBytes' ) ,
380
+ rng : getRandomBytesAlias ( 'rng' )
341
381
} ) ;
0 commit comments