Sha256: 994de133913230a844e5567366d1e9ca14593454c6a114c43acf5cacf27a3328

Contents?: true

Size: 977 Bytes

Versions: 1

Compression:

Stored size: 977 Bytes

Contents

class Lockbox
  class Utils
    def self.build_box(context, options, table, attribute)
      options = options.except(:attribute, :encrypted_attribute, :migrating, :attached)
      options.each do |k, v|
        if v.is_a?(Proc)
          options[k] = context.instance_exec(&v) if v.respond_to?(:call)
        elsif v.is_a?(Symbol)
          options[k] = context.send(v)
        end
      end

      unless options[:key] || options[:encryption_key] || options[:decryption_key]
        options[:key] = Lockbox.attribute_key(table: table, attribute: attribute, master_key: options.delete(:master_key))
      end

      Lockbox.new(options)
    end

    def self.encrypted_options(record, name)
      record.class.respond_to?(:lockbox_attachments) && record.class.lockbox_attachments[name.to_sym]
    end

    def self.decode_key(key)
      if key.encoding != Encoding::BINARY && key =~ /\A[0-9a-f]{64,128}\z/i
        key = [key].pack("H*")
      end
      key
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lockbox-0.2.0 lib/lockbox/utils.rb