/*
  This file is part of TALER
  Copyright (C) 2014-2026 Taler Systems SA

  TALER 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.

  TALER 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
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
/**
 * @file include/taler/exchange/post-management-keys.h
 * @brief C interface for POST /management/keys
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__POST_MANAGEMENT_KEYS_H
#define _TALER_EXCHANGE__POST_MANAGEMENT_KEYS_H

#include <taler/exchange/common.h>


/**
 * @brief Public information about a signature on an exchange's online signing key
 */
struct TALER_EXCHANGE_SigningKeySignature
{
  /**
   * The signing public key
   */
  struct TALER_ExchangePublicKeyP exchange_pub;

  /**
   * Signature over this signing key by the exchange's master signature.
   * Of purpose #TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY
   */
  struct TALER_MasterSignatureP master_sig;

};


/**
 * @brief Public information about a signature on an exchange's denomination key
 */
struct TALER_EXCHANGE_DenominationKeySignature
{
  /**
   * The hash of the denomination's public key
   */
  struct TALER_DenominationHashP h_denom_pub;

  /**
   * Signature over this denomination key by the exchange's master signature.
   * Of purpose #TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY.
   */
  struct TALER_MasterSignatureP master_sig;

};


/**
 * Information needed for a POST /management/keys operation.
 */
struct TALER_EXCHANGE_ManagementPostKeysData
{
  /**
   * Array of the master signatures for the exchange's online signing keys.
   */
  struct TALER_EXCHANGE_SigningKeySignature *sign_sigs;

  /**
   * Array of the master signatures for the exchange's denomination keys.
   */
  struct TALER_EXCHANGE_DenominationKeySignature *denom_sigs;

  /**
   * Length of the @e sign_keys array (number of valid entries).
   */
  unsigned int num_sign_sigs;

  /**
   * Length of the @e denom_keys array.
   */
  unsigned int num_denom_sigs;
};


/**
 * Handle for an operation to POST /management/keys.
 */
struct TALER_EXCHANGE_PostManagementKeysHandle;


/**
 * Set up POST /management/keys operation.
 * Note that you must explicitly start the operation after setup.
 *
 * @param ctx the context
 * @param url HTTP base URL for the exchange
 * @param pkd signature data to POST
 * @return handle to operation, NULL on error
 */
struct TALER_EXCHANGE_PostManagementKeysHandle *
TALER_EXCHANGE_post_management_keys_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const struct TALER_EXCHANGE_ManagementPostKeysData *pkd);


/**
 * Response from a POST /management/keys request.
 */
struct TALER_EXCHANGE_PostManagementKeysResponse
{
  /**
   * HTTP response data
   */
  struct TALER_EXCHANGE_HttpResponse hr;
};


#ifndef TALER_EXCHANGE_POST_MANAGEMENT_KEYS_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_PostManagementKeysCallback.
 */
#define TALER_EXCHANGE_POST_MANAGEMENT_KEYS_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_POST_MANAGEMENT_KEYS_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * POST /management/keys request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_PostManagementKeysCallback)(
  TALER_EXCHANGE_POST_MANAGEMENT_KEYS_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_PostManagementKeysResponse *result);


/**
 * Start POST /management/keys operation.
 *
 * @param[in,out] pmkh operation to start
 * @param cb function to call with the exchange's result
 * @param cb_cls closure for @a cb
 * @return status code, #TALER_EC_NONE on success
 */
enum TALER_ErrorCode
TALER_EXCHANGE_post_management_keys_start (
  struct TALER_EXCHANGE_PostManagementKeysHandle *pmkh,
  TALER_EXCHANGE_PostManagementKeysCallback cb,
  TALER_EXCHANGE_POST_MANAGEMENT_KEYS_RESULT_CLOSURE *cb_cls);


/**
 * Cancel POST /management/keys operation.  This function must not be called
 * by clients after the TALER_EXCHANGE_PostManagementKeysCallback has been
 * invoked (as in those cases it'll be called internally by the implementation
 * already).
 *
 * @param[in] pmkh operation to cancel
 */
void
TALER_EXCHANGE_post_management_keys_cancel (
  struct TALER_EXCHANGE_PostManagementKeysHandle *pmkh);


#endif /* _TALER_EXCHANGE__POST_MANAGEMENT_KEYS_H */
