diff options
| author | mo <mo.khan@gmail.com> | 2018-02-11 13:49:07 -0700 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2018-02-11 13:49:07 -0700 |
| commit | e8053cc6ff0921750d9818c54ac32468a8ab1516 (patch) | |
| tree | a18d9ff79fa9ae123c8f94ce5e42060c3685cf41 | |
| parent | 97eba5178fadec9c59cf091452a8184dc4132cd1 (diff) | |
save original encrypted version if there are no changes.
| -rw-r--r-- | lib/tfa/secure_proxy.rb | 16 |
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 |
