aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/taler_json_lib.h20
-rw-r--r--src/mint/taler-mint-httpd_keystate.c8
-rw-r--r--src/mint/taler-mint-httpd_responses.c38
-rw-r--r--src/util/json.c44
4 files changed, 73 insertions, 37 deletions
diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h
index ffa440d56..1048b89f6 100644
--- a/src/include/taler_json_lib.h
+++ b/src/include/taler_json_lib.h
@@ -77,6 +77,26 @@ TALER_JSON_from_ecdsa_sig (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpo
/**
+ * Convert RSA public key to JSON.
+ *
+ * @param pk public key to convert
+ * @return corresponding JSON encoding
+ */
+json_t *
+TALER_JSON_from_rsa_public_key (struct GNUNET_CRYPTO_rsa_PublicKey *pk);
+
+
+/**
+ * Convert RSA signature to JSON.
+ *
+ * @param sig signature to convert
+ * @return corresponding JSON encoding
+ */
+json_t *
+TALER_JSON_from_rsa_signature (struct GNUNET_CRYPTO_rsa_Signature *sig);
+
+
+/**
* Convert binary data to a JSON string
* with the base32crockford encoding.
*
diff --git a/src/mint/taler-mint-httpd_keystate.c b/src/mint/taler-mint-httpd_keystate.c
index d9eb81a9c..abc746e7d 100644
--- a/src/mint/taler-mint-httpd_keystate.c
+++ b/src/mint/taler-mint-httpd_keystate.c
@@ -116,8 +116,6 @@ static int reload_pipe[2];
static json_t *
denom_key_issue_to_json (const struct TALER_MINT_DenomKeyIssue *dki)
{
- char *buf;
- size_t buf_len;
json_t *dk_json = json_object ();
json_object_set_new (dk_json,
@@ -134,13 +132,9 @@ denom_key_issue_to_json (const struct TALER_MINT_DenomKeyIssue *dki)
"stamp_expire_deposit",
TALER_JSON_from_abs (GNUNET_TIME_absolute_ntoh (dki->expire_spend)));
- buf_len = GNUNET_CRYPTO_rsa_public_key_encode (dki->denom_pub,
- &buf);
json_object_set_new (dk_json,
"denom_pub",
- TALER_JSON_from_data (buf,
- buf_len));
- GNUNET_free (buf);
+ TALER_JSON_from_rsa_public_key (dki->denom_pub));
json_object_set_new (dk_json,
"value",
TALER_JSON_from_amount (TALER_amount_ntoh (dki->value)));
diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c
index dc51dee4b..1a0a7c997 100644
--- a/src/mint/taler-mint-httpd_responses.c
+++ b/src/mint/taler-mint-httpd_responses.c
@@ -581,15 +581,9 @@ TALER_MINT_reply_withdraw_sign_success (struct MHD_Connection *connection,
const struct CollectableBlindcoin *collectable)
{
json_t *sig_json;
- size_t sig_buf_size;
- char *sig_buf;
int ret;
- sig_buf_size = GNUNET_CRYPTO_rsa_signature_encode (collectable->sig,
- &sig_buf);
- sig_json = TALER_JSON_from_data (sig_buf,
- sig_buf_size);
- GNUNET_free (sig_buf);
+ sig_json = TALER_JSON_from_rsa_signature (collectable->sig);
ret = TALER_MINT_reply_json_pack (connection,
MHD_HTTP_OK,
"{s:o}",
@@ -691,22 +685,14 @@ TALER_MINT_reply_refresh_reveal_success (struct MHD_Connection *connection,
int newcoin_index;
json_t *root;
json_t *list;
- char *buf;
- size_t buf_size;
int ret;
root = json_object ();
list = json_array ();
json_object_set_new (root, "ev_sigs", list);
for (newcoin_index = 0; newcoin_index < num_newcoins; newcoin_index++)
- {
- buf_size = GNUNET_CRYPTO_rsa_signature_encode (sigs[newcoin_index],
- &buf);
json_array_append_new (list,
- TALER_JSON_from_data (buf,
- buf_size));
- GNUNET_free (buf);
- }
+ TALER_JSON_from_rsa_signature (sigs[newcoin_index]));
ret = TALER_MINT_reply_json (connection,
root,
MHD_HTTP_OK);
@@ -772,26 +758,18 @@ TALER_MINT_reply_refresh_link_success (struct MHD_Connection *connection,
for (pos = ldl; NULL != pos; pos = pos->next)
{
json_t *obj;
- char *buf;
- size_t buf_len;
obj = json_object ();
json_object_set_new (obj, "link_enc",
TALER_JSON_from_data (ldl->link_data_enc->coin_priv_enc,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey) +
ldl->link_data_enc->blinding_key_enc_size));
- buf_len = GNUNET_CRYPTO_rsa_public_key_encode (ldl->denom_pub,
- &buf);
- json_object_set_new (obj, "denom_pub",
- TALER_JSON_from_data (buf,
- buf_len));
- GNUNET_free (buf);
- buf_len = GNUNET_CRYPTO_rsa_signature_encode (ldl->ev_sig,
- &buf);
- json_object_set_new (obj, "ev_sig",
- TALER_JSON_from_data (buf,
- buf_len));
- GNUNET_free (buf);
+ json_object_set_new (obj,
+ "denom_pub",
+ TALER_JSON_from_rsa_public_key (ldl->denom_pub));
+ json_object_set_new (obj,
+ "ev_sig",
+ TALER_JSON_from_rsa_signature (ldl->ev_sig));
json_array_append_new (list, obj);
}
diff --git a/src/util/json.c b/src/util/json.c
index a9d6dc5cc..84fac4c98 100644
--- a/src/util/json.c
+++ b/src/util/json.c
@@ -151,6 +151,50 @@ TALER_JSON_from_ecdsa_sig (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpo
/**
+ * Convert RSA public key to JSON.
+ *
+ * @param pk public key to convert
+ * @return corresponding JSON encoding
+ */
+json_t *
+TALER_JSON_from_rsa_public_key (struct GNUNET_CRYPTO_rsa_PublicKey *pk)
+{
+ char *buf;
+ size_t buf_len;
+ json_t *ret;
+
+ buf_len = GNUNET_CRYPTO_rsa_public_key_encode (pk,
+ &buf);
+ ret = TALER_JSON_from_data (buf,
+ buf_len);
+ GNUNET_free (buf);
+ return ret;
+}
+
+
+/**
+ * Convert RSA signature to JSON.
+ *
+ * @param sig signature to convert
+ * @return corresponding JSON encoding
+ */
+json_t *
+TALER_JSON_from_rsa_signature (struct GNUNET_CRYPTO_rsa_Signature *sig)
+{
+ char *buf;
+ size_t buf_len;
+ json_t *ret;
+
+ buf_len = GNUNET_CRYPTO_rsa_signature_encode (sig,
+ &buf);
+ ret = TALER_JSON_from_data (buf,
+ buf_len);
+ GNUNET_free (buf);
+ return ret;
+}
+
+
+/**
* Convert binary data to a JSON string
* with the base32crockford encoding.
*