Class: Sequel::Plugins::ColumnEncryption::ColumnDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/plugins/column_encryption.rb

Overview

The object type yielded to blocks passed to the column method inside plugin :column_encryption blocks. This is used to configure custom per-column keys.

Direct Known Subclasses

DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeColumnDSL

Returns a new instance of ColumnDSL.


523
524
525
# File 'lib/sequel/plugins/column_encryption.rb', line 523

def initialize
  @keys = []
end

Instance Attribute Details

#keysObject (readonly)

An array of arrays for the data for the keys configured inside the block.


521
522
523
# File 'lib/sequel/plugins/column_encryption.rb', line 521

def keys
  @keys
end

Instance Method Details

#key(key_id, key, opts = OPTS) ⇒ Object

Verify that the key_id, key, and options are value.


528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/sequel/plugins/column_encryption.rb', line 528

def key(key_id, key, opts=OPTS)
  unless key_id.is_a?(Integer) && key_id >= 0 && key_id <= 255
    raise Error, "invalid key_id argument, must be integer between 0 and 255"
  end

  unless key.is_a?(String) && key.bytesize == 32
    raise Error, "invalid key argument, must be string with exactly 32 bytes"
  end

  if opts.has_key?(:padding)
    if padding = opts[:padding]
      unless padding.is_a?(Integer) && padding >= 1 && padding <= 120
        raise Error, "invalid :padding option, must be between 1 and 120"
      end
    end
  else
    padding = Cryptor::DEFAULT_PADDING
  end

  @keys << [key_id, key, opts[:auth_data].to_s, padding].freeze
end