summaryrefslogtreecommitdiff
path: root/src/json
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-10-31 17:56:56 +0100
committerChristian Grothoff <christian@grothoff.org>2021-10-31 17:56:56 +0100
commit3eae999efc0cb923aebd2bf7214c5f4093217d4f (patch)
tree9581fa718e127a79779ee1a095d4e017549f2b5e /src/json
parentde8e0907aadecf4f97c0eb8230217751f3fd44a1 (diff)
downloadexchange-3eae999efc0cb923aebd2bf7214c5f4093217d4f.tar.gz
exchange-3eae999efc0cb923aebd2bf7214c5f4093217d4f.tar.bz2
exchange-3eae999efc0cb923aebd2bf7214c5f4093217d4f.zip
distinguish between blind and non-blind denomination signatures
Diffstat (limited to 'src/json')
-rw-r--r--src/json/json_helper.c98
-rw-r--r--src/json/json_pack.c26
2 files changed, 122 insertions, 2 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index d509f4eff..1684e7f35 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -433,7 +433,7 @@ TALER_JSON_spec_relative_time (const char *name,
* @param[out] spec where to write the data
* @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
*/
-static int
+static enum GNUNET_GenericReturnValue
parse_denom_pub (void *cls,
json_t *root,
struct GNUNET_JSON_Specification *spec)
@@ -528,7 +528,7 @@ TALER_JSON_spec_denom_pub (const char *field,
* @param[out] spec where to write the data
* @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
*/
-static int
+static enum GNUNET_GenericReturnValue
parse_denom_sig (void *cls,
json_t *root,
struct GNUNET_JSON_Specification *spec)
@@ -614,6 +614,100 @@ TALER_JSON_spec_denom_sig (const char *field,
/**
+ * Parse given JSON object to blinded denomination signature.
+ *
+ * @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_blinded_denom_sig (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ struct TALER_BlindedDenominationSignature *denom_sig = 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;
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (root,
+ dspec,
+ &emsg,
+ &eline))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ denom_sig->cipher = (enum TALER_DenominationCipher) cipher;
+ switch (denom_sig->cipher)
+ {
+ case TALER_DENOMINATION_RSA:
+ {
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_rsa_signature (
+ "blinded_rsa_signature",
+ &denom_sig->details.blinded_rsa_signature),
+ 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;
+ }
+}
+
+
+/**
+ * Cleanup data left from parsing denomination public key.
+ *
+ * @param cls closure, NULL
+ * @param[out] spec where to free the data
+ */
+static void
+clean_blinded_denom_sig (void *cls,
+ struct GNUNET_JSON_Specification *spec)
+{
+ struct TALER_BlindedDenominationSignature *denom_sig = spec->ptr;
+
+ TALER_blinded_denom_sig_free (denom_sig);
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_blinded_denom_sig (
+ const char *field,
+ struct TALER_BlindedDenominationSignature *sig)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_blinded_denom_sig,
+ .cleaner = &clean_blinded_denom_sig,
+ .field = field,
+ .ptr = sig
+ };
+
+ return ret;
+}
+
+
+/**
* Closure for #parse_i18n_string.
*/
struct I18nContext
diff --git a/src/json/json_pack.c b/src/json/json_pack.c
index 0d1c95708..59e3afb77 100644
--- a/src/json/json_pack.c
+++ b/src/json/json_pack.c
@@ -142,6 +142,32 @@ TALER_JSON_pack_denom_sig (
struct GNUNET_JSON_PackSpec
+TALER_JSON_pack_blinded_denom_sig (
+ const char *name,
+ const struct TALER_BlindedDenominationSignature *sig)
+{
+ struct GNUNET_JSON_PackSpec ps = {
+ .field_name = name,
+ };
+
+ switch (sig->cipher)
+ {
+ case TALER_DENOMINATION_RSA:
+ ps.object
+ = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("cipher",
+ TALER_DENOMINATION_RSA),
+ GNUNET_JSON_pack_rsa_signature ("blinded_rsa_signature",
+ sig->details.blinded_rsa_signature));
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ return ps;
+}
+
+
+struct GNUNET_JSON_PackSpec
TALER_JSON_pack_amount (const char *name,
const struct TALER_Amount *amount)
{