Sha256: 37887321aacba09ab4d1cc5e60a8bbc1ffaa9a67775356fe00045ef6a68ca0c5

Contents?: true

Size: 588 Bytes

Versions: 1

Compression:

Stored size: 588 Bytes

Contents

module EventMachine
  module WebSocket
    class MaskedString < String
      def read_mask
        raise "Too short" if bytesize < 4 # TODO - change
        @masking_key = String.new(self[0..3])
      end

      def slice_mask
        slice!(0, 4)
      end

      def getbyte(index)
        masked_char = super(index + 4)
        masked_char ? masked_char ^ @masking_key.getbyte(index % 4) : nil
      end

      def getbytes(start_index, count)
        data = ''
        count.times do |i|
          data << getbyte(start_index + i)
        end
        data
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
em-websocket-0.3.0 lib/em-websocket/masking04.rb