- if format >= (1,8):
- hashes = [("sha1", apt_pkg.sha1sum),
- ("sha256", apt_pkg.sha256sum)]
- else:
- hashes = []
-
- for x in changes:
- if x.startswith("checksum-"):
- h = x.split("-",1)[1]
- if h not in dict(hashes):
- reject("Unsupported checksum field in .changes" % (h))
-
- for x in dsc:
- if x.startswith("checksum-"):
- h = x.split("-",1)[1]
- if h not in dict(hashes):
- reject("Unsupported checksum field in .dsc" % (h))
-
- for h,f in hashes:
- try:
- fs = daklib.utils.build_file_list(changes, 0, "checksums-%s" % h, h)
- check_hash(".changes %s" % (h), fs, h, f, files)
- except daklib.utils.no_files_exc:
- reject("No Checksums-%s: field in .changes file" % (h))
-
- if "source" not in changes["architecture"]: continue
-
- try:
- fs = daklib.utils.build_file_list(dsc, 1, "checksums-%s" % h, h)
- check_hash(".dsc %s" % (h), fs, h, f, dsc_files)
- except daklib.utils.no_files_exc:
- reject("No Checksums-%s: field in .changes file" % (h))
-
-################################################################################
-
-def check_hash (where, files, key, testfn, basedict = None):
- if basedict:
- for file in basedict.keys():
- if file not in files:
- reject("%s: no %s checksum" % (file, key))
-
- for file in files.keys():
- if basedict and file not in basedict:
- reject("%s: extraneous entry in %s checksums" % (file, key))
-
- try:
- file_handle = daklib.utils.open_file(file)
- except daklib.utils.cant_open_exc:
- continue
-
- # Check hash
- if testfn(file_handle) != files[file][key]:
- reject("%s: %s check failed." % (file, key))
- file_handle.close()
- # Check size
- actual_size = os.stat(file)[stat.ST_SIZE]
- size = int(files[file]["size"])
- if size != actual_size:
- reject("%s: actual file size (%s) does not match size (%s) in %s"
- % (file, actual_size, size, where))