From 7213d9cc7f8b802d3345c9afa6968ab2ad05fd56 Mon Sep 17 00:00:00 2001 From: Nimalan Date: Wed, 4 Sep 2019 20:12:40 +0530 Subject: [PATCH] ws: use crypto getRandomValues (denoland/deno_std#584) Original: https://github.com/denoland/deno_std/commit/bc7dd3904bede90b9e7ae96674446ab6e9d4ccfc --- ws/mod.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ws/mod.ts b/ws/mod.ts index b649ef1781a2fc..ce2b90e3ab2378 100644 --- a/ws/mod.ts +++ b/ws/mod.ts @@ -189,11 +189,7 @@ export async function readFrame(buf: BufReader): Promise { // Create client-to-server mask, random 32bit number function createMask(): Uint8Array { - // TODO: use secure and immutable random function. Crypto.getRandomValues() - const arr = Array.from({ length: 4 }).map( - (): number => Math.round(Math.random() * 0xff) - ); - return new Uint8Array(arr); + return crypto.getRandomValues(new Uint8Array(4)); } class WebSocketImpl implements WebSocket {