summaryrefslogtreecommitdiff
path: root/src/json
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-02-09 22:02:29 +0100
committerChristian Grothoff <christian@grothoff.org>2022-02-09 22:02:29 +0100
commit025922950dcf39700625e04be9f6037af67dddf5 (patch)
tree89b14956f470210e716b46dde8615221e51d1d72 /src/json
parente6598cfa1a81f6b040718933496436987d21194b (diff)
downloadexchange-025922950dcf39700625e04be9f6037af67dddf5.tar.gz
exchange-025922950dcf39700625e04be9f6037af67dddf5.tar.bz2
exchange-025922950dcf39700625e04be9f6037af67dddf5.zip
pass exchange values to /recoup
Diffstat (limited to 'src/json')
-rw-r--r--src/json/json_helper.c85
-rw-r--r--src/json/json_pack.c39
2 files changed, 123 insertions, 1 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index 4acac5061..c304bf22f 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -691,6 +691,91 @@ TALER_JSON_spec_blinded_planchet (const char *field,
/**
+ * Parse given JSON object to exchange withdraw values (/csr).
+ *
+ * @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_exchange_withdraw_values (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ struct TALER_ExchangeWithdrawValues *ewv = spec->ptr;
+ uint32_t cipher;
+ struct GNUNET_JSON_Specification dspec[] = {
+ GNUNET_JSON_spec_uint32 ("cipher",
+ &cipher),
+ GNUNET_JSON_spec_end ()
+ };
+ const char *emsg;
+ unsigned int eline;
+
+ (void) cls;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (root,
+ dspec,
+ &emsg,
+ &eline))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ ewv->cipher = (enum TALER_DenominationCipher) cipher;
+ switch (cipher)
+ {
+ case TALER_DENOMINATION_RSA:
+ return GNUNET_OK;
+ case TALER_DENOMINATION_CS:
+ {
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_fixed (
+ "r_pub_0",
+ &ewv->details.cs_values.r_pub_pair.r_pub[0],
+ sizeof (struct GNUNET_CRYPTO_CsRPublic)),
+ GNUNET_JSON_spec_fixed (
+ "r_pub_1",
+ &ewv->details.cs_values.r_pub_pair.r_pub[1],
+ sizeof (struct GNUNET_CRYPTO_CsRPublic)),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (root,
+ ispec,
+ &emsg,
+ &eline))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+ }
+ default:
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_exchange_withdraw_values (const char *field,
+ struct TALER_ExchangeWithdrawValues *
+ ewv)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_exchange_withdraw_values,
+ .field = field,
+ .ptr = ewv
+ };
+
+ return ret;
+}
+
+
+/**
* Closure for #parse_i18n_string.
*/
struct I18nContext
diff --git a/src/json/json_pack.c b/src/json/json_pack.c
index cf6504c06..043fa8463 100644
--- a/src/json/json_pack.c
+++ b/src/json/json_pack.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021, 2022 Taler Systems SA
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
@@ -121,6 +121,43 @@ TALER_JSON_pack_denom_sig (
struct GNUNET_JSON_PackSpec
+TALER_JSON_pack_exchange_withdraw_values (
+ const char *name,
+ const struct TALER_ExchangeWithdrawValues *ewv)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ };
+
+ switch (ewv->cipher)
+ {
+ case TALER_DENOMINATION_RSA:
+ ps.object = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("cipher",
+ TALER_DENOMINATION_RSA));
+ break;
+ case TALER_DENOMINATION_CS:
+ ps.object = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("cipher",
+ TALER_DENOMINATION_CS),
+ GNUNET_JSON_pack_data_varsize (
+ "r_pub_0",
+ &ewv->details.cs_values.r_pub_pair.r_pub[0],
+ sizeof(struct GNUNET_CRYPTO_CsRPublic)),
+ GNUNET_JSON_pack_data_varsize (
+ "r_pub_1",
+ &ewv->details.cs_values.r_pub_pair.r_pub[1],
+ sizeof(struct GNUNET_CRYPTO_CsRPublic))
+ );
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
TALER_JSON_pack_blinded_denom_sig (
const char *name,
const struct TALER_BlindedDenominationSignature *sig)