Skip to content

Commit

Permalink
Switch hash from MD5 to SHA256
Browse files Browse the repository at this point in the history
On FIPS-compliant systems (http://en.wikipedia.org/wiki/FIPS_140), MD5
cannot be used. Switch to SHA256 instead.

However, this change does not keep backward compatibility with systems
with already-installed Thor recipes.

Closes #287
  • Loading branch information
stanhu committed May 3, 2022
1 parent ab3b5be commit 0c01a18
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/thor/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative "group"

require "yaml"
require "digest/md5"
require "digest/sha2"
require "pathname"

class Thor::Runner < Thor #:nodoc: # rubocop:disable ClassLength
Expand Down Expand Up @@ -91,7 +91,7 @@ def install(name) # rubocop:disable MethodLength
end

thor_yaml[as] = {
:filename => Digest::MD5.hexdigest(name + as),
:filename => Digest::SHA256.hexdigest(name + as),
:location => location,
:namespaces => Thor::Util.namespaces_in_content(contents, base)
}
Expand Down
2 changes: 1 addition & 1 deletion spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def when_no_thorfiles_exist
allow(FileUtils).to receive(:touch)
allow(Thor::LineEditor).to receive(:readline).and_return("Y")

path = File.join(Thor::Util.thor_root, Digest::MD5.hexdigest(@location + "random"))
path = File.join(Thor::Util.thor_root, Digest::SHA256.hexdigest(@location + "random"))
expect(File).to receive(:open).with(path, "w")
end

Expand Down

0 comments on commit 0c01a18

Please sign in to comment.