From 0d1eced630f4ed05ad95fdbb4354fd428c9cdbf6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 19 Mar 2016 15:23:11 +0100 Subject: first refactoring of JSON logic to address #4150 and #4237 --- src/json/json.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/json/json.c (limited to 'src/json/json.c') diff --git a/src/json/json.c b/src/json/json.c new file mode 100644 index 00000000..1fbc59a7 --- /dev/null +++ b/src/json/json.c @@ -0,0 +1,53 @@ +/* + This file is part of TALER + Copyright (C) 2014, 2015, 2016 GNUnet e.V. + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, If not, see +*/ +/** + * @file json/json.c + * @brief helper functions for JSON processing using libjansson + * @author Sree Harsha Totakura + */ +#include "platform.h" +#include +#include "taler_util.h" +#include "taler_json_lib.h" + + +/** + * Hash a JSON for binary signing. + * + * @param[in] json some JSON value + * @param[out] hc resulting hash code + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error + */ +int +TALER_JSON_hash (json_t *json, + struct GNUNET_HashCode *hc) +{ + char *wire_enc; + size_t len; + + if (NULL == (wire_enc = json_dumps (json, + JSON_COMPACT | JSON_SORT_KEYS))) + return GNUNET_SYSERR; + len = strlen (wire_enc) + 1; + GNUNET_CRYPTO_hash (wire_enc, + len, + hc); + free (wire_enc); + return GNUNET_OK; +} + + +/* End of json/json.c */ -- cgit v1.2.3 From aee021aa3701213471dff9f378c58a0a0599f9b6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 6 Apr 2016 11:27:51 +0200 Subject: update ignore file, fix compiler warning --- .gitignore | 2 +- src/json/json.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/json/json.c') diff --git a/.gitignore b/.gitignore index 81be5b2f..ce73b4d2 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,7 @@ src/exchange-tools/taler-exchange-dbinit src/exchange-tools/taler-exchange-keycheck src/exchange-tools/taler-exchange-keyup src/exchange-tools/taler-exchange-reservemod -src/exchange-tools/taler-exchange-sepa +src/exchange-tools/taler-exchange-wire src/exchangedb/perf-exchangedb src/json/test_json src/wire/test_sepa_wireformat diff --git a/src/json/json.c b/src/json/json.c index 1fbc59a7..da9e8b9f 100644 --- a/src/json/json.c +++ b/src/json/json.c @@ -32,7 +32,7 @@ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -TALER_JSON_hash (json_t *json, +TALER_JSON_hash (const json_t *json, struct GNUNET_HashCode *hc) { char *wire_enc; -- cgit v1.2.3