summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/taler_json_lib.h32
-rw-r--r--src/util/json.c84
2 files changed, 91 insertions, 25 deletions
diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h
index 2f0c54498..ede2a20ee 100644
--- a/src/include/taler_json_lib.h
+++ b/src/include/taler_json_lib.h
@@ -97,17 +97,6 @@ TALER_json_from_data (const void *data, size_t size);
/**
- * Convert binary hash to a JSON string with the base32crockford
- * encoding.
- *
- * @param hc binary data
- * @return json string that encodes @a hc
- */
-json_t *
-TALER_json_from_hash (const struct GNUNET_HashCode *hc);
-
-
-/**
* Parse given JSON object to Amount
*
* @param json the json object representing Amount
@@ -142,6 +131,27 @@ TALER_json_to_data (json_t *json,
void *out,
size_t out_size);
+
+/**
+ * Convert JSON to RSA public key.
+ *
+ * @param pk JSON encoding to convert
+ * @return corresponding public key
+ */
+struct GNUNET_CRYPTO_rsa_PublicKey *
+TALER_json_to_rsa_public_key (json_t *json);
+
+
+/**
+ * Convert JSON to RSA signature.
+ *
+ * @param pk JSON encoding to convert
+ * @return corresponding signature
+ */
+struct GNUNET_CRYPTO_rsa_Signature *
+TALER_json_to_rsa_signature (json_t *json);
+
+
/**
* Check if the given wire format JSON object is correctly formatted
*
diff --git a/src/util/json.c b/src/util/json.c
index 3d702b7be..34e41e0d7 100644
--- a/src/util/json.c
+++ b/src/util/json.c
@@ -153,6 +153,76 @@ TALER_json_from_rsa_public_key (struct GNUNET_CRYPTO_rsa_PublicKey *pk)
/**
+ * Convert JSON to RSA public key.
+ *
+ * @param pk JSON encoding to convert
+ * @return corresponding public key
+ */
+struct GNUNET_CRYPTO_rsa_PublicKey *
+TALER_json_to_rsa_public_key (json_t *json)
+{
+ const char *enc;
+ char *buf;
+ size_t len;
+ size_t buf_len;
+ struct GNUNET_CRYPTO_rsa_PublicKey *pk;
+
+ buf = NULL;
+ EXITIF (NULL == (enc = json_string_value (json)));
+ len = strlen (enc);
+ buf_len = (len * 5) / 8;
+ buf = GNUNET_malloc (buf_len);
+ EXITIF (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (enc,
+ len,
+ buf,
+ buf_len));
+ EXITIF (NULL == (pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
+ buf_len)));
+ GNUNET_free (buf);
+ return pk;
+ EXITIF_exit:
+ GNUNET_free_non_null (buf);
+ return NULL;
+}
+
+
+/**
+ * Convert JSON to RSA signature.
+ *
+ * @param pk JSON encoding to convert
+ * @return corresponding signature
+ */
+struct GNUNET_CRYPTO_rsa_Signature *
+TALER_json_to_rsa_signature (json_t *json)
+{
+ const char *enc;
+ char *buf;
+ size_t len;
+ size_t buf_len;
+ struct GNUNET_CRYPTO_rsa_Signature *sig;
+
+ buf = NULL;
+ EXITIF (NULL == (enc = json_string_value (json)));
+ len = strlen (enc);
+ buf_len = (len * 5) / 8;
+ buf = GNUNET_malloc (buf_len);
+ EXITIF (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (enc,
+ len,
+ buf,
+ buf_len));
+ EXITIF (NULL == (sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
+ buf_len)));
+ GNUNET_free (buf);
+ return sig;
+ EXITIF_exit:
+ GNUNET_free_non_null (buf);
+ return NULL;
+}
+
+
+/**
* Convert RSA signature to JSON.
*
* @param sig signature to convert
@@ -197,20 +267,6 @@ TALER_json_from_data (const void *data,
/**
- * Convert binary hash to a JSON string with the base32crockford
- * encoding.
- *
- * @param hc binary data
- * @return json string that encodes @a hc
- */
-json_t *
-TALER_json_from_hash (const struct GNUNET_HashCode *hc)
-{
- return TALER_json_from_data (hc, sizeof (struct GNUNET_HashCode));
-}
-
-
-/**
* Parse given JSON object to Amount
*
* @param json the json object representing Amount