better api for parsing a denomination group

This commit is contained in:
Özgür Kesim 2022-06-27 10:36:13 +02:00
parent a6544069f9
commit 5633ad5a26
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
4 changed files with 12 additions and 10 deletions

View File

@ -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);

View File

@ -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);
/**

View File

@ -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;
}

View File

@ -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 ==