From 5633ad5a26d435c32b0df2b757950c416c6faaec Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Mon, 27 Jun 2022 10:36:13 +0200 Subject: better api for parsing a denomination group --- src/exchange/taler-exchange-httpd_keys.c | 2 ++ src/include/taler_json_lib.h | 8 +++----- src/json/json_helper.c | 8 +++++--- src/lib/exchange_api_handle.c | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c index ee80dcf9e..fcdfe119a 100644 --- a/src/exchange/taler-exchange-httpd_keys.c +++ b/src/exchange/taler-exchange-httpd_keys.c @@ -2190,6 +2190,8 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh) .age_mask = dk->meta.age_mask, }; + memset (&meta.hash, 0, sizeof(meta.hash)); + /* Search the group/JSON-blob for the key */ GNUNET_CRYPTO_hash (&meta, sizeof(meta), &key); diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h index 0b58b43d1..1300f8751 100644 --- a/src/include/taler_json_lib.h +++ b/src/include/taler_json_lib.h @@ -375,9 +375,6 @@ struct TALER_DenominationGroup struct TALER_DenomFeeSet fees; struct TALER_AgeMask age_mask; - // currency must be set prior to calling TALER_JSON_spec_denomination_group - const char *currency; - // hash is/should be the XOR of all SHA-512 hashes of the public keys in this // group struct GNUNET_HashCode hash; @@ -385,14 +382,15 @@ struct TALER_DenominationGroup /** * Generate a parser for a group of denominations. - * NOTE: group.currency MUST have been set prior to calling this function. * - * @param field name of the field, maybe NULL + * @param[in] field name of the field, maybe NULL + * @param[in] currency name of the currency * @param[out] group denomination group information * @return corresponding field spec */ struct GNUNET_JSON_Specification TALER_JSON_spec_denomination_group (const char *field, + const char *currency, struct TALER_DenominationGroup *group); /** diff --git a/src/json/json_helper.c b/src/json/json_helper.c index b29a49b3a..202caf6f1 100644 --- a/src/json/json_helper.c +++ b/src/json/json_helper.c @@ -250,16 +250,17 @@ parse_denomination_group (void *cls, { struct TALER_DenominationGroup *group = spec->ptr; const char *cipher; + const char *currency = cls; bool age_mask_missing = false; bool has_age_restricted_suffix = false; struct GNUNET_JSON_Specification gspec[] = { GNUNET_JSON_spec_string ("cipher", &cipher), TALER_JSON_spec_amount ("value", - group->currency, + currency, &group->value), TALER_JSON_SPEC_DENOM_FEES ("fee", - group->currency, + currency, &group->fees), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_uint32 ("age_mask", @@ -307,9 +308,11 @@ parse_denomination_group (void *cls, struct GNUNET_JSON_Specification TALER_JSON_spec_denomination_group (const char *name, + const char *currency, struct TALER_DenominationGroup *group) { struct GNUNET_JSON_Specification ret = { + .cls = (void *) currency, .parser = &parse_denomination_group, .cleaner = NULL, .field = name, @@ -318,7 +321,6 @@ TALER_JSON_spec_denomination_group (const char *name, .size_ptr = NULL, }; - return ret; } diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index c690c352e..f7865af7c 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -952,9 +952,9 @@ decode_keys_json (const json_t *resp_obj, // First, parse { cipher, fees, value, age_mask, hash } of the current // group. - struct TALER_DenominationGroup group = { .currency = currency }; + struct TALER_DenominationGroup group = {0}; struct GNUNET_JSON_Specification group_spec[] = { - TALER_JSON_spec_denomination_group (NULL, &group), + TALER_JSON_spec_denomination_group (NULL, currency, &group), GNUNET_JSON_spec_end () }; EXITIF (GNUNET_SYSERR == -- cgit v1.2.3