Class: ActiverecordCursorPagination::SecureCursorSerializer
- Inherits:
-
Serializer
- Object
- Serializer
- ActiverecordCursorPagination::SecureCursorSerializer
- Defined in:
- lib/activerecord_cursor_pagination/secure_cursor_serializer.rb
Overview
Secure cursor serializer implementation using AES 256 encryption.
Instance Method Summary collapse
-
#deserialize(str) ⇒ Hash
Deserializes the secure cursor.
-
#serialize(hash) ⇒ String
Serializes and secures the hash representation of a cursor.
Instance Method Details
#deserialize(str) ⇒ Hash
Deserializes the secure cursor.
11 12 13 14 15 16 17 18 |
# File 'lib/activerecord_cursor_pagination/secure_cursor_serializer.rb', line 11 def deserialize(str) c = cipher.decrypt c.key = cipher_key decoded = Base64.strict_decode64 str decrypted = c.update(decoded) + c.final json = JSON.parse decrypted json.symbolize_keys end |
#serialize(hash) ⇒ String
Serializes and secures the hash representation of a cursor.
26 27 28 29 30 31 32 |
# File 'lib/activerecord_cursor_pagination/secure_cursor_serializer.rb', line 26 def serialize(hash) c = cipher.encrypt c.key = cipher_key json = JSON.generate hash encrypted = c.update(json) + c.final Base64.strict_encode64 encrypted end |