def ValidateChecksums(reference_checksums,
                      new_checksums,
                      allow_missing_projects=False):
  """Validates that reference_checksums and new_checksums match.

  Args:
    reference_checksums: a dict of reference checksums, mapping from a project
      name to a project checksum.
    new_checksums: a dict of checksums to be checked, mapping from a project
      name to a project checksum.
    allow_missing_projects:
      When True, reference_checksums may contain more projects than
        new_checksums. Projects missing from new_checksums are ignored.
      When False, new_checksums and reference_checksums must contain checksums
        for the same set of projects. If there is a project in
        reference_checksums, missing from new_checksums, ValidateChecksums
        will return False.

  Returns:
    True, if checksums match with regards to allow_missing_projects flag value.
    False, otherwise.
  """
  if not allow_missing_projects:
    if len(new_checksums) != len(reference_checksums):
      return False

  for proj, checksum in new_checksums.items():
    # We never computed a checksum for this project.
    if proj not in reference_checksums:
      return False
    # Checksum did not match.
    if reference_checksums[proj] != checksum:
      return False

  return True