exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 53fe1523d69da07841f7108a77e24373c67e1b93
parent a316e20ba663c288e61757a1a6454fb191607fa6
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 10 Dec 2024 19:14:36 +0100

more convenience functions

Diffstat:
Msrc/include/taler_json_lib.h | 16+++++++++++++++-
Msrc/json/json_helper.c | 8+++++---
Msrc/json/json_pack.c | 44++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 62 insertions(+), 6 deletions(-)

diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h @@ -142,6 +142,19 @@ TALER_JSON_pack_token_issue_sig ( /** + * Generate packer instruction for a JSON field of type + * token family public key. + * + * @param name name of the field to add to the object + * @param pk public key + * @return json pack specification + */ +struct GNUNET_JSON_PackSpec +TALER_JSON_pack_token_pub ( + const char *name, + const struct TALER_TokenIssuePublicKey *pk); + +/** * Generate packer instruction for a JSON field of type token envelope. * * @param name name of the field to add to the object @@ -451,7 +464,8 @@ TALER_JSON_spec_denom_pub (const char *field, * @return corresponding field spec */ struct GNUNET_JSON_Specification -TALER_JSON_spec_token_pub (struct TALER_TokenIssuePublicKey *pk); +TALER_JSON_spec_token_pub (const char *field, + struct TALER_TokenIssuePublicKey *pk); /** diff --git a/src/json/json_helper.c b/src/json/json_helper.c @@ -616,7 +616,7 @@ parse_denom_pub (void *cls, { struct GNUNET_JSON_Specification ispec[] = { GNUNET_JSON_spec_rsa_public_key ( - "rsa_public_key", + "rsa_pub", &bsign_pub->details.rsa_public_key), GNUNET_JSON_spec_end () }; @@ -637,7 +637,7 @@ parse_denom_pub (void *cls, case GNUNET_CRYPTO_BSA_CS: { struct GNUNET_JSON_Specification ispec[] = { - GNUNET_JSON_spec_fixed ("cs_public_key", + GNUNET_JSON_spec_fixed ("cs_pub", &bsign_pub->details.cs_public_key, sizeof (bsign_pub->details.cs_public_key)), GNUNET_JSON_spec_end () @@ -807,9 +807,11 @@ clean_token_pub (void *cls, struct GNUNET_JSON_Specification -TALER_JSON_spec_token_pub (struct TALER_TokenIssuePublicKey *pk) +TALER_JSON_spec_token_pub (const char *field, + struct TALER_TokenIssuePublicKey *pk) { struct GNUNET_JSON_Specification ret = { + .field = field, .parser = &parse_token_pub, .cleaner = &clean_token_pub, .ptr = pk diff --git a/src/json/json_pack.c b/src/json/json_pack.c @@ -161,7 +161,7 @@ TALER_JSON_pack_denom_pub ( "RSA"), GNUNET_JSON_pack_uint64 ("age_mask", pk->age_mask.bits), - GNUNET_JSON_pack_rsa_public_key ("rsa_public_key", + GNUNET_JSON_pack_rsa_public_key ("rsa_pub", bsp->details.rsa_public_key)); return ps; case GNUNET_CRYPTO_BSA_CS: @@ -171,7 +171,47 @@ TALER_JSON_pack_denom_pub ( "CS"), GNUNET_JSON_pack_uint64 ("age_mask", pk->age_mask.bits), - GNUNET_JSON_pack_data_varsize ("cs_public_key", + GNUNET_JSON_pack_data_varsize ("cs_pub", + &bsp->details.cs_public_key, + sizeof (bsp->details.cs_public_key))); + return ps; + } + GNUNET_assert (0); + return ps; +} + + +struct GNUNET_JSON_PackSpec +TALER_JSON_pack_token_pub ( + const char *name, + const struct TALER_TokenIssuePublicKey *pk) +{ + const struct GNUNET_CRYPTO_BlindSignPublicKey *bsp; + struct GNUNET_JSON_PackSpec ps = { + .field_name = name, + }; + + if (NULL == pk) + return ps; + bsp = pk->public_key; + switch (bsp->cipher) + { + case GNUNET_CRYPTO_BSA_INVALID: + break; + case GNUNET_CRYPTO_BSA_RSA: + ps.object + = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("cipher", + "RSA"), + GNUNET_JSON_pack_rsa_public_key ("rsa_pub", + bsp->details.rsa_public_key)); + return ps; + case GNUNET_CRYPTO_BSA_CS: + ps.object + = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("cipher", + "CS"), + GNUNET_JSON_pack_data_varsize ("cs_pub", &bsp->details.cs_public_key, sizeof (bsp->details.cs_public_key))); return ps;