Skip to content

Commit dfbe5fd

Browse files
authored
Use Diffcrypt::File as the storage for rails helper (#27)
The new cipher support wasn't available in rails monkey patch.
1 parent 7ec3d08 commit dfbe5fd

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Diff for: lib/diffcrypt/rails/encrypted_configuration.rb

+13-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
require 'active_support/core_ext/module/delegation'
1010
require 'active_support/core_ext/object/inclusion'
1111

12+
require 'diffcrypt/file'
13+
1214
module Diffcrypt
1315
module Rails
1416
class EncryptedConfiguration
@@ -24,15 +26,10 @@ def initialize(config_path:, key_path:, env_key:, raise_if_missing_key:)
2426
@content_path = Pathname.new(::File.absolute_path(config_path)).yield_self do |path|
2527
path.symlink? ? path.realpath : path
2628
end
29+
@diffcrypt_file = Diffcrypt::File.new(@content_path)
2730
@key_path = Pathname.new(key_path)
2831
@env_key = env_key
2932
@raise_if_missing_key = raise_if_missing_key
30-
31-
# TODO: Use Diffcrypt::File to ensure correct cipher is used
32-
@active_support_encryptor = ActiveSupport::MessageEncryptor.new(
33-
[key].pack('H*'),
34-
cipher: Encryptor::DEFAULT_CIPHER,
35-
)
3633
end
3734

3835
# Determines if file is using the diffable format, or still
@@ -108,9 +105,18 @@ def decrypt(contents)
108105
end
109106
end
110107

108+
# Rails applications with an existing credentials file, the inbuilt active support encryptor should be used
109+
# @return [ActiveSupport::MessageEncryptor]
110+
def active_support_encryptor
111+
@active_support_encryptor = ActiveSupport::MessageEncryptor.new(
112+
[key].pack('H*'),
113+
cipher: @diffcrypt_file.cipher,
114+
)
115+
end
116+
111117
# @return [Encryptor]
112118
def encryptor
113-
@encryptor ||= Encryptor.new key
119+
@encryptor ||= Encryptor.new key, cipher: @diffcrypt_file.cipher
114120
end
115121

116122
def read_env_key

0 commit comments

Comments
 (0)