module WebSocket::Mask - websocket-driver-0.6.5 Documentation

# module WebSocket::Mask

### Public Class Methods

mask(p1, p2) click to toggle source

    VALUE
    method_websocket_mask(VALUE self,
                          VALUE payload,
                          VALUE mask)
    {
      char *payload_s, *mask_s, *unmasked_s;
      long i, n;
      VALUE unmasked;

      if (mask == Qnil || RSTRING_LEN(mask) != 4) {
        return payload;
      }

      payload_s = RSTRING_PTR(payload);
      mask_s    = RSTRING_PTR(mask);
      n         = RSTRING_LEN(payload);

      unmasked   = rb_str_new(0, n);
      unmasked_s = RSTRING_PTR(unmasked);

      for (i = 0; i < n; i++) {
        unmasked_s[i] = payload_s[i] ^ mask_s[i % 4];
      }
      return unmasked;
    }