aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Blättler <blatc2@bfh.ch>2024-04-27 16:46:43 +0200
committerChristian Blättler <blatc2@bfh.ch>2024-04-27 16:46:43 +0200
commitd4f6ca72309f5400af20aa57905846fd3ac13949 (patch)
tree3db624111848219462d5ac0f0b434bddc1fdd2c5 /src
parent5ea7c067a0751ae3af6ecd770d1c932a5b98b8fd (diff)
downloadexchange-d4f6ca72309f5400af20aa57905846fd3ac13949.tar.xz
add json spec for token envelope
Diffstat (limited to 'src')
-rw-r--r--src/include/taler_crypto_lib.h2
-rw-r--r--src/include/taler_json_lib.h14
-rw-r--r--src/json/json_helper.c138
3 files changed, 28 insertions, 126 deletions
diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h
index e2f377448..5e5a15b71 100644
--- a/src/include/taler_crypto_lib.h
+++ b/src/include/taler_crypto_lib.h
@@ -2336,7 +2336,7 @@ struct TALER_TokenEnvelopeP
/**
* Blinded public key of the token.
*/
- struct GNUNET_CRYPTO_BlindedMessage blinded_pub;
+ struct GNUNET_CRYPTO_BlindedMessage *blinded_pub;
};
diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h
index 48175ec2b..17768c0e3 100644
--- a/src/include/taler_json_lib.h
+++ b/src/include/taler_json_lib.h
@@ -613,6 +613,20 @@ struct GNUNET_JSON_Specification
TALER_JSON_spec_token_issue_sig (const char *field,
struct TALER_TokenIssueSignatureP *sig);
+
+/**
+ * Generate line in parser specification for a
+ * token envelope.
+ *
+ * @param field name of the field
+ * @param[out] env the envelope to initialize
+ * @return corresponding field spec
+ */
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_token_envelope (const char *field,
+ struct TALER_TokenEnvelopeP *env);
+
+
/**
* Hash a JSON for binary signing.
*
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index ad5b8d5a3..40b9c78d5 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -534,7 +534,7 @@ TALER_JSON_spec_age_commitment (const char *name,
/**
* Parse given JSON object to token issue signature.
- * TODO: Exctract common between this and parse_denom_sig function to a helper.
+ * TODO: Exctract common code between this and parse_denom_sig function to a helper.
*
* @param cls closure, NULL
* @param root the json object representing data
@@ -661,6 +661,16 @@ TALER_JSON_spec_token_issue_sig (const char *field,
}
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_token_envelope (const char *field,
+ struct TALER_TokenEnvelopeP *env)
+{
+ env->blinded_pub = NULL;
+ return GNUNET_JSON_spec_blinded_message (field,
+ &env->blinded_pub);
+}
+
+
/**
* Parse given JSON object to denomination public key.
*
@@ -1148,135 +1158,13 @@ TALER_JSON_spec_blinded_denom_sig (
}
-/**
- * Parse given JSON object to blinded planchet.
- *
- * @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_planchet (void *cls,
- json_t *root,
- struct GNUNET_JSON_Specification *spec)
-{
- struct TALER_BlindedPlanchet *blinded_planchet = spec->ptr;
- struct GNUNET_CRYPTO_BlindedMessage *blinded_message;
- const char *cipher;
- struct GNUNET_JSON_Specification dspec[] = {
- GNUNET_JSON_spec_string ("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;
- }
- blinded_message = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
- blinded_message->rc = 1;
- blinded_message->cipher = string_to_cipher (cipher);
- switch (blinded_message->cipher)
- {
- case GNUNET_CRYPTO_BSA_INVALID:
- break;
- case GNUNET_CRYPTO_BSA_RSA:
- {
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_varsize (
- "rsa_blinded_planchet",
- &blinded_message->details.rsa_blinded_message.blinded_msg,
- &blinded_message->details.rsa_blinded_message.blinded_msg_size),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (root,
- ispec,
- &emsg,
- &eline))
- {
- GNUNET_break_op (0);
- GNUNET_free (blinded_message);
- return GNUNET_SYSERR;
- }
- blinded_planchet->blinded_message = blinded_message;
- return GNUNET_OK;
- }
- case GNUNET_CRYPTO_BSA_CS:
- {
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_fixed_auto (
- "cs_nonce",
- &blinded_message->details.cs_blinded_message.nonce),
- GNUNET_JSON_spec_fixed_auto (
- "cs_blinded_c0",
- &blinded_message->details.cs_blinded_message.c[0]),
- GNUNET_JSON_spec_fixed_auto (
- "cs_blinded_c1",
- &blinded_message->details.cs_blinded_message.c[1]),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (root,
- ispec,
- &emsg,
- &eline))
- {
- GNUNET_break_op (0);
- GNUNET_free (blinded_message);
- return GNUNET_SYSERR;
- }
- blinded_planchet->blinded_message = blinded_message;
- return GNUNET_OK;
- }
- }
- GNUNET_break_op (0);
- GNUNET_free (blinded_message);
- return GNUNET_SYSERR;
-}
-
-
-/**
- * Cleanup data left from parsing blinded planchet.
- *
- * @param cls closure, NULL
- * @param[out] spec where to free the data
- */
-static void
-clean_blinded_planchet (void *cls,
- struct GNUNET_JSON_Specification *spec)
-{
- struct TALER_BlindedPlanchet *blinded_planchet = spec->ptr;
-
- (void) cls;
- TALER_blinded_planchet_free (blinded_planchet);
-}
-
-
struct GNUNET_JSON_Specification
TALER_JSON_spec_blinded_planchet (const char *field,
struct TALER_BlindedPlanchet *blinded_planchet)
{
- struct GNUNET_JSON_Specification ret = {
- .parser = &parse_blinded_planchet,
- .cleaner = &clean_blinded_planchet,
- .field = field,
- .ptr = blinded_planchet
- };
-
blinded_planchet->blinded_message = NULL;
- return ret;
+ return GNUNET_JSON_spec_blinded_message (field,
+ &blinded_planchet->blinded_message);
}