End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
IO::Buffer#xor!
source.xor!(mask) → io_buffer
io_buffer.c
View on GitHub ↗
static VALUE
io_buffer_xor_inplace(VALUE self, VALUE mask)
{
struct rb_io_buffer *data = NULL;
TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, data);
struct rb_io_buffer *mask_data = NULL;
TypedData_Get_Struct(mask, struct rb_io_buffer, &rb_io_buffer_type, mask_data);
io_buffer_check_mask(mask_data);
io_buffer_check_overlaps(data, mask_data);
void *base;
size_t size;
io_buffer_get_bytes_for_writing(data, &base, &size);
memory_xor_inplace(base, size, mask_data->base, mask_data->size);
return self;
}
Modify the source buffer in place by applying the binary XOR operation to the source, using the mask, repeating as necessary.
Example
source = IO::Buffer.for("1234567890").dup # Make a read/write copy. # => # #<IO::Buffer 0x000056307a25b3e0+10 INTERNAL> # 0x00000000 31 32 33 34 35 36 37 38 39 30 1234567890 source.xor!(IO::Buffer.for("\xFF\x00\x00\xFF")) # => # #<IO::Buffer 0x000056307a25b3e0+10 INTERNAL> # 0x00000000 ce 32 33 cb ca 36 37 c7 c6 30 .23..67..0