Skip to content

Commit

Permalink
ws: use crypto getRandomValues (#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 4e21ace commit bc7dd39
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions ws/mod.ts
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 bc7dd39

Please sign in to comment.