-minor refactoring in age_withdraw-reveal

This commit is contained in:
Özgür Kesim 2023-03-06 21:36:14 +01:00
parent 6adc223028
commit 7521ff1cf4
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7

View File

@ -260,7 +260,7 @@ EXIT:
/** /**
* Check if the request belongs to an existing age-withdraw request. * Check if the request belongs to an existing age-withdraw request.
* If so, sets the age_withdraw object with the request data. * If so, sets the commitment object with the request data.
* Otherwise, it queues an appropriate MHD response. * Otherwise, it queues an appropriate MHD response.
* *
* @param connection The HTTP connection to the client * @param connection The HTTP connection to the client
@ -272,7 +272,7 @@ EXIT:
* GNUNET_SYSERROR if we did not find the request in the DB * GNUNET_SYSERROR if we did not find the request in the DB
*/ */
static enum GNUNET_GenericReturnValue static enum GNUNET_GenericReturnValue
retrieve_original_commitment ( find_original_commitment (
struct MHD_Connection *connection, struct MHD_Connection *connection,
const struct TALER_AgeWithdrawCommitmentHashP *h_commitment, const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
@ -319,7 +319,15 @@ retrieve_original_commitment (
/** /**
* TODO * Check if the given denomination is still or already valid, has not been
* revoked and supports age restriction.
*
* @param connection HTTP-connection to the client
* @param ksh The handle to the current state of (denomination) keys in the exchange
* @param denom_h Hash of the denomination key to check
* @param[out] dks On success, will contain the denomination key details
* @param[out] result On failure, an MHD-response will be qeued and result will be set to accordingly
* @return true on success (denomination valid), false otherwise
*/ */
static bool static bool
denomination_is_valid ( denomination_is_valid (
@ -379,20 +387,21 @@ denomination_is_valid (
return false; return false;
} }
/* Does the denomation support age restriction ? */
if (0 == dks->denom_pub.age_mask.bits) if (0 == dks->denom_pub.age_mask.bits)
{ {
/* This denomation does not support age restriction */
char msg[256] = {0}; char msg[256] = {0};
GNUNET_snprintf (msg, GNUNET_snprintf (msg,
sizeof(msg), sizeof(msg),
"denomination %s does not support age restriction", "denomination %s does not support age restriction",
GNUNET_h2s (&denom_h->hash)); GNUNET_h2s (&denom_h->hash));
*result = TALER_MHD_reply_with_error (connection, *result = TALER_MHD_reply_with_error (
MHD_HTTP_BAD_REQUEST, connection,
TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN, MHD_HTTP_BAD_REQUEST,
msg); TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN,
return GNUNET_SYSERR; msg);
return false;
} }
return true; return true;
@ -415,7 +424,7 @@ denomination_is_valid (
* GNUNET_SYSERR otherwise * GNUNET_SYSERR otherwise
*/ */
static enum GNUNET_GenericReturnValue static enum GNUNET_GenericReturnValue
all_denominations_valid ( are_denominations_valid (
struct MHD_Connection *connection, struct MHD_Connection *connection,
uint32_t len, uint32_t len,
const struct TALER_DenominationHashP *denoms_h, const struct TALER_DenominationHashP *denoms_h,
@ -544,24 +553,26 @@ TEH_handler_age_withdraw_reveal (
do { do {
/* Extract denominations, blinded and disclosed coins */ /* Extract denominations, blinded and disclosed coins */
if (GNUNET_OK != parse_age_withdraw_reveal_json (rc->connection, if (GNUNET_OK != parse_age_withdraw_reveal_json (
j_denoms_h, rc->connection,
j_coin_evs, j_denoms_h,
j_disclosed_coins, j_coin_evs,
&actx, j_disclosed_coins,
&result)) &actx,
&result))
break; break;
/* Find original commitment */ /* Find original commitment */
if (GNUNET_OK != retrieve_original_commitment (rc->connection, if (GNUNET_OK != find_original_commitment (
&actx.ach, rc->connection,
&actx.reserve_pub, &actx.ach,
&actx.commitment, &actx.reserve_pub,
&result)) &actx.commitment,
&result))
break; break;
/* Ensure validity of denoms and the sum of amounts and fees */ /* Ensure validity of denoms and the sum of amounts and fees */
if (GNUNET_OK != all_denominations_valid ( if (GNUNET_OK != are_denominations_valid (
rc->connection, rc->connection,
actx.num_coins, actx.num_coins,
actx.denoms_h, actx.denoms_h,