Module: WebSocket::Mask

Defined in:
lib/websocket/mask.rb,
ext/websocket-driver/websocket_mask.c

Class Method Summary collapse

Class Method Details

.mask(payload, mask) ⇒ Object


3
4
5
6
7
8
9
10
11
# File 'ext/websocket-driver/websocket_mask.c', line 3

def self.mask(payload, mask)
  return payload if mask.nil? || payload.empty?

  payload.tap do |result|
    payload.bytesize.times do |i|
      result.setbyte(i, payload.getbyte(i) ^ mask.getbyte(i % 4))
    end
  end
end