Module: ROM::EncryptedAttribute

Extended by:
Dry::Configurable
Defined in:
lib/rom/encrypted_attribute.rb,
lib/rom/encrypted_attribute/version.rb,
lib/rom/encrypted_attribute/decryptor.rb,
lib/rom/encrypted_attribute/encryptor.rb,
lib/rom/encrypted_attribute/key_derivator.rb

Defined Under Namespace

Modules: Types Classes: Decryptor, Encryptor, KeyDerivator, Payload

Constant Summary collapse

VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.define_encrypted_attribute_types(primary_key:, key_derivation_salt:, hash_digest_class: OpenSSL::Digest::SHA1, support_unencrypted_data: false) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rom/encrypted_attribute.rb', line 24

def self.define_encrypted_attribute_types(primary_key:, key_derivation_salt:, hash_digest_class: OpenSSL::Digest::SHA1, support_unencrypted_data: false)
  key_derivator = KeyDerivator.new(salt: key_derivation_salt, secret: primary_key,
    hash_digest_class: hash_digest_class)

  reader_type = Dry.Types.Constructor(Types::String.optional) do |value|
    ROM::EncryptedAttribute::Decryptor.new(derivator: key_derivator, support_unencrypted_data: support_unencrypted_data).decrypt(value)
  end

  writer_type = Dry.Types.Constructor(Types::String.optional) do |value|
    ROM::EncryptedAttribute::Encryptor.new(derivator: key_derivator).encrypt(value)
  end

  [writer_type, reader_type]
end