diff options
Diffstat (limited to 'src/json/json.c')
-rw-r--r-- | src/json/json.c | 107 |
1 files changed, 83 insertions, 24 deletions
diff --git a/src/json/json.c b/src/json/json.c index 4c2b82ccb..639bd530c 100644 --- a/src/json/json.c +++ b/src/json/json.c @@ -23,6 +23,7 @@ #include <gnunet/gnunet_util_lib.h> #include "taler_util.h" #include "taler_json_lib.h" +#include <unistr.h> /** @@ -97,7 +98,7 @@ dump_and_hash (const json_t *json, GNUNET_break (0); return GNUNET_SYSERR; } - len = strlen (wire_enc) + 1; + len = TALER_rfc8785encode (&wire_enc); if (NULL == salt) { GNUNET_CRYPTO_hash (wire_enc, @@ -325,7 +326,7 @@ forget (const json_t *in, enum GNUNET_GenericReturnValue TALER_JSON_contract_hash (const json_t *json, - struct GNUNET_HashCode *hc) + struct TALER_PrivateContractHashP *hc) { enum GNUNET_GenericReturnValue ret; json_t *cjson; @@ -339,7 +340,7 @@ TALER_JSON_contract_hash (const json_t *json, return ret; ret = dump_and_hash (cjson, NULL, - hc); + &hc->hash); json_decref (cjson); return ret; } @@ -532,7 +533,7 @@ TALER_JSON_contract_part_forget (json_t *json, /** - * Look over all of the values of a '$forgettable' object. Replace 'True' + * Loop over all of the values of a '$forgettable' object. Replace 'True' * values with proper random salts. Fails if any forgettable values are * neither 'True' nor valid salts (strings). * @@ -558,9 +559,14 @@ seed_forgettable (json_t *f) GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &sh, sizeof (sh)); - json_object_set_new (f, - key, - GNUNET_JSON_from_data_auto (&sh)); + if (0 != + json_object_set_new (f, + key, + GNUNET_JSON_from_data_auto (&sh))) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } continue; } GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -572,51 +578,64 @@ seed_forgettable (json_t *f) } -/** - * Take a given contract with "forgettable" fields marked - * but with 'True' instead of a real salt. Replaces all - * 'True' values with proper random salts. Fails if any - * forgettable markers are neither 'True' nor valid salts. - * - * @param[in,out] json JSON to transform - * @return #GNUNET_OK on success - */ enum GNUNET_GenericReturnValue -TALER_JSON_contract_seed_forgettable (json_t *json) +TALER_JSON_contract_seed_forgettable (const json_t *spec, + json_t *contract) { - if (json_is_object (json)) + if (json_is_object (spec)) { const char *key; json_t *val; - json_object_foreach (json, + json_object_foreach ((json_t *) spec, key, val) { + json_t *cval = json_object_get (contract, + key); + if (0 == strcmp ("$forgettable", key)) { + json_t *xval = json_deep_copy (val); + if (GNUNET_OK != - seed_forgettable (val)) + seed_forgettable (xval)) + { + json_decref (xval); return GNUNET_SYSERR; + } + GNUNET_assert (0 == + json_object_set_new (contract, + "$forgettable", + xval)); continue; } + if (NULL == cval) + continue; if (GNUNET_OK != - TALER_JSON_contract_seed_forgettable (val)) + TALER_JSON_contract_seed_forgettable (val, + cval)) return GNUNET_SYSERR; } } - if (json_is_array (json)) + if (json_is_array (spec)) { size_t index; json_t *val; - json_array_foreach (json, + json_array_foreach ((json_t *) spec, index, val) { + json_t *ival = json_array_get (contract, + index); + + if (NULL == ival) + continue; if (GNUNET_OK != - TALER_JSON_contract_seed_forgettable (val)) + TALER_JSON_contract_seed_forgettable (val, + ival)) return GNUNET_SYSERR; } } @@ -649,6 +668,7 @@ parse_path (json_t *obj, json_t *next_obj = NULL; char *next_dot; + GNUNET_assert (NULL != id); /* make stupid compiler happy */ if (NULL == next_id) { cb (cb_cls, @@ -837,4 +857,43 @@ TALER_JSON_get_error_code2 (const void *data, } +void +TALER_deposit_policy_hash (const json_t *policy, + struct TALER_ExtensionPolicyHashP *ech) +{ + GNUNET_assert (GNUNET_OK == + dump_and_hash (policy, + "taler-extensions-policy", + &ech->hash)); +} + + +char * +TALER_JSON_canonicalize (const json_t *input) +{ + char *wire_enc; + + if (NULL == (wire_enc = json_dumps (input, + JSON_ENCODE_ANY + | JSON_COMPACT + | JSON_SORT_KEYS))) + { + GNUNET_break (0); + return NULL; + } + TALER_rfc8785encode (&wire_enc); + return wire_enc; +} + + +enum GNUNET_GenericReturnValue +TALER_JSON_extensions_manifests_hash (const json_t *manifests, + struct TALER_ExtensionManifestsHashP *ech) +{ + return dump_and_hash (manifests, + "taler-extensions-manifests", + &ech->hash); +} + + /* End of json/json.c */ |