Class: EventStoreClient::Mapper::Encrypted
- Inherits:
-
Object
- Object
- EventStoreClient::Mapper::Encrypted
- Defined in:
- lib/event_store_client/mapper/encrypted.rb
Overview
Transforms given event’s data and encrypts/decrypts selected subset of data based on encryption schema stored in the event itself.
Constant Summary collapse
- MissingEncryptionKey =
Class.new(StandardError)
Instance Method Summary collapse
-
#deserialize(event) ⇒ Object
Decrypts the given event’s subset of data.
-
#serialize(event) ⇒ Object
Encrypts the given event’s subset of data.
Instance Method Details
#deserialize(event) ⇒ Object
Decrypts the given event’s subset of data. General Event instance with encrypted data
-
#data- hash with encrypted values. -
encryption_metadata - hash with information which data to encrypt and which key should be used as an identifier.
Returns: Specific event class with all data decrypted
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/event_store_client/mapper/encrypted.rb', line 52 def deserialize(event) = serializer.deserialize(event.) encryption_schema = serializer.deserialize(event.)['encryption'] decrypted_data = EventStoreClient::DataDecryptor.new( data: serializer.deserialize(event.data), schema: encryption_schema, repository: key_repository ).call event_class = begin Object.const_get(event.type) rescue NameError EventStoreClient::DeserializedEvent end event_class.new( id: event.id, type: event.type, title: event.title, data: decrypted_data, metadata: ) end |
#serialize(event) ⇒ Object
Encrypts the given event’s subset of data. Accepts specific event class instance with:
-
#data- hash with non-encrypted values. -
encryption_schema - hash with information which data to encrypt and which key should be used as an identifier.
Returns: General Event instance with encrypted data
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/event_store_client/mapper/encrypted.rb', line 24 def serialize(event) encryption_schema = ( event.class.respond_to?(:encryption_schema) && event.class.encryption_schema ) encryptor = EventStoreClient::DataEncryptor.new( data: event.data, schema: encryption_schema, repository: key_repository ) encryptor.call EventStoreClient::Event.new( data: serializer.serialize(encryptor.encrypted_data), metadata: serializer.serialize( event..merge(encryption: encryptor.) ), type: event.class.to_s ) end |