Skip to content

Commit

Permalink
crypto: use kEmptyObject
Browse files Browse the repository at this point in the history
PR-URL: #43159
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
LiviaMedeiros authored and danielleadams committed Jun 13, 2022
1 parent 7b5cb14 commit df0903c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions lib/internal/crypto/keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const {
kAesKeyLengths,
} = require('internal/crypto/util');

const { customPromisifyArgs } = require('internal/util');
const {
customPromisifyArgs,
kEmptyObject,
} = require('internal/util');

const {
validateFunction,
Expand Down Expand Up @@ -119,7 +122,7 @@ function handleError(ret) {
};
}

function parseKeyEncoding(keyType, options = {}) {
function parseKeyEncoding(keyType, options = kEmptyObject) {
const { publicKeyEncoding, privateKeyEncoding } = options;

let publicFormat, publicType;
Expand Down
13 changes: 7 additions & 6 deletions lib/internal/crypto/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
} = internalBinding('crypto');

const {
kEmptyObject,
lazyDOMException,
} = require('internal/util');

Expand Down Expand Up @@ -399,7 +400,7 @@ function randomUUID(options) {
validateObject(options, 'options');
const {
disableEntropyCache = false,
} = options || {};
} = options || kEmptyObject;

validateBoolean(disableEntropyCache, 'options.disableEntropyCache');

Expand Down Expand Up @@ -464,7 +465,7 @@ function generatePrime(size, options, callback) {
validateInt32(size, 'size', 1);
if (typeof options === 'function') {
callback = options;
options = {};
options = kEmptyObject;
}
validateFunction(callback, 'callback');

Expand All @@ -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);
Expand All @@ -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)) {
Expand All @@ -524,7 +525,7 @@ function checkPrime(candidate, options = {}, callback) {
}
if (typeof options === 'function') {
callback = options;
options = {};
options = kEmptyObject;
}
validateFunction(callback, 'callback');
validateObject(options, 'options');
Expand All @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/crypto/x509.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const {

const {
customInspectSymbol: kInspect,
kEmptyObject,
} = require('internal/util');

const {
Expand Down Expand Up @@ -64,7 +65,7 @@ function isX509Certificate(value) {
return value[kInternalState] !== undefined;
}

function getFlags(options = {}) {
function getFlags(options = kEmptyObject) {
validateObject(options, 'options');
const {
subject = 'default', // Can be 'default', 'always', or 'never'
Expand Down

0 comments on commit df0903c

Please sign in to comment.