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
|
@version=Pathname.new(@url).version unless @version
|
||||||
validate_variable :version if @version
|
validate_variable :version if @version
|
||||||
@homepage=self.class.homepage unless @homepage
|
@homepage=self.class.homepage unless @homepage
|
||||||
@md5=self.class.md5 unless @md5
|
CHECKSUM_TYPES.each do |type|
|
||||||
@sha1=self.class.sha1 unless @sha1
|
if !instance_variable_defined?("@#{type}")
|
||||||
|
class_value = self.class.send(type)
|
||||||
|
instance_variable_set("@#{type}", class_value) if class_value
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# if the dir is there, but it's empty we consider it not installed
|
# if the dir is there, but it's empty we consider it not installed
|
||||||
@ -206,12 +210,15 @@ private
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
CHECKSUM_TYPES=[:md5, :sha1, :sha256].freeze
|
||||||
|
|
||||||
def verify_download_integrity fn
|
def verify_download_integrity fn
|
||||||
require 'digest'
|
require 'digest'
|
||||||
type='MD5'
|
type=CHECKSUM_TYPES.detect { |type| instance_variable_defined?("@#{type}") }
|
||||||
type='SHA1' if @sha1
|
type ||= :md5
|
||||||
supplied=eval "@#{type.downcase}"
|
supplied=instance_variable_get("@#{type}")
|
||||||
hash=eval("Digest::#{type}").hexdigest(fn.read)
|
type=type.to_s.upcase
|
||||||
|
hash=Digest.const_get(type).hexdigest(fn.read)
|
||||||
|
|
||||||
if supplied and not supplied.empty?
|
if supplied and not supplied.empty?
|
||||||
raise "#{type} mismatch: #{hash}" unless supplied.upcase == hash.upcase
|
raise "#{type} mismatch: #{hash}" unless supplied.upcase == hash.upcase
|
||||||
@ -271,7 +278,8 @@ private
|
|||||||
end
|
end
|
||||||
|
|
||||||
class <<self
|
class <<self
|
||||||
attr_reader :url, :version, :homepage, :md5, :sha1, :head
|
attr_reader :url, :version, :homepage, :head
|
||||||
|
attr_reader *CHECKSUM_TYPES
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -295,6 +295,26 @@ class BeerTasting <Test::Unit::TestCase
|
|||||||
nostdout { invalid_sha1.new.brew {} }
|
nostdout { invalid_sha1.new.brew {} }
|
||||||
end
|
end
|
||||||
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'
|
FOOBAR='foo-bar'
|
||||||
def test_formula_funcs
|
def test_formula_funcs
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user