diff options
| author | Jack Nagel | 2012-02-16 23:42:30 -0600 |
|---|---|---|
| committer | Jack Nagel | 2012-02-16 23:47:39 -0600 |
| commit | f1dc59ca1169523353ea52b878dbce05ae3c9bae (patch) | |
| tree | 1d4d58409989027ea744e864646598579fda8782 /Library/Homebrew | |
| parent | 0ae1772b89ec52faa77108a3008402f2a1328ef7 (diff) | |
| download | brew-f1dc59ca1169523353ea52b878dbce05ae3c9bae.tar.bz2 | |
audit: make checksum warnings more clear
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library/Homebrew')
| -rwxr-xr-x | Library/Homebrew/cmd/audit.rb | 38 |
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 |
