/
githubmirror
/
deno
Обзор
Документация
Войти
/
githubmirror
/
deno
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
tests/specs/node/crypto_random_bytes_buffer/main.ts
29 строк
1 KB
Copilot
fix(node/crypto): randomBytes returns buffer with dedicated ArrayBuffer (#32048)
04 фев 2026, 19:13
Не верифицирован
04 фев 2026, 19:13
60814fb
Код
Авторство
О чём код?
// Regression test for https://github.com/denoland/deno/issues/32047 // crypto.randomBytes should return a buffer with its own ArrayBuffer, // not a shared pool buffer. import { randomBytes } from "node:crypto"; // Test that the underlying ArrayBuffer has the expected size const buf8 = randomBytes(8); if (buf8.buffer.byteLength !== 8) { throw new Error( `Expected buffer.byteLength to be 8, got ${buf8.buffer.byteLength}`, ); } // Test that multiple calls return buffers with different underlying data // This was broken when using shared pool allocation - all values were identical const val1 = new BigUint64Array(randomBytes(8).buffer)[0]; const val2 = new BigUint64Array(randomBytes(8).buffer)[0]; const val3 = new BigUint64Array(randomBytes(8).buffer)[0]; // While extremely unlikely to be identical by chance, this specifically // tests the fix for the bug where all values were the same due to shared buffer pool if (val1 === val2 && val2 === val3) { throw new Error( `All random values were identical: ${val1} (shared buffer pool bug)`, ); } console.log("ok");