Class: RomEncryptedAttribute::Payload
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- RomEncryptedAttribute::Payload
- Defined in:
- lib/rom_encrypted_attribute/payload.rb
Defined Under Namespace
Classes: Types
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.decode(database_value) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/rom_encrypted_attribute/payload.rb', line 16 def self.decode(database_value) payload = JSON.parse(database_value) new( message: decode64(payload["p"]), initialization_vector: decode64(payload.dig("h", "iv")), auth_tag: decode64(payload.dig("h", "at")) ) end |
.decode64(value) ⇒ Object
25 26 27 |
# File 'lib/rom_encrypted_attribute/payload.rb', line 25 def self.decode64(value) Base64.strict_decode64(value) end |
Instance Method Details
#encode ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rom_encrypted_attribute/payload.rb', line 29 def encode payload = { "p" => encode64(), "h" => { "iv" => encode64(initialization_vector), "at" => encode64(auth_tag) } } JSON.dump(payload) end |