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#^
source ^ mask → io_buffer
io_buffer.c
View on GitHub ↗
static VALUE
io_buffer_xor(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);
VALUE output = rb_io_buffer_new(NULL, data->size, io_flags_for_size(data->size));
struct rb_io_buffer *output_data = NULL;
TypedData_Get_Struct(output, struct rb_io_buffer, &rb_io_buffer_type, output_data);
memory_xor(output_data->base, data->base, data->size, mask_data->base, mask_data->size);
return output;
}
Generate a new buffer the same size as the source by applying the binary XOR operation to the source, using the mask, repeating as necessary.
Example
IO::Buffer.for("1234567890") ^ IO::Buffer.for("\xFF\x00\x00\xFF") # => # #<IO::Buffer 0x000055a2d5d10480+10 INTERNAL> # 0x00000000 ce 32 33 cb ca 36 37 c7 c6 30 .23..67..0