Sha256: a0a475b33c6729a44359ea0e5e643b77f1466c97e7e870b490f0a9112169ff72

Contents?: true

Size: 767 Bytes

Versions: 28

Compression:

Stored size: 767 Bytes

Contents

#include <ruby.h>

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;
}

void Init_websocket_mask()
{
    VALUE WebSocket = rb_define_module("WebSocket");
    VALUE Mask = rb_define_module_under(WebSocket, "Mask");

    rb_define_singleton_method(Mask, "mask", method_websocket_mask, 2);
}

Version data entries

28 entries across 28 versions & 11 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/websocket-driver-0.7.6/ext/websocket-driver/websocket_mask.c
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/websocket-driver-0.7.6/ext/websocket-driver/websocket_mask.c
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/websocket-driver-0.7.6/ext/websocket-driver/websocket_mask.c
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/websocket-driver-0.7.6/ext/websocket-driver/websocket_mask.c
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/websocket-driver-0.7.6/ext/websocket-driver/websocket_mask.c
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/websocket-driver-0.7.5/ext/websocket-driver/websocket_mask.c
websocket-driver-0.7.6-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.7.6 ext/websocket-driver/websocket_mask.c
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/websocket-driver-0.7.5/ext/websocket-driver/websocket_mask.c
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/websocket-driver-0.7.5/ext/websocket-driver/websocket_mask.c
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/websocket-driver-0.7.5/ext/websocket-driver/websocket_mask.c
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/websocket-driver-0.7.5/ext/websocket-driver/websocket_mask.c
websocket-driver-0.7.5-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.7.5 ext/websocket-driver/websocket_mask.c
websocket-driver-0.7.4-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.7.4 ext/websocket-driver/websocket_mask.c
websocket-driver-0.7.3-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.7.3 ext/websocket-driver/websocket_mask.c
websocket-driver-0.7.2-java ext/websocket-driver/websocket_mask.c
websocket-driver-0.7.2 ext/websocket-driver/websocket_mask.c