From bd7e8543b3fba04a914f8f8c583652d6970d51db Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Sun, 20 Mar 2016 14:03:28 +0800 Subject: [PATCH] deprecate SHA1 --- Library/Homebrew/checksum.rb | 2 +- Library/Homebrew/compat.rb | 1 + Library/Homebrew/compat/sha1.rb | 35 +++++++++++++++++++++++++++++ Library/Homebrew/extend/pathname.rb | 6 ----- 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 Library/Homebrew/compat/sha1.rb diff --git a/Library/Homebrew/checksum.rb b/Library/Homebrew/checksum.rb index a4e38e0ada..1197609b1c 100644 --- a/Library/Homebrew/checksum.rb +++ b/Library/Homebrew/checksum.rb @@ -2,7 +2,7 @@ class Checksum attr_reader :hash_type, :hexdigest alias_method :to_s, :hexdigest - TYPES = [:sha1, :sha256] + TYPES = [:sha256] def initialize(hash_type, hexdigest) @hash_type = hash_type diff --git a/Library/Homebrew/compat.rb b/Library/Homebrew/compat.rb index 4ee137f1db..4bfe7174b1 100644 --- a/Library/Homebrew/compat.rb +++ b/Library/Homebrew/compat.rb @@ -5,6 +5,7 @@ require "compat/formula_specialties" require "compat/hardware" require "compat/macos" require "compat/md5" +require "compat/sha1" require "compat/requirements" require "compat/version" require "compat/download_strategy" diff --git a/Library/Homebrew/compat/sha1.rb b/Library/Homebrew/compat/sha1.rb new file mode 100644 index 0000000000..9d6fbc6e01 --- /dev/null +++ b/Library/Homebrew/compat/sha1.rb @@ -0,0 +1,35 @@ +class Formula + def self.sha1(val) + stable.sha1(val) + end +end + +class SoftwareSpec + def sha1(val) + @resource.sha1(val) + end +end + +class Resource + def sha1(val) + @checksum = Checksum.new(:sha1, val) + end +end + +class BottleSpecification + def sha1(val) + digest, tag = val.shift + collector[tag] = Checksum.new(:sha1, digest) + end +end + +class Pathname + def sha1 + require "digest/sha1" + opoo <<-EOS.undent + SHA1 support is deprecated and will be removed in a future version. + Please switch this formula to SHA256. + EOS + incremental_hash(Digest::SHA1) + end +end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 2f3fbc32f1..3f898fecb4 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -300,12 +300,6 @@ class Pathname digest.hexdigest end - # @private - def sha1 - require "digest/sha1" - incremental_hash(Digest::SHA1) - end - def sha256 require "digest/sha2" incremental_hash(Digest::SHA2)