diff options
Diffstat (limited to 'src/json/donau_json.c')
-rw-r--r-- | src/json/donau_json.c | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/src/json/donau_json.c b/src/json/donau_json.c index 90fd6dd..629e005 100644 --- a/src/json/donau_json.c +++ b/src/json/donau_json.c @@ -366,6 +366,131 @@ DONAU_JSON_spec_blinded_donation_identifier (const char *field, return ret; } +/** + * Parse given JSON object to blinded donation unit 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_donation_unit_sig (void *cls, + json_t *root, + struct GNUNET_JSON_Specification *spec) +{ + struct DONAU_BlindedDonationUnitSignature *du_sig = spec->ptr; + struct GNUNET_CRYPTO_BlindedSignature *blinded_sig; + 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_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature); + blinded_sig->cipher = string_to_cipher (cipher); + blinded_sig->rc = 1; + switch (blinded_sig->cipher) + { + case GNUNET_CRYPTO_BSA_INVALID: + break; + case GNUNET_CRYPTO_BSA_RSA: + { + struct GNUNET_JSON_Specification ispec[] = { + GNUNET_JSON_spec_rsa_signature ( + "blinded_rsa_signature", + &blinded_sig->details.blinded_rsa_signature), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (root, + ispec, + &emsg, + &eline)) + { + GNUNET_break_op (0); + GNUNET_free (blinded_sig); + return GNUNET_SYSERR; + } + du_sig->blinded_sig = blinded_sig; + return GNUNET_OK; + } + case GNUNET_CRYPTO_BSA_CS: + { + struct GNUNET_JSON_Specification ispec[] = { + GNUNET_JSON_spec_uint32 ("b", + &blinded_sig->details.blinded_cs_answer.b), + GNUNET_JSON_spec_fixed_auto ("s", + &blinded_sig->details.blinded_cs_answer. + s_scalar), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (root, + ispec, + &emsg, + &eline)) + { + GNUNET_break_op (0); + GNUNET_free (blinded_sig); + return GNUNET_SYSERR; + } + du_sig->blinded_sig = blinded_sig; + return GNUNET_OK; + } + } + GNUNET_break_op (0); + GNUNET_free (blinded_sig); + return GNUNET_SYSERR; +} + + +/** + * Cleanup data left from parsing donation unit public key. + * + * @param cls closure, NULL + * @param[out] spec where to free the data + */ +static void +clean_blinded_donation_unit_sig (void *cls, + struct GNUNET_JSON_Specification *spec) +{ + struct DONAU_BlindedDonationUnitSignature *du_sig = spec->ptr; + + (void) cls; + DONAU_blinded_donation_unit_sig_free (du_sig); +} + + +struct GNUNET_JSON_Specification +DONAU_JSON_spec_blinded_donation_unit_sig (const char *field, + struct DONAU_BlindedDonationUnitSignature *sig) +{ + struct GNUNET_JSON_Specification ret = { + .parser = &parse_blinded_donation_unit_sig, + .cleaner = &clean_blinded_donation_unit_sig, + .field = field, + .ptr = sig + }; + + sig->blinded_sig = NULL; + return ret; +} struct GNUNET_JSON_PackSpec DONAU_JSON_pack_blinded_donation_unit_sig ( |