diff --git a/lib/i18n/backend/cache.rb b/lib/i18n/backend/cache.rb index 41b58fc2..40c18d65 100644 --- a/lib/i18n/backend/cache.rb +++ b/lib/i18n/backend/cache.rb @@ -17,11 +17,11 @@ # # The cache_key implementation by default assumes you pass values that return # a valid key from #hash (see -# http://www.ruby-doc.org/core/classes/Object.html#M000337). However, you can +# https://www.ruby-doc.org/core/classes/Object.html#M000337). However, you can # configure your own digest method via which responds to #hexdigest (see -# http://ruby-doc.org/stdlib/libdoc/digest/rdoc/index.html): +# https://ruby-doc.org/stdlib/libdoc/openssl/rdoc/OpenSSL/Digest.html): # -# I18n.cache_key_digest = Digest::MD5.new +# I18n.cache_key_digest = OpenSSL::Digest::SHA256.new # # If you use a lambda as a default value in your translation like this: # diff --git a/lib/i18n/backend/cache_file.rb b/lib/i18n/backend/cache_file.rb index 4dafb3e6..0c5e1922 100644 --- a/lib/i18n/backend/cache_file.rb +++ b/lib/i18n/backend/cache_file.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'digest/sha2' +require 'openssl' module I18n module Backend @@ -19,7 +19,7 @@ def load_file(filename) key = I18n::Backend::Flatten.escape_default_separator(normalized_path(filename)) old_mtime, old_digest = initialized && lookup(:i18n, key, :load_file) return if (mtime = File.mtime(filename).to_i) == old_mtime || - (digest = Digest::SHA2.file(filename).hexdigest) == old_digest + (digest = OpenSSL::Digest::SHA256.file(filename).hexdigest) == old_digest super store_translations(:i18n, load_file: { key => [mtime, digest] }) end diff --git a/test/backend/cache_test.rb b/test/backend/cache_test.rb index a14a0a4c..bd2efbce 100644 --- a/test/backend/cache_test.rb +++ b/test/backend/cache_test.rb @@ -1,5 +1,5 @@ require 'test_helper' -require 'digest/md5' +require 'openssl' begin require 'active_support' @@ -74,11 +74,11 @@ def teardown end test "cache_key uses configured digest method" do - md5 = Digest::MD5.new + digest = OpenSSL::Digest::SHA256.new options = { :bar => 1 } options_hash = options.inspect - with_cache_key_digest(md5) do - assert_equal "i18n//en/#{md5.hexdigest(:foo.to_s)}/#{md5.hexdigest(options_hash)}", I18n.backend.send(:cache_key, :en, :foo, options) + with_cache_key_digest(digest) do + assert_equal "i18n//en/#{digest.hexdigest(:foo.to_s)}/#{digest.hexdigest(options_hash)}", I18n.backend.send(:cache_key, :en, :foo, options) end end