lib/symmetric_encryption/generator.rb in symmetric-encryption-3.9.1 vs lib/symmetric_encryption/generator.rb in symmetric-encryption-4.0.0.beta3
- old
+ new
@@ -23,19 +23,20 @@
# Set the un-encrypted field
# Also updates the encrypted field with the encrypted value
# Freeze the decrypted field value so that it is not modified directly
def #{decrypted_name}=(value)
v = SymmetricEncryption::Coerce.coerce(value, :#{type})
- self.#{encrypted_name} = @stored_#{encrypted_name} = ::SymmetricEncryption.encrypt(v, #{random_iv}, #{compress}, :#{type})
+ return if (@#{decrypted_name} == v) && !v.nil? && !(v == '')
+ self.#{encrypted_name} = @stored_#{encrypted_name} = ::SymmetricEncryption.encrypt(v, random_iv: #{random_iv}, compress: #{compress}, type: :#{type})
@#{decrypted_name} = v.freeze
end
# Returns the decrypted value for the encrypted field
# The decrypted value is cached and is only decrypted if the encrypted value has changed
# If this method is not called, then the encrypted value is never decrypted
def #{decrypted_name}
if !defined?(@stored_#{encrypted_name}) || (@stored_#{encrypted_name} != self.#{encrypted_name})
- @#{decrypted_name} = ::SymmetricEncryption.decrypt(self.#{encrypted_name}, nil, :#{type}).freeze
+ @#{decrypted_name} = ::SymmetricEncryption.decrypt(self.#{encrypted_name}, type: :#{type}).freeze
@stored_#{encrypted_name} = self.#{encrypted_name}
end
@#{decrypted_name}
end