Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/node/internal/crypto_cipher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ export function publicEncrypt(
): Buffer {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (key === undefined) {
throw new ERR_MISSING_ARGS('privateKey');
throw new ERR_MISSING_ARGS('key');
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (buffer === undefined) {
Expand Down Expand Up @@ -660,7 +660,7 @@ export function publicDecrypt(
): Buffer {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (key === undefined) {
throw new ERR_MISSING_ARGS('privateKey');
throw new ERR_MISSING_ARGS('key');
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (buffer === undefined) {
Expand Down
6 changes: 3 additions & 3 deletions src/node/internal/crypto_random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function randomFillSync(
} else offset = 0;
if (size !== undefined) {
validateInteger(size, 'size', 0, maxLength - offset);
} else size = maxLength;
} else size = maxLength - offset;
if (isAnyArrayBuffer(buffer)) {
buffer = Buffer.from(buffer);
}
Expand Down Expand Up @@ -243,8 +243,8 @@ export function randomInt(
max = minOrMax;
}

if (min > max) {
throw new ERR_OUT_OF_RANGE('min', 'min <= max', min);
if (min >= max) {
throw new ERR_OUT_OF_RANGE('min', 'min < max', min);
}

if (callback != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/node/internal/crypto_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ArrayLike = cryptoImpl.ArrayLike;

export const kHandle = Symbol('kHandle');
export const kFinalized = Symbol('kFinalized');
export const kState = Symbol('kFinalized');
export const kState = Symbol('kState');

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getStringOption(options: any, key: string): string | undefined {
Expand Down
2 changes: 1 addition & 1 deletion src/node/internal/internal_inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,7 @@ function isRpcWildcardType(value: unknown) {
return (
value instanceof internalWorkers.RpcStub ||
value instanceof internalWorkers.RpcPromise ||
value instanceof internalWorkers.RpcPromise
value instanceof internalWorkers.RpcProperty
);
}

Expand Down
34 changes: 34 additions & 0 deletions src/workerd/api/node/tests/crypto_random-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,40 @@ export const timingSafeEqualTest = {
},
};

export const randomIntTest = {
async test() {
const { randomInt } = await import('node:crypto');

// min === max should throw, not infinite-loop
throws(() => randomInt(5, 5), { code: 'ERR_OUT_OF_RANGE' });

// min > max should throw
throws(() => randomInt(10, 5), { code: 'ERR_OUT_OF_RANGE' });

// Valid range returns value in [min, max)
const val = randomInt(0, 10);
ok(val >= 0 && val < 10);

// Single-arg form: randomInt(max) means [0, max)
strictEqual(randomInt(1), 0);
},
};

export const randomFillSyncTest = {
async test() {
const { randomFillSync } = await import('node:crypto');

// With offset but no size, should fill only buf.length - offset bytes
const buf = Buffer.alloc(10, 0);
randomFillSync(buf, 4);

// First 4 bytes must be untouched (all zero)
for (let i = 0; i < 4; i++) {
strictEqual(buf[i], 0, `byte ${i} should be untouched`);
}
},
};

// Ref: https://github.com/cloudflare/workerd/issues/2716
export const getRandomValuesIllegalInvocation = {
async test() {
Expand Down