Class: Ribbon::EncryptedStore::Instance

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

Instance Method Summary collapse

Instance Method Details

#config(&block) ⇒ Object



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

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

#decrypt_key(dek, primary = false) ⇒ Object



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

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

#encrypt_key(dek, primary = false) ⇒ Object



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

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.



13
14
15
16
# File 'lib/ribbon/encrypted_store/instance.rb', line 13

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

#retrieve_dek(key_model, key_id) ⇒ Object



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

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