Class: ActiveRecord::Encryption::MessageSerializer
- Inherits:
-
Object
- Object
- ActiveRecord::Encryption::MessageSerializer
- Defined in:
- lib/active_record/encryption/message_serializer.rb
Overview
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.
Instance Method Summary collapse
Instance Method Details
#dump(message) ⇒ Object
29 30 31 32 |
# File 'lib/active_record/encryption/message_serializer.rb', line 29 def dump() raise ActiveRecord::Encryption::Errors::ForbiddenClass unless .is_a?(ActiveRecord::Encryption::Message) JSON.dump () end |
#load(serialized_content) ⇒ Object
[View source]
22 23 24 25 26 27 |
# File 'lib/active_record/encryption/message_serializer.rb', line 22 def load(serialized_content) data = JSON.parse(serialized_content) (data, 1) rescue JSON::ParserError raise ActiveRecord::Encryption::Errors::Encoding end |