Skip to Content Skip to Search

class ActiveRecord::Encryption::MessageSerializer

A message serializer that serializes Messages with JSON.

The generated structure is pretty simple:

{
  p: <payload>,
  h: {
    header1: value1,
    header2: value2,
    ...
  }
}

Both the payload and the header values are encoded with Base64 to prevent JSON parsing errors and encoding issues when storing the resulting serialized data.

Public instance methods

Source code GitHub
# File activerecord/lib/active_record/encryption/message_serializer.rb, line 36
def binary?
  false
end
Source code GitHub
# File activerecord/lib/active_record/encryption/message_serializer.rb, line 31
def dump(message)
  raise ActiveRecord::Encryption::Errors::ForbiddenClass unless message.is_a?(ActiveRecord::Encryption::Message)
  JSON.dump message_to_json(message)
end
Source code GitHub
# File activerecord/lib/active_record/encryption/message_serializer.rb, line 24
def load(serialized_content)
  data = JSON.parse(serialized_content)
  parse_message(data, 1)
rescue JSON::ParserError
  raise ActiveRecord::Encryption::Errors::Encoding
end

Definition files