9
9
require 'active_support/core_ext/module/delegation'
10
10
require 'active_support/core_ext/object/inclusion'
11
11
12
+ require 'diffcrypt/file'
13
+
12
14
module Diffcrypt
13
15
module Rails
14
16
class EncryptedConfiguration
@@ -24,15 +26,10 @@ def initialize(config_path:, key_path:, env_key:, raise_if_missing_key:)
24
26
@content_path = Pathname . new ( ::File . absolute_path ( config_path ) ) . yield_self do |path |
25
27
path . symlink? ? path . realpath : path
26
28
end
29
+ @diffcrypt_file = Diffcrypt ::File . new ( @content_path )
27
30
@key_path = Pathname . new ( key_path )
28
31
@env_key = env_key
29
32
@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
- )
36
33
end
37
34
38
35
# Determines if file is using the diffable format, or still
@@ -108,9 +105,18 @@ def decrypt(contents)
108
105
end
109
106
end
110
107
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
+
111
117
# @return [Encryptor]
112
118
def encryptor
113
- @encryptor ||= Encryptor . new key
119
+ @encryptor ||= Encryptor . new key , cipher : @diffcrypt_file . cipher
114
120
end
115
121
116
122
def read_env_key
0 commit comments