Class: EncryptedStore::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/encrypted_store/instance.rb

Instance Method Summary collapse

Instance Method Details

#config(&block) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/encrypted_store/instance.rb', line 3

def config(&block)
  (@__config ||= Config.new).tap { |config|
    if block_given?
      config.define(&block)
    end
  }
end

#decrypt_key(dek, primary = false) ⇒ Object



22
23
24
# File 'lib/encrypted_store/instance.rb', line 22

def decrypt_key(dek, primary = false)
  config.decrypt_key? ? config.decrypt_key.last.call(dek, primary) : dek
end

#encrypt_key(dek, primary = false) ⇒ Object



26
27
28
# File 'lib/encrypted_store/instance.rb', line 26

def encrypt_key(dek, primary = false)
  config.encrypt_key? ? config.encrypt_key.last.call(dek, primary) : dek
end

#preload_keys(amount = 12) ⇒ Object

Preloads the most recent ‘amount` keys.



17
18
19
20
# File 'lib/encrypted_store/instance.rb', line 17

def preload_keys(amount = 12)
  keys = EncryptedStore::ActiveRecord.preload_keys(amount)
  keys.each { |k| (@_decrypted_keys ||= {})[k.id] = k.decrypted_key }
end

#retrieve_dek(key_model, key_id) ⇒ Object



30
31
32
# File 'lib/encrypted_store/instance.rb', line 30

def retrieve_dek(key_model, key_id)
  (@_decrypted_keys ||= {})[key_id] ||= key_model.find(key_id).decrypted_key
end

#rotate_keysObject



11
12
13
# File 'lib/encrypted_store/instance.rb', line 11

def rotate_keys
  EncryptedStore::ActiveRecord.rotate_keys
end