Skip to content

Commit

Permalink
[minor] Use crypto.randomFillSync() to generate the masking key
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Apr 26, 2019
1 parent 993b0cd commit 1b85466
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/sender.js
@@ -1,12 +1,14 @@
'use strict';

const { randomBytes } = require('crypto');
const { randomFillSync } = require('crypto');

const PerMessageDeflate = require('./permessage-deflate');
const { EMPTY_BUFFER } = require('./constants');
const { isValidStatusCode } = require('./validation');
const { mask: applyMask, toBuffer } = require('./buffer-util');

const mask = Buffer.alloc(4);

/**
* HyBi Sender implementation.
*/
Expand Down Expand Up @@ -71,7 +73,7 @@ class Sender {

if (!options.mask) return [target, data];

const mask = randomBytes(4);
randomFillSync(mask, 0, 4);

target[1] |= 0x80;
target[offset - 4] = mask[0];
Expand Down

0 comments on commit 1b85466

Please sign in to comment.