Sha256: e51c84afdc6e5f59262011588d0795bcf2d54ad5a3b298e196a862340233c566

Contents?: true

Size: 919 Bytes

Versions: 1

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

require_relative "encrypted_attribute/key_derivator"
require_relative "encrypted_attribute/decryptor"
require_relative "encrypted_attribute/encryptor"
require_relative "encrypted_attribute/version"

require "dry/types"

module ROM
  module EncryptedAttribute
    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-encrypted_attribute-0.0.3 lib/rom/encrypted_attribute.rb