aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorJack Nagel2012-02-16 23:42:30 -0600
committerJack Nagel2012-02-16 23:47:39 -0600
commitf1dc59ca1169523353ea52b878dbce05ae3c9bae (patch)
tree1d4d58409989027ea744e864646598579fda8782 /Library/Homebrew
parent0ae1772b89ec52faa77108a3008402f2a1328ef7 (diff)
downloadbrew-f1dc59ca1169523353ea52b878dbce05ae3c9bae.tar.bz2
audit: make checksum warnings more clear
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library/Homebrew')
-rwxr-xr-xLibrary/Homebrew/cmd/audit.rb38
1 files changed, 20 insertions, 18 deletions
diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb
index fac083564..de7a9fd03 100755
--- a/Library/Homebrew/cmd/audit.rb
+++ b/Library/Homebrew/cmd/audit.rb
@@ -74,24 +74,6 @@ def audit_formula_text name, text
problems << " * \"#{$1}\" should be \"\#{#{$2}}\""
end
- # Empty checksums
- if text =~ /(md5|sha1|sha256)\s+(''|"")/
- problems << " * #{$1} is empty"
- end
-
- # Checksum sanity check
- if text =~ /md5\s+['"](.+)['"]/ and $1 != '#{md5}' and $1 !~ /[a-f0-9]{32}/
- problems << " * md5 contains invalid or incorrect number of characters"
- end
-
- if text =~ /sha1\s+['"](.+)['"]/ and $1 != '#{sha1}' and $1 !~ /[a-f0-9]{40}/
- problems << " * sha1 contains invalid or incorrect number of characters"
- end
-
- if text =~ /sha256\s+['"](.+)['"]/ and $1 != '#{sha256}' and $1 !~ /[a-f0-9]{64}/
- problems << " * sha256 contains invalid or incorrect number of characters"
- end
-
# Commented-out depends_on
if text =~ /#\s*depends_on\s+(.+)\s*$/
problems << " * Commented-out dep #{$1}."
@@ -305,6 +287,26 @@ def audit_formula_instance f
problems += [' * invalid or missing version'] if f.version.to_s.empty?
+ %w[md5 sha1 sha256].each do |checksum|
+ hash = f.instance_variable_get("@#{checksum}")
+ next if hash.nil?
+ hash = hash.strip
+
+ len = case checksum
+ when 'md5' then 32
+ when 'sha1' then 40
+ when 'sha256' then 64
+ end
+
+ if hash.empty?
+ problems << " * #{checksum} is empty"
+ else
+ problems << " * #{checksum} should be #{len} characters" unless hash.length == len
+ problems << " * #{checksum} contains invalid characters" unless hash =~ /^[a-fA-F0-9]+$/
+ problems << " * #{checksum} should be lowercase" unless hash == hash.downcase
+ end
+ end
+
return problems
end