Add support for SHA256
This commit is contained in:
parent
b2e12c4517
commit
3809c0b419
@ -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
|
||||
|
||||
|
||||
@ -296,6 +296,26 @@ class BeerTasting <Test::Unit::TestCase
|
||||
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
|
||||
classname=Formula.class(FOOBAR)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user