summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/tfa/secure_proxy.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/tfa/secure_proxy.rb b/lib/tfa/secure_proxy.rb
index aadde0d..8f4fffe 100644
--- a/lib/tfa/secure_proxy.rb
+++ b/lib/tfa/secure_proxy.rb
@@ -42,9 +42,21 @@ module TFA
super unless @original.respond_to?(name)
was_encrypted = encrypted?
- decrypt! if was_encrypted
+ if was_encrypted
+ encrypted_content = IO.read(@original.path)
+ decrypt!
+ end
+ original_sha256 = Digest::SHA256.file(@original.path)
result = @original.public_send(name, *args, &block)
- encrypt! if was_encrypted
+ if was_encrypted
+ new_sha256 = Digest::SHA256.file(@original.path)
+
+ if original_sha256 == new_sha256
+ IO.write(@original.path, encrypted_content)
+ else
+ encrypt!
+ end
+ end
result
end