lib/lockbox/model.rb in lockbox-0.3.2 vs lib/lockbox/model.rb in lockbox-0.3.3

- old
+ new

@@ -189,25 +189,31 @@ define_method("#{name}?") do send("#{encrypted_attribute}?") end define_method("#{name}=") do |message| - original_message = message - # decrypt first for dirty tracking # don't raise error if can't decrypt previous begin send(name) rescue Lockbox::DecryptionError + # this is expected for hybrid cryptography + warn "[lockbox] Decrypting previous value failed" unless options[:algorithm] == "hybrid" nil end - # set ciphertext + send("lockbox_direct_#{name}=", message) + + super(message) + end + + # separate method for setting directly + # used to skip blind indexes for key rotation + define_method("lockbox_direct_#{name}=") do |message| ciphertext = self.class.send(encrypt_method_name, message, context: self) send("#{encrypted_attribute}=", ciphertext) - - super(original_message) end + private :"lockbox_direct_#{name}=" define_method(name) do message = super() unless message