module Rack::Session::Encryptor::Serializable
Private Instance Methods
Source
# File lib/rack/session/encryptor.rb, line 45 def deserialized_message(data) # Read the first 2 bytes as the padding_bytes size padding_bytes, = data.unpack('v') # Slice out the serialized_data and deserialize it serialized_data = data.slice(2 + padding_bytes, data.bytesize) serializer.load serialized_data end
Return the deserialized message. The first 2 bytes will be read as the amount of padding.
Source
# File lib/rack/session/encryptor.rb, line 32 def serialize_payload(message) serialized_data = serializer.dump(message) return "#{[0].pack('v')}#{serialized_data.force_encoding(Encoding::BINARY)}" if @options[:pad_size].nil? padding_bytes = @options[:pad_size] - (2 + serialized_data.size) % @options[:pad_size] padding_data = SecureRandom.random_bytes(padding_bytes) "#{[padding_bytes].pack('v')}#{padding_data}#{serialized_data.force_encoding(Encoding::BINARY)}" end
Returns a serialized payload of the message. If a :pad_size is supplied, the message will be padded. The first 2 bytes of the returned string will indicating the amount of padding.
Source
# File lib/rack/session/encryptor.rb, line 54 def serializer @serializer ||= @options[:serialize_json] ? JSON : Marshal end