mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(node): add crypto.pseudoRandomBytes (#21649)
This commit is contained in:
parent
55fac9f5ea
commit
5aa27c45f1
2 changed files with 27 additions and 1 deletions
|
@ -6,7 +6,7 @@ import {
|
||||||
assertThrows,
|
assertThrows,
|
||||||
} from "../../../../test_util/std/assert/mod.ts";
|
} from "../../../../test_util/std/assert/mod.ts";
|
||||||
import { assertCallbackErrorUncaught } from "../_test_utils.ts";
|
import { assertCallbackErrorUncaught } from "../_test_utils.ts";
|
||||||
import { randomBytes } from "node:crypto";
|
import { pseudoRandomBytes, randomBytes } from "node:crypto";
|
||||||
|
|
||||||
const MAX_RANDOM_VALUES = 65536;
|
const MAX_RANDOM_VALUES = 65536;
|
||||||
const MAX_SIZE = 4294967295;
|
const MAX_SIZE = 4294967295;
|
||||||
|
@ -90,3 +90,23 @@ Deno.test("[std/node/crypto] randomBytes callback isn't called twice if error is
|
||||||
invocation: "randomBytes(0, ",
|
invocation: "randomBytes(0, ",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// https://github.com/denoland/deno/issues/21632
|
||||||
|
Deno.test("pseudoRandomBytes works", function () {
|
||||||
|
assertEquals(pseudoRandomBytes(0).length, 0, "len: " + 0);
|
||||||
|
assertEquals(pseudoRandomBytes(3).length, 3, "len: " + 3);
|
||||||
|
assertEquals(pseudoRandomBytes(30).length, 30, "len: " + 30);
|
||||||
|
assertEquals(pseudoRandomBytes(300).length, 300, "len: " + 300);
|
||||||
|
assertEquals(
|
||||||
|
pseudoRandomBytes(17 + MAX_RANDOM_VALUES).length,
|
||||||
|
17 + MAX_RANDOM_VALUES,
|
||||||
|
"len: " + 17 + MAX_RANDOM_VALUES,
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
pseudoRandomBytes(MAX_RANDOM_VALUES * 100).length,
|
||||||
|
MAX_RANDOM_VALUES * 100,
|
||||||
|
"len: " + MAX_RANDOM_VALUES * 100,
|
||||||
|
);
|
||||||
|
assertThrows(() => pseudoRandomBytes(MAX_SIZE + 1));
|
||||||
|
assertThrows(() => pseudoRandomBytes(-1));
|
||||||
|
});
|
||||||
|
|
|
@ -306,6 +306,9 @@ const setFips = fipsForced ? setFipsForced : setFipsCrypto;
|
||||||
const sign = signOneShot;
|
const sign = signOneShot;
|
||||||
const verify = verifyOneShot;
|
const verify = verifyOneShot;
|
||||||
|
|
||||||
|
/* Deprecated in Node.js, alias of randomBytes */
|
||||||
|
const pseudoRandomBytes = randomBytes;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Certificate,
|
Certificate,
|
||||||
checkPrime,
|
checkPrime,
|
||||||
|
@ -353,6 +356,7 @@ export default {
|
||||||
publicDecrypt,
|
publicDecrypt,
|
||||||
publicEncrypt,
|
publicEncrypt,
|
||||||
randomBytes,
|
randomBytes,
|
||||||
|
pseudoRandomBytes,
|
||||||
randomFill,
|
randomFill,
|
||||||
randomFillSync,
|
randomFillSync,
|
||||||
randomInt,
|
randomInt,
|
||||||
|
@ -485,6 +489,8 @@ export {
|
||||||
pbkdf2Sync,
|
pbkdf2Sync,
|
||||||
privateDecrypt,
|
privateDecrypt,
|
||||||
privateEncrypt,
|
privateEncrypt,
|
||||||
|
/* Deprecated in Node.js, alias of randomBytes */
|
||||||
|
pseudoRandomBytes,
|
||||||
publicDecrypt,
|
publicDecrypt,
|
||||||
publicEncrypt,
|
publicEncrypt,
|
||||||
randomBytes,
|
randomBytes,
|
||||||
|
|
Loading…
Add table
Reference in a new issue