class DoorMat::AttrAsymmetricStore::AttrAsymmetricStoreWrapper
Public Class Methods
new(attribute, actor_column)
click to toggle source
# File lib/door_mat/attr_asymmetric_store.rb, line 5 def initialize(attribute, actor_column) @attribute = attribute @actor_column = actor_column end
Public Instance Methods
after_find(record)
click to toggle source
# File lib/door_mat/attr_asymmetric_store.rb, line 10 def after_find(record) return if DoorMat::Crypto.current_skip_crypto_callback.skip? # leave attribute as-is if blank or the actor is not set encrypted_attribute = record.send("#{@attribute}") actor = record.send("#{@actor_column}") return if encrypted_attribute.blank? || actor.blank? clear_attribute = nil DoorMat::Session.current_session.autoload_sesion_for(actor) DoorMat::Session.current_session.with_session_for_actor(actor) do |session| clear_attribute = actor.decrypt_shared_key(encrypted_attribute, session) end if clear_attribute.nil? clear_attribute = '[ENCRYPTED SHARED KEY]' end record.send("#{@attribute}=", clear_attribute) DoorMat.configuration.logger.debug "DEBUG: Decrypt #{@attribute}: #{encrypted_attribute} -> #{clear_attribute}" if Rails.env.development? end
around_save(record) { || ... }
click to toggle source
# File lib/door_mat/attr_asymmetric_store.rb, line 33 def around_save(record) return yield if DoorMat::Crypto.current_skip_crypto_callback.skip? clear_attribute = record.send("#{@attribute}") actor = record.send("#{@actor_column}") # leave attribute as-is if blank or the actor is not set if clear_attribute.blank? || actor.blank? yield else encrypted_attribute = actor.encrypt_shared_key(clear_attribute) DoorMat.configuration.logger.debug "DEBUG: Encrypt #{@attribute}: #{clear_attribute} -> #{encrypted_attribute}" if Rails.env.development? record.send("#{@attribute}=", encrypted_attribute) yield record.send("#{@attribute}=", clear_attribute) DoorMat.configuration.logger.debug "DEBUG: Decrypt #{@attribute}: #{encrypted_attribute} -> #{clear_attribute}" if Rails.env.development? end end