From e6e0cabf084ca4a333718b953bc0b48ac12e7356 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 27 Jan 2022 20:25:40 +0100 Subject: test and hopefully fix JSON canonicalization --- src/json/json.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/json/json.c') diff --git a/src/json/json.c b/src/json/json.c index bf3b2a0e..da447252 100644 --- a/src/json/json.c +++ b/src/json/json.c @@ -144,6 +144,9 @@ rfc8785encode (char **inp) if ( (1 == mbl) && (val <= 0x1F) ) { + /* Should not happen, as input is produced by + * JSON stringification */ + GNUNET_break (0); lowdump (&buf, val); } @@ -193,6 +196,12 @@ rfc8785encode (char **inp) } } break; + default: + mbl = 2; + GNUNET_buffer_write (&buf, + pos, + mbl); + break; } } else @@ -1009,6 +1018,24 @@ TALER_deposit_extension_hash (const json_t *extensions, } +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; + } + rfc8785encode (&wire_enc); + return wire_enc; +} + + enum GNUNET_GenericReturnValue TALER_JSON_extensions_config_hash (const json_t *config, struct TALER_ExtensionConfigHash *ech) -- cgit v1.2.3