1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-15 10:35:19 -05:00

ws: use crypto getRandomValues (denoland/deno_std#584)

Original: bc7dd3904b
This commit is contained in:
Nimalan 2019-09-04 20:12:40 +05:30 committed by Ryan Dahl
parent eea856e341
commit 7213d9cc7f

View file

@ -189,11 +189,7 @@ export async function readFrame(buf: BufReader): Promise<WebSocketFrame> {
// Create client-to-server mask, random 32bit number // Create client-to-server mask, random 32bit number
function createMask(): Uint8Array { function createMask(): Uint8Array {
// TODO: use secure and immutable random function. Crypto.getRandomValues() return crypto.getRandomValues(new Uint8Array(4));
const arr = Array.from({ length: 4 }).map(
(): number => Math.round(Math.random() * 0xff)
);
return new Uint8Array(arr);
} }
class WebSocketImpl implements WebSocket { class WebSocketImpl implements WebSocket {