#include <stdlib.h>

#include "test-utils.h"

struct input_proof {
  const char *leaf_hash;
  sigsum_size_t leaf_index;
  sigsum_size_t tree_size;
  const char *root_hash;
  const char *const *inclusion_path;
};

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

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

#define MAX_INCLUSION_PATH 10

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

  hash_from_base64 (&leaf_hash, input->leaf_hash);
  hash_from_base64 (&tree_head.root_hash, input->root_hash);
  tree_head.size = input->tree_size;
  path_length = path_from_base64 (MAX_INCLUSION_PATH, path, input->inclusion_path);

  return sigsum_verify_inclusion (&leaf_hash, input->leaf_index, &tree_head, 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 inclusion 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 inclusion proof was accepted", i);
    }

  return 0;
}
