+################################################################################
+
+def check_hash_fields(what, manifest):
+ """
+ check_hash_fields ensures that there are no checksum fields in the
+ given dict that we do not know about.
+ """
+
+ rejmsg = []
+ hashes = map(lambda x: x[0], known_hashes)
+ for field in manifest:
+ if field.startswith("checksums-"):
+ hashname = field.split("-",1)[1]
+ if hashname not in hashes:
+ rejmsg.append("Unsupported checksum field for %s "\
+ "in %s" % (hashname, what))
+ return rejmsg
+
+################################################################################
+
+def _ensure_changes_hash(changes, format, version, files, hashname, hashfunc):
+ if format >= version:
+ # The version should contain the specified hash.
+ func = check_hash
+
+ # Import hashes from the changes
+ rejmsg = parse_checksums(".changes", files, changes, hashname)
+ if len(rejmsg) > 0:
+ return rejmsg
+ else:
+ # We need to calculate the hash because it can't possibly
+ # be in the file.
+ func = create_hash
+ return func(".changes", files, hashname, hashfunc)
+
+# We could add the orig which might be in the pool to the files dict to
+# access the checksums easily.
+
+def _ensure_dsc_hash(dsc, dsc_files, hashname, hashfunc):
+ """
+ ensure_dsc_hashes' task is to ensure that each and every *present* hash
+ in the dsc is correct, i.e. identical to the changes file and if necessary
+ the pool. The latter task is delegated to check_hash.
+ """
+
+ rejmsg = []
+ if not dsc.has_key('Checksums-%s' % (hashname,)):
+ return rejmsg
+ # Import hashes from the dsc
+ parse_checksums(".dsc", dsc_files, dsc, hashname)
+ # And check it...
+ rejmsg.extend(check_hash(".dsc", dsc_files, hashname, hashfunc))