From 0b94ec8c30a9811bb93f9e60f3615b899e9d120a Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 21 May 2022 17:51:28 +0800 Subject: [PATCH] crypto: use `kEmptyObject` PR-URL: https://github.com/nodejs/node/pull/43159 Reviewed-By: Matteo Collina Reviewed-By: Antoine du Hamel --- lib/internal/crypto/keygen.js | 7 +++++-- lib/internal/crypto/random.js | 13 +++++++------ lib/internal/crypto/x509.js | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index 5004ad1a4b7..93c23d4d38b 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -38,7 +38,10 @@ const { kAesKeyLengths, } = require('internal/crypto/util'); -const { customPromisifyArgs } = require('internal/util'); +const { + customPromisifyArgs, + kEmptyObject, +} = require('internal/util'); const { isInt32, @@ -118,7 +121,7 @@ function handleError(ret) { }; } -function parseKeyEncoding(keyType, options = {}) { +function parseKeyEncoding(keyType, options = kEmptyObject) { const { publicKeyEncoding, privateKeyEncoding } = options; let publicFormat, publicType; diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index 43d7a022a67..277ddf95eb4 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -26,6 +26,7 @@ const { } = internalBinding('crypto'); const { + kEmptyObject, lazyDOMException, } = require('internal/util'); @@ -399,7 +400,7 @@ function randomUUID(options) { validateObject(options, 'options'); const { disableEntropyCache = false, - } = options || {}; + } = options || kEmptyObject; validateBoolean(disableEntropyCache, 'options.disableEntropyCache'); @@ -464,7 +465,7 @@ function generatePrime(size, options, callback) { validateInt32(size, 'size', 1); if (typeof options === 'function') { callback = options; - options = {}; + options = kEmptyObject; } validateCallback(callback); @@ -482,7 +483,7 @@ function generatePrime(size, options, callback) { job.run(); } -function generatePrimeSync(size, options = {}) { +function generatePrimeSync(size, options = kEmptyObject) { validateInt32(size, 'size', 1); const job = createRandomPrimeJob(kCryptoJobSync, size, options); @@ -506,7 +507,7 @@ function unsignedBigIntToBuffer(bigint, name) { return Buffer.from(padded, 'hex'); } -function checkPrime(candidate, options = {}, callback) { +function checkPrime(candidate, options = kEmptyObject, callback) { if (typeof candidate === 'bigint') candidate = unsignedBigIntToBuffer(candidate, 'candidate'); if (!isAnyArrayBuffer(candidate) && !isArrayBufferView(candidate)) { @@ -524,7 +525,7 @@ function checkPrime(candidate, options = {}, callback) { } if (typeof options === 'function') { callback = options; - options = {}; + options = kEmptyObject; } validateCallback(callback); validateObject(options, 'options'); @@ -539,7 +540,7 @@ function checkPrime(candidate, options = {}, callback) { job.run(); } -function checkPrimeSync(candidate, options = {}) { +function checkPrimeSync(candidate, options = kEmptyObject) { if (typeof candidate === 'bigint') candidate = unsignedBigIntToBuffer(candidate, 'candidate'); if (!isAnyArrayBuffer(candidate) && !isArrayBufferView(candidate)) { diff --git a/lib/internal/crypto/x509.js b/lib/internal/crypto/x509.js index cd20f6868da..c8356dea2b2 100644 --- a/lib/internal/crypto/x509.js +++ b/lib/internal/crypto/x509.js @@ -23,6 +23,7 @@ const { const { customInspectSymbol: kInspect, + kEmptyObject, } = require('internal/util'); const { @@ -62,7 +63,7 @@ function isX509Certificate(value) { return value[kInternalState] !== undefined; } -function getFlags(options = {}) { +function getFlags(options = kEmptyObject) { validateObject(options, 'options'); const { // TODO(tniessen): change the default to 'default'