Module: Slosilo::EncryptedAttributes

Defined in:
lib/slosilo/attr_encrypted.rb

Overview

we don’t trust the database to keep all backups safe from the prying eyes so we encrypt sensitive attributes before storing them

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.cipherObject



70
71
72
# File 'lib/slosilo/attr_encrypted.rb', line 70

def cipher
  @cipher ||= Slosilo::Symmetric.new
end

.decrypt(ctxt, opts = {}) ⇒ Object



61
62
63
64
# File 'lib/slosilo/attr_encrypted.rb', line 61

def decrypt ctxt, opts={}
  return nil unless ctxt
  cipher.decrypt ctxt, key: key, aad: opts[:aad]
end

.encrypt(value, opts = {}) ⇒ Object



56
57
58
59
# File 'lib/slosilo/attr_encrypted.rb', line 56

def encrypt value, opts={}
  return nil unless value
  cipher.encrypt value, key: key, aad: opts[:aad]
end

.included(base) ⇒ Object



51
52
53
# File 'lib/slosilo/attr_encrypted.rb', line 51

def self.included base
  base.extend ClassMethods
end

.keyObject



66
67
68
# File 'lib/slosilo/attr_encrypted.rb', line 66

def key
  Slosilo::encryption_key || (raise "Please set Slosilo::encryption_key")
end