#include <stdlib.h>

#include "test-utils.h"

struct input_proof {
  sigsum_size_t old_size;
  sigsum_size_t new_size;
  const char *old_root;
  const char *new_root;
  const char *const *consistency_path;
};

struct input_proof valid_input[] =
#include "consistency-valid.h"
  ;

struct input_proof invalid_input[] =
#include "consistency-invalid.h"
  ;

#define MAX_INCLUSION_PATH 10

static int
verify_input (const struct input_proof *input)
{
  struct sigsum_tree_head old_tree;
  struct sigsum_tree_head new_tree;
  struct sigsum_hash path[MAX_INCLUSION_PATH];
  unsigned path_length;

  hash_from_base64 (&old_tree.root_hash, input->old_root);
  hash_from_base64 (&new_tree.root_hash, input->new_root);
  old_tree.size = input->old_size;
  new_tree.size = input->new_size;
  path_length = path_from_base64 (MAX_INCLUSION_PATH, path, input->consistency_path);

  return sigsum_verify_consistency (&old_tree, &new_tree, path_length, path);
}

int
main (void)
{
  unsigned i;
  for (i = 0; i < sizeof (valid_input) / sizeof (valid_input[0]); i++)
    {
      if (!verify_input (&valid_input[i]))
	die ("test case %d: valid consistency proof was rejected", i);
    }

  for (i = 0; i < sizeof (invalid_input) / sizeof (invalid_input[0]); i++)
    {
      if (verify_input (&invalid_input[i]))
	die ("test case %d: invalid consistency proof was accepted", i);
    }

  return 0;
}
