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

Classes: Decryptor, Encryptor, KeyDerivator, Payload

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rom/encrypted_attribute.rb', line 19

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

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

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

  [writer_type, reader_type]
end