aboutsummaryrefslogtreecommitdiff
path: root/src/json
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-06-05 00:25:56 +0200
committerChristian Grothoff <christian@grothoff.org>2022-06-05 00:25:56 +0200
commitefa0ca4ec18d636f9950cb03a192cf9a6484fadb (patch)
treef2d5c8697ffb235e1dc582965e1cbcf2a7d48d81 /src/json
parenta17781ba8d5f875b5150e524174c5f144aa6c0ba (diff)
-move econtract into sub-object with its own parser
Diffstat (limited to 'src/json')
-rw-r--r--src/json/json_helper.c76
-rw-r--r--src/json/json_pack.c34
2 files changed, 110 insertions, 0 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index 50d4705d5..2e5241b5a 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -235,6 +235,82 @@ TALER_JSON_spec_amount_any_nbo (const char *name,
/**
+ * Parse given JSON object to an encrypted contract.
+ *
+ * @param cls closure, NULL
+ * @param root the json object representing data
+ * @param[out] spec where to write the data
+ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
+ */
+static enum GNUNET_GenericReturnValue
+parse_econtract (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ struct TALER_EncryptedContract *econtract = spec->ptr;
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_varsize ("econtract",
+ &econtract->econtract,
+ &econtract->econtract_size),
+ GNUNET_JSON_spec_fixed_auto ("econtract_sig",
+ &econtract->econtract_sig),
+ GNUNET_JSON_spec_fixed_auto ("contract_pub",
+ &econtract->contract_pub),
+ GNUNET_JSON_spec_end ()
+ };
+ const char *emsg;
+ unsigned int eline;
+
+ (void) cls;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (root,
+ ispec,
+ &emsg,
+ &eline))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Cleanup data left from parsing encrypted contract.
+ *
+ * @param cls closure, NULL
+ * @param[out] spec where to free the data
+ */
+static void
+clean_econtract (void *cls,
+ struct GNUNET_JSON_Specification *spec)
+{
+ struct TALER_EncryptedContract *econtract = spec->ptr;
+
+ (void) cls;
+ GNUNET_free (econtract->econtract);
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_econtract (const char *name,
+ struct TALER_EncryptedContract *econtract)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_econtract,
+ .cleaner = &clean_econtract,
+ .cls = NULL,
+ .field = name,
+ .ptr = econtract,
+ .ptr_size = 0,
+ .size_ptr = NULL
+ };
+
+ return ret;
+}
+
+
+/**
* Parse given JSON object to denomination public key.
*
* @param cls closure, NULL
diff --git a/src/json/json_pack.c b/src/json/json_pack.c
index ad41eb955..090a8b96b 100644
--- a/src/json/json_pack.c
+++ b/src/json/json_pack.c
@@ -48,6 +48,30 @@ TALER_JSON_pack_time_abs_nbo_human (const char *name,
struct GNUNET_JSON_PackSpec
+TALER_JSON_pack_econtract (
+ const char *name,
+ const struct TALER_EncryptedContract *econtract)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ };
+
+ if (NULL == econtract)
+ return ps;
+ ps.object
+ = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_varsize ("econtract",
+ econtract->econtract,
+ econtract->econtract_size),
+ GNUNET_JSON_pack_data_auto ("econtract_sig",
+ &econtract->econtract_sig),
+ GNUNET_JSON_pack_data_auto ("contract_pub",
+ &econtract->contract_pub));
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
TALER_JSON_pack_denom_pub (
const char *name,
const struct TALER_DenominationPublicKey *pk)
@@ -56,6 +80,8 @@ TALER_JSON_pack_denom_pub (
.field_name = name,
};
+ if (NULL == pk)
+ return ps;
switch (pk->cipher)
{
case TALER_DENOMINATION_RSA:
@@ -95,6 +121,8 @@ TALER_JSON_pack_denom_sig (
.field_name = name,
};
+ if (NULL == sig)
+ return ps;
switch (sig->cipher)
{
case TALER_DENOMINATION_RSA:
@@ -129,6 +157,8 @@ TALER_JSON_pack_exchange_withdraw_values (
.field_name = name,
};
+ if (NULL == ewv)
+ return ps;
switch (ewv->cipher)
{
case TALER_DENOMINATION_RSA:
@@ -166,6 +196,8 @@ TALER_JSON_pack_blinded_denom_sig (
.field_name = name,
};
+ if (NULL == sig)
+ return ps;
switch (sig->cipher)
{
case TALER_DENOMINATION_RSA:
@@ -200,6 +232,8 @@ TALER_JSON_pack_blinded_planchet (
.field_name = name,
};
+ if (NULL == blinded_planchet)
+ return ps;
switch (blinded_planchet->cipher)
{
case TALER_DENOMINATION_RSA: