lib/symmetric_encryption/config.rb in symmetric-encryption-4.1.0.beta1 vs lib/symmetric_encryption/config.rb in symmetric-encryption-4.1.0

- old
+ new

@@ -51,12 +51,12 @@ # See: `.load!` for parameters. def initialize(file_name: nil, env: nil) env ||= defined?(Rails) ? Rails.env : ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development' unless file_name - root = defined?(Rails) ? Rails.root : '.' - file_name = + root = defined?(Rails) ? Rails.root : '.' + file_name = if (env_var = ENV['SYMMETRIC_ENCRYPTION_CONFIG']) File.expand_path(env_var) else File.join(root, 'config', 'symmetric-encryption.yml') end @@ -99,10 +99,11 @@ object.collect { |i| deep_symbolize_keys(i) } else object end end + private_class_method :deep_symbolize_keys # Iterate through the Hash symbolizing all keys. def self.deep_stringify_keys(object) case object @@ -117,32 +118,33 @@ object.collect { |i| deep_stringify_keys(i) } else object end end + private_class_method :deep_stringify_keys # Migrate old configuration format for this environment def self.migrate_old_formats!(config) # Inline single cipher before :ciphers unless config.key?(:ciphers) - inline_cipher = {} + inline_cipher = {} config.keys.each { |key| inline_cipher[key] = config.delete(key) } - config[:ciphers] = [inline_cipher] + config[:ciphers] = [inline_cipher] end # Copy Old :private_rsa_key into each ciphers config # Cipher.from_config replaces it with the RSA Kek if config[:private_rsa_key] - private_rsa_key = config.delete(:private_rsa_key) + private_rsa_key = config.delete(:private_rsa_key) config[:ciphers].each { |cipher| cipher[:private_rsa_key] = private_rsa_key } end # Old :cipher_name config[:ciphers].each do |cipher| if (old_key_name_cipher = cipher.delete(:cipher)) - cipher[:cipher_name] = old_key_name_cipher + cipher[:cipher_name] = old_key_name_cipher end # Only temporarily used during v4 Beta process cipher[:private_rsa_key] = cipher.delete(:key_encrypting_key) if cipher[:key_encrypting_key].is_a?(String) @@ -154,8 +156,9 @@ puts 'WARNING: :encrypted_key resolved to nil. Please see the migrated config file for the new option :key_env_var.' end end config end + private_class_method :migrate_old_formats! end end