Class: SafeCabinet
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SafeCabinet
- Defined in:
- app/models/safe_cabinet.rb
Constant Summary collapse
- SAFE_KEYS_DIR =
File.join(RAILS_ROOT,'config', 'safe_keys')
Instance Method Summary collapse
- #data ⇒ Object
- #lock_for(name) ⇒ Object
- #lockdown ⇒ Object
-
#options ⇒ Object
Instance Methods ::::::::::::::::::::::::::::::::::::::::::::::::.
- #read_data(pass) ⇒ Object
Instance Method Details
#data ⇒ Object
32 33 34 |
# File 'app/models/safe_cabinet.rb', line 32 def data lock_for("data") end |
#lock_for(name) ⇒ Object
46 47 48 49 50 |
# File 'app/models/safe_cabinet.rb', line 46 def lock_for name [name] = .merge(:key_pair => File.join(SAFE_KEYS_DIR, self.encryptable_type.to_s.tableize, self.encryptable_id.to_s, "keypair.pem")) @_locks ||= {} @_locks[name] ||= Lock.new(name, self, self.class.[name]) end |
#lockdown ⇒ Object
36 37 38 |
# File 'app/models/safe_cabinet.rb', line 36 def lockdown self.data = lock_for("data").encrypt self[:data] end |
#options ⇒ Object
- Instance Methods ::::::::::::::::::::::::::::::::::::::::::::::
23 24 25 26 27 28 29 30 |
# File 'app/models/safe_cabinet.rb', line 23 def @options ||= { :base64 => false, :symmetric => :always, :padding => OpenSSL::PKey::RSA::PKCS1_PADDING, :symmetric_cipher => 'aes-256-cbc' } end |
#read_data(pass) ⇒ Object
40 41 42 43 44 |
# File 'app/models/safe_cabinet.rb', line 40 def read_data(pass) self.data.decrypt pass rescue OpenSSL::PKey::RSAError nil end |