Skip to content

Commit

Permalink
crypto: reduce range of size to int max
Browse files Browse the repository at this point in the history
Refs: #38090

PR-URL: #38096
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
Ayase-252 authored and jasnell committed Apr 12, 2021
1 parent 8dd0685 commit 993ed19
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/internal/crypto/random.js
Expand Up @@ -57,8 +57,8 @@ const {

const { FastBuffer } = require('internal/buffer');

const kMaxUint32 = 2 ** 32 - 1;
const kMaxPossibleLength = MathMin(kMaxLength, kMaxUint32);
const kMaxInt32 = 2 ** 31 - 1;
const kMaxPossibleLength = MathMin(kMaxLength, kMaxInt32);

function assertOffset(offset, elementSize, length) {
validateNumber(offset, 'offset');
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-crypto-random.js
Expand Up @@ -32,8 +32,8 @@ const cryptop = require('crypto').webcrypto;
const { kMaxLength } = require('buffer');
const { inspect } = require('util');

const kMaxUint32 = Math.pow(2, 32) - 1;
const kMaxPossibleLength = Math.min(kMaxLength, kMaxUint32);
const kMaxInt32 = 2 ** 31 - 1;
const kMaxPossibleLength = Math.min(kMaxLength, kMaxInt32);

common.expectWarning('DeprecationWarning',
'crypto.pseudoRandomBytes is deprecated.', 'DEP0115');
Expand All @@ -51,7 +51,7 @@ common.expectWarning('DeprecationWarning',
assert.throws(() => f(value, common.mustNotCall()), errObj);
});

[-1, NaN, 2 ** 32].forEach((value) => {
[-1, NaN, 2 ** 32, 2 ** 31].forEach((value) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
Expand Down

0 comments on commit 993ed19

Please sign in to comment.