From 3809c0b4190850d54ba64248ade6d4737067c710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Mon, 7 Sep 2009 16:10:50 +0200 Subject: [PATCH] Add support for SHA256 --- Library/Homebrew/formula.rb | 22 +++++++++++++++------- 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 55293ca80a..a6be9ea9bf 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 <