diff options
| author | Étienne Barrié | 2009-09-07 16:10:50 +0200 |
|---|---|---|
| committer | Étienne Barrié | 2009-09-07 16:10:50 +0200 |
| commit | 3809c0b4190850d54ba64248ade6d4737067c710 (patch) | |
| tree | be19be81cb40ca5b3d2ec83f1009526635f31962 /Library | |
| parent | b2e12c4517e36a8efa8d5cceac7b256d9cad7f6b (diff) | |
| download | brew-3809c0b4190850d54ba64248ade6d4737067c710.tar.bz2 | |
Add support for SHA256
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/formula.rb | 22 | ||||
| -rwxr-xr-x | Library/Homebrew/unittest.rb | 20 |
2 files changed, 35 insertions, 7 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 55293ca80..a6be9ea9b 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -54,8 +54,12 @@ class Formula @version=Pathname.new(@url).version unless @version validate_variable :version if @version @homepage=self.class.homepage unless @homepage - @md5=self.class.md5 unless @md5 - @sha1=self.class.sha1 unless @sha1 + CHECKSUM_TYPES.each do |type| + if !instance_variable_defined?("@#{type}") + class_value = self.class.send(type) + instance_variable_set("@#{type}", class_value) if class_value + end + end end # if the dir is there, but it's empty we consider it not installed @@ -206,12 +210,15 @@ private end end + CHECKSUM_TYPES=[:md5, :sha1, :sha256].freeze + def verify_download_integrity fn require 'digest' - type='MD5' - type='SHA1' if @sha1 - supplied=eval "@#{type.downcase}" - hash=eval("Digest::#{type}").hexdigest(fn.read) + type=CHECKSUM_TYPES.detect { |type| instance_variable_defined?("@#{type}") } + type ||= :md5 + supplied=instance_variable_get("@#{type}") + type=type.to_s.upcase + hash=Digest.const_get(type).hexdigest(fn.read) if supplied and not supplied.empty? raise "#{type} mismatch: #{hash}" unless supplied.upcase == hash.upcase @@ -271,7 +278,8 @@ private end class <<self - attr_reader :url, :version, :homepage, :md5, :sha1, :head + attr_reader :url, :version, :homepage, :head + attr_reader *CHECKSUM_TYPES end end diff --git a/Library/Homebrew/unittest.rb b/Library/Homebrew/unittest.rb index 9cdf46cc8..ba93e33ec 100755 --- a/Library/Homebrew/unittest.rb +++ b/Library/Homebrew/unittest.rb @@ -295,6 +295,26 @@ class BeerTasting <Test::Unit::TestCase nostdout { invalid_sha1.new.brew {} } end end + + def test_sha256 + valid_sha256 = Class.new(TestBall) do + @sha256='ccbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8' + end + + assert_nothing_raised do + nostdout { valid_sha256.new.brew {} } + end + end + + def test_badsha256 + invalid_sha256 = Class.new(TestBall) do + @sha256='dcbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8' + end + + assert_raises RuntimeError do + nostdout { invalid_sha256.new.brew {} } + end + end FOOBAR='foo-bar' def test_formula_funcs |
