/*
  This file is part of Anastasis
  Copyright (C) 2020-2022 Anastasis SARL

  Anastasis is free software; you can redistribute it and/or modify it under the
  terms of the GNU Affero General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License along with
  Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file include/anastasis/anastasis-database/do_do_verify_challenge_code.h
 * @brief Anastasis database: do verify challenge code
 * @author Christian Grothoff
 */
#ifndef ANASTASIS_DATABASE_DO_VERIFY_CHALLENGE_CODE_H
#define ANASTASIS_DATABASE_DO_VERIFY_CHALLENGE_CODE_H

#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_db_lib.h>
#include "anastasis_service.h"
#include "anastasis/anastasis-database/common.h"

/**
 * Verify the provided code with the code on the server.
 * Only the newest unexpired code issued for @a truth_uuid is answerable.
 * If the code matches the function will return with success, if the code
 * does not match, the retry counter will be decreased by one.  Once that
 * counter reaches zero the code is no longer answerable and
 * #ANASTASIS_DB_CODE_STATUS_RATE_LIMITED is returned until the next code
 * is issued.
 *
 * @param truth_uuid identification of the challenge which the code corresponds to
 * @param hashed_code code which the user provided and wants to verify
 * @param[out] code set to the original numeric code
 * @param[out] satisfied set to true if the challenge is set to satisfied
 * @return code validity status
 */
enum ANASTASIS_DB_CodeStatus
ANASTASIS_DB_do_verify_challenge_code (
  const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid,
  const struct GNUNET_HashCode *hashed_code,
  uint64_t *code,
  bool *satisfied);

#endif
