1 # See support/scripts/check-package.txt before editing this file.
2 # The validity of the hashes itself is checked when building, so below check
3 # functions don't need to check for things already checked by running
4 # "make package-dirclean package-source".
8 from checkpackagebase import _CheckFunction
9 # Notice: ignore 'imported but unused' from pyflakes for check functions.
10 from checkpackagelib import ConsecutiveEmptyLines
11 from checkpackagelib import EmptyLastLine
12 from checkpackagelib import NewlineAtEof
13 from checkpackagelib import TrailingSpace
16 def _empty_line_or_comment(text):
17 return text.strip() == "" or text.startswith("#")
20 class HashFilename(_CheckFunction):
21 def check_line(self, lineno, text):
22 if _empty_line_or_comment(text):
30 return ["{}:{}: use filename without directory component"
31 " ({}#adding-packages-hash)"
32 .format(self.filename, lineno, self.url_to_manual),
36 class HashNumberOfFields(_CheckFunction):
37 def check_line(self, lineno, text):
38 if _empty_line_or_comment(text):
43 return ["{}:{}: expected three fields ({}#adding-packages-hash)"
44 .format(self.filename, lineno, self.url_to_manual),
48 class HashType(_CheckFunction):
49 len_of_hash = {"md5": 32, "sha1": 40, "sha224": 56, "sha256": 64,
50 "sha384": 96, "sha512": 128}
52 def check_line(self, lineno, text):
53 if _empty_line_or_comment(text):
60 htype, hexa = fields[:2]
63 if htype not in self.len_of_hash.keys():
64 return ["{}:{}: unexpected type of hash ({}#adding-packages-hash)"
65 .format(self.filename, lineno, self.url_to_manual),
67 if not re.match("^[0-9A-Fa-f]{%s}$" % self.len_of_hash[htype], hexa):
68 return ["{}:{}: hash size does not match type "
69 "({}#adding-packages-hash)"
70 .format(self.filename, lineno, self.url_to_manual),
72 "expected {} hex digits".format(self.len_of_hash[htype])]