#ifndef SIGSUM_PROOF_H_INCLUDED
#define SIGSUM_PROOF_H_INCLUDED

#include <stddef.h>

#include "merkle.h"
#include "policy.h"

#define SIGSUM_PROOF_MAX_PATH_LENGTH 63

struct sigsum_proof
{
  struct sigsum_hash log_key_hash;
  struct sigsum_hash submitter_key_hash;
  struct sigsum_signature leaf_signature;

  struct sigsum_tree_head tree_head;
  struct sigsum_signature log_signature;
  size_t num_cosignatures;
  const struct sigsum_cosignature *cosignatures;

  sigsum_size_t leaf_index;
  size_t path_length;
  const struct sigsum_hash *path;
};

bool
sigsum_proof_verify (const struct sigsum_hash *msg, const struct sigsum_proof *proof,
		     /* Submitters must be sorted by key hash. */
		     unsigned nsubmitters, const struct sigsum_key_with_hash *submitters,
		     const struct sigsum_policy *policy,
		     /* If non-NULL, a statically allocated
			error message is returned on
			failure. */
		     const char **err,
		     /* The scratch pointer must point to an area of size at least
			sigsum_policy_verify_tree_head_itch (policy), and suitably aligned
			for the bool type. (On most platforms, bool has same size and
			alignment as a char). */
		     void *scratch);

/* Initializes the proof struct, from the version=2 ASCII
   representation defined in
   https://git.glasklar.is/sigsum/core/sigsum-go/-/blob/main/doc/sigsum-proof.md.
   Allocates storage for cosignatures and inclusion path. Returns true
   on success, zero on failure. */
bool
sigsum_proof_parse (struct sigsum_proof *proof, size_t size, const char *data,
		    /* If non-NULL, a statically allocated error
		       message is returned on failure. */
		    const char **err);

/* Clears a proof struct initialized using sigsum_proof_parse, and
   deallocates storage. */
void
sigsum_proof_clear (struct sigsum_proof *proof);


#endif /* SIGSUM_PROOF_H_INCLUDED */
