Sha256: 2ad8657a58708ac50d56ad973ce763782c2e3cfa438499ba97052ae1927f01df

Contents?: true

Size: 925 Bytes

Versions: 19

Compression:

Stored size: 925 Bytes

Contents

#include <ruby.h>

VALUE WebSocket = Qnil;
VALUE WebSocketMask = Qnil;

void Init_websocket_mask();
VALUE method_websocket_mask(VALUE self, VALUE payload, VALUE mask);

void
Init_websocket_mask()
{
  WebSocket = rb_define_module("WebSocket");
  WebSocketMask = rb_define_module_under(WebSocket, "Mask");
  rb_define_singleton_method(WebSocketMask, "mask", method_websocket_mask, 2);
}

VALUE
method_websocket_mask(VALUE self,
                      VALUE payload,
                      VALUE mask)
{
  char *payload_s, *mask_s, *unmasked_s;
  int 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;
}

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/websocket-driver-0.5.4/ext/websocket-driver/websocket_mask.c
solidus_backend-1.0.0.pre2 vendor/bundle/gems/websocket-driver-0.5.4/ext/websocket-driver/websocket_mask.c
websocket-driver-0.6.2-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.6.2 ext/websocket-driver/websocket_mask.c
websocket-driver-0.6.1-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.6.1 ext/websocket-driver/websocket_mask.c
websocket-driver-0.6.0-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.6.0 ext/websocket-driver/websocket_mask.c
solidus_backend-1.0.0.pre vendor/bundle/gems/websocket-driver-0.5.4/ext/websocket-driver/websocket_mask.c
websocket-driver-0.5.4-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.5.4 ext/websocket-driver/websocket_mask.c
websocket-driver-0.5.3-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.5.3 ext/websocket-driver/websocket_mask.c
websocket-driver-0.5.2-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.5.2 ext/websocket-driver/websocket_mask.c
websocket-driver-0.5.1-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.5.1 ext/websocket-driver/websocket_mask.c
websocket-driver-0.5.0 ext/websocket-driver/websocket_mask.c
websocket-driver-0.5.0-java ext/websocket-driver/websocket_mask.c