From 1db139a7f3b74b2dc4135ab8b42d625415705d63 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 31 Jul 2021 22:50:16 +0200 Subject: -eliminating some legacy json_pack calls from Anastasis --- src/lib/anastasis_backup.c | 140 ++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 79 deletions(-) (limited to 'src/lib/anastasis_backup.c') diff --git a/src/lib/anastasis_backup.c b/src/lib/anastasis_backup.c index ea55e6a..d97bdae 100644 --- a/src/lib/anastasis_backup.c +++ b/src/lib/anastasis_backup.c @@ -134,29 +134,28 @@ ANASTASIS_truth_from_json (const json_t *json) json_t * ANASTASIS_truth_to_json (const struct ANASTASIS_Truth *t) { - return json_pack ( - "{s:o,s:o,s:o,s:o,s:o" - ",s:o,s:s,s:s,s:s,s:s?}", - "uuid", - GNUNET_JSON_from_data_auto (&t->uuid), - "key_share", - GNUNET_JSON_from_data_auto (&t->key_share), - "truth_key", - GNUNET_JSON_from_data_auto (&t->truth_key), - "salt", - GNUNET_JSON_from_data_auto (&t->salt), - "nonce", - GNUNET_JSON_from_data_auto (&t->nonce), - "provider_salt", - GNUNET_JSON_from_data_auto (&t->provider_salt), - "url", - t->url, - "type", - t->type, - "instructions", - t->instructions, - "mime_type", - t->mime_type); + return GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("uuid", + &t->uuid), + GNUNET_JSON_pack_data_auto ("key_share", + &t->key_share), + GNUNET_JSON_pack_data_auto ("truth_key", + &t->truth_key), + GNUNET_JSON_pack_data_auto ("salt", + &t->salt), + GNUNET_JSON_pack_data_auto ("nonce", + &t->nonce), + GNUNET_JSON_pack_data_auto ("provider_salt", + &t->provider_salt), + GNUNET_JSON_pack_string ("url", + t->url), + GNUNET_JSON_pack_string ("type", + t->type), + GNUNET_JSON_pack_string ("instructions", + t->instructions), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("mime_type", + t->mime_type))); } @@ -778,23 +777,16 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx, uuids, GNUNET_JSON_from_data_auto ( &policy->truths[b]->uuid))); - if (0 != - json_array_append_new ( - dec_policies, - json_pack ("{s:o, s:o, s:o}", - "master_key", - GNUNET_JSON_from_data_auto ( - &encrypted_master_keys[k]), - "uuids", - uuids, - "salt", - GNUNET_JSON_from_data_auto (&policy->salt)))) - { - GNUNET_break (0); - json_decref (dec_policies); - ANASTASIS_secret_share_cancel (ss); - return NULL; - } + GNUNET_assert (0 == + json_array_append_new ( + dec_policies, + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("master_key", + &encrypted_master_keys[k]), + GNUNET_JSON_pack_array_steal ("uuids", + uuids), + GNUNET_JSON_pack_data_auto ("salt", + &policy->salt)))); } esc_methods = json_array (); @@ -825,38 +817,24 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx, if (! unique) continue; - if (0 != - json_array_append_new ( - esc_methods, - json_pack ("{s:o," /* truth uuid */ - " s:s," /* provider url */ - " s:s," /* instructions */ - " s:o," /* truth key */ - " s:o," /* truth salt */ - " s:o," /* provider salt */ - " s:s}", /* escrow method */ - "uuid", - GNUNET_JSON_from_data_auto ( - &pt->uuid), - "url", - pt->url, - "instructions", - pt->instructions, - "truth_key", GNUNET_JSON_from_data_auto ( - &pt->truth_key), - "salt", GNUNET_JSON_from_data_auto ( - &pt->salt), - "provider_salt", GNUNET_JSON_from_data_auto ( - &pt->provider_salt), - "escrow_type", - pt->type))) - { - GNUNET_break (0); - json_decref (esc_methods); - json_decref (dec_policies); - ANASTASIS_secret_share_cancel (ss); - return NULL; - } + GNUNET_assert (0 == + json_array_append_new ( + esc_methods, + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("uuid", + &pt->uuid), + GNUNET_JSON_pack_string ("url", + pt->url), + GNUNET_JSON_pack_string ("instructions", + pt->instructions), + GNUNET_JSON_pack_data_auto ("truth_key", + &pt->truth_key), + GNUNET_JSON_pack_data_auto ("salt", + &pt->salt), + GNUNET_JSON_pack_data_auto ("provider_salt", + &pt->provider_salt), + GNUNET_JSON_pack_string ("escrow_type", + pt->type)))); } } @@ -869,13 +847,17 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx, int ret; uint32_t be_size; - recovery_document = json_pack ( - "{s:s?, s:o, s:o, s:o}", - "secret_name", secret_name, - "policies", dec_policies, - "escrow_methods", esc_methods, - "encrypted_core_secret", GNUNET_JSON_from_data (encrypted_core_secret, - core_secret_size)); + recovery_document = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("secret_name", + secret_name)), + GNUNET_JSON_pack_array_steal ("policies", + dec_policies), + GNUNET_JSON_pack_array_steal ("escrow_methods", + esc_methods), + GNUNET_JSON_pack_data_varsize ("encrypted_core_secret", + encrypted_core_secret, + core_secret_size)); GNUNET_assert (NULL != recovery_document); GNUNET_free (encrypted_core_secret); -- cgit v1.2.3