module Sequel::Plugins::ColumnEncryption::InstanceMethods

Public Instance Methods

reencrypt() click to toggle source

Reencrypt the model if needed. Looks at all of the models encrypted columns and if any were encypted with older keys or a different format, reencrypt with the current key and format and save the object. Returns the object if reencryption was needed, or nil if reencryption was not needed.

# File lib/sequel/plugins/column_encryption.rb, line 707
def reencrypt
  do_save = false

  model.send(:column_encryption_metadata).each do |column, metadata|
    if (value = values[column]) && !value.start_with?(metadata.key_searcher.call)
      do_save = true
      values[column] = metadata.encryptor.call(metadata.decryptor.call(value))
    end
  end

  save if do_save
end