Skip to content

Commit

Permalink
ws: use crypto getRandomValues (denoland/std#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark1626 authored and ry committed Sep 4, 2019
1 parent eea856e commit 7213d9c
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions ws/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,7 @@ export async function readFrame(buf: BufReader): Promise<WebSocketFrame> {

// 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 {
Expand Down

0 comments on commit 7213d9c

Please sign in to comment.