Skip to content

Commit 9956f67

Browse files
authored
Fix undefined variable when accessing active support encryptor fallback (#31)
Related to: #29 creating new credentials fails with ``` 0.4.0/lib/diffcrypt/rails/encrypted_configuration.rb:102:in `decrypt': undefined method `decrypt_and_verify' for nil:NilClass (NoMethodError) ``` it seems `decrypt_and_verify` is never called, thus `@decrypt_and_verify` is not populated and hence results in this error. Not sure if ```ruby def active_support_encryptor @active_support_encryptor = ActiveSupport::MessageEncryptor.new( [key].pack('H*'), cipher: @diffcrypt_file.cipher, ) end ``` was intended to memorize the AS Message Encryptor instance, if so, we can drop in `@active_support_encryptor ||= ...`.
1 parent 818adb4 commit 9956f67

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ end
8585

8686
## Converting between ciphers
8787

88-
Sometimes you may want to rotate the cipher used on a file. You cab do this rogramtically using the ruby code above, or you can also chain the CLI commands like so:
88+
Sometimes you may want to rotate the cipher used on a file. You can do this programmatically using the ruby code above, or you can also chain the CLI commands like so:
8989

9090
```shell
9191
diffcrypt decrypt -k $(cat test/fixtures/aes-128-gcm.key) test/fixtures/example.yml.enc > test/fixtures/example.128.yml \

lib/diffcrypt/rails/encrypted_configuration.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def encrypt(contents, original_encrypted_contents = nil)
9999
# @return [String]
100100
def decrypt(contents)
101101
if contents.index('---').nil?
102-
@active_support_encryptor.decrypt_and_verify contents
102+
active_support_encryptor.decrypt_and_verify contents
103103
else
104104
encryptor.decrypt contents
105105
end
@@ -108,7 +108,7 @@ def decrypt(contents)
108108
# Rails applications with an existing credentials file, the inbuilt active support encryptor should be used
109109
# @return [ActiveSupport::MessageEncryptor]
110110
def active_support_encryptor
111-
@active_support_encryptor = ActiveSupport::MessageEncryptor.new(
111+
@active_support_encryptor ||= ActiveSupport::MessageEncryptor.new(
112112
[key].pack('H*'),
113113
cipher: @diffcrypt_file.cipher,
114114
)

0 commit comments

Comments
 (0)