2015-01-08 18:37:20 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2015-04-13 17:20:46 +02:00
|
|
|
Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file include/taler_json_lib.h
|
|
|
|
* @brief helper functions for JSON processing using libjansson
|
|
|
|
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
|
|
|
|
*/
|
2015-03-27 19:58:40 +01:00
|
|
|
#ifndef TALER_json_LIB_H_
|
|
|
|
#define TALER_json_LIB_H_
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
#include <jansson.h>
|
|
|
|
|
2015-02-17 17:23:13 +01:00
|
|
|
/**
|
|
|
|
* Print JSON parsing related error information
|
|
|
|
*/
|
2015-03-27 19:58:40 +01:00
|
|
|
#define TALER_json_warn(error) \
|
2015-02-17 17:23:13 +01:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
|
|
|
|
"JSON parsing failed at %s:%u: %s (%s)\n", \
|
|
|
|
__FILE__, __LINE__, error.text, error.source)
|
|
|
|
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
/**
|
2015-01-19 21:53:23 +01:00
|
|
|
* Convert a TALER amount to a JSON object.
|
2015-01-08 18:37:20 +01:00
|
|
|
*
|
|
|
|
* @param amount the amount
|
|
|
|
* @return a json object describing the amount
|
|
|
|
*/
|
|
|
|
json_t *
|
2015-03-27 19:58:40 +01:00
|
|
|
TALER_json_from_amount (const struct TALER_Amount *amount);
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert absolute timestamp to a json string.
|
|
|
|
*
|
2015-03-28 15:42:07 +01:00
|
|
|
* @param stamp the time stamp
|
2015-01-08 18:37:20 +01:00
|
|
|
* @return a json string with the timestamp in @a stamp
|
|
|
|
*/
|
|
|
|
json_t *
|
2015-03-27 19:58:40 +01:00
|
|
|
TALER_json_from_abs (struct GNUNET_TIME_Absolute stamp);
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
|
2015-03-15 16:39:06 +01:00
|
|
|
/**
|
|
|
|
* Convert RSA public key to JSON.
|
|
|
|
*
|
|
|
|
* @param pk public key to convert
|
|
|
|
* @return corresponding JSON encoding
|
|
|
|
*/
|
|
|
|
json_t *
|
2015-03-27 19:58:40 +01:00
|
|
|
TALER_json_from_rsa_public_key (struct GNUNET_CRYPTO_rsa_PublicKey *pk);
|
2015-03-15 16:39:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert RSA signature to JSON.
|
|
|
|
*
|
|
|
|
* @param sig signature to convert
|
|
|
|
* @return corresponding JSON encoding
|
|
|
|
*/
|
|
|
|
json_t *
|
2015-03-27 19:58:40 +01:00
|
|
|
TALER_json_from_rsa_signature (struct GNUNET_CRYPTO_rsa_Signature *sig);
|
2015-03-15 16:39:06 +01:00
|
|
|
|
|
|
|
|
2015-01-08 18:37:20 +01:00
|
|
|
/**
|
|
|
|
* Convert binary data to a JSON string
|
|
|
|
* with the base32crockford encoding.
|
|
|
|
*
|
|
|
|
* @param data binary data
|
|
|
|
* @param size size of @a data in bytes
|
|
|
|
* @return json string that encodes @a data
|
|
|
|
*/
|
|
|
|
json_t *
|
2015-11-11 14:44:08 +01:00
|
|
|
TALER_json_from_data (const void *data,
|
|
|
|
size_t size);
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse given JSON object to Amount
|
|
|
|
*
|
|
|
|
* @param json the json object representing Amount
|
2015-03-28 15:42:07 +01:00
|
|
|
* @param[out] r_amount where the amount has to be written
|
2015-01-28 20:37:51 +01:00
|
|
|
* @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
|
2015-01-08 18:37:20 +01:00
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TALER_json_to_amount (json_t *json,
|
2015-01-08 18:37:20 +01:00
|
|
|
struct TALER_Amount *r_amount);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse given JSON object to absolute time.
|
|
|
|
*
|
|
|
|
* @param json the json object representing absolute time in seconds
|
2015-03-28 15:42:07 +01:00
|
|
|
* @param[out] abs where the time has to be written
|
2015-01-28 20:37:51 +01:00
|
|
|
* @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
|
2015-01-08 18:37:20 +01:00
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TALER_json_to_abs (json_t *json,
|
2015-03-28 15:42:07 +01:00
|
|
|
struct GNUNET_TIME_Absolute *abs);
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse given JSON object to data
|
|
|
|
*
|
|
|
|
* @param json the json object representing data
|
|
|
|
* @param out the pointer to hold the parsed data.
|
2015-01-28 20:37:51 +01:00
|
|
|
* @param out_size the size of @a out
|
|
|
|
* @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
|
2015-01-08 18:37:20 +01:00
|
|
|
*/
|
|
|
|
int
|
2015-03-27 19:58:40 +01:00
|
|
|
TALER_json_to_data (json_t *json,
|
2015-01-08 18:37:20 +01:00
|
|
|
void *out,
|
|
|
|
size_t out_size);
|
|
|
|
|
2015-05-17 17:28:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert JSON to RSA public key.
|
|
|
|
*
|
2015-06-12 11:00:04 +02:00
|
|
|
* @param json JSON encoding to convert
|
2015-05-17 17:28:18 +02:00
|
|
|
* @return corresponding public key
|
|
|
|
*/
|
|
|
|
struct GNUNET_CRYPTO_rsa_PublicKey *
|
|
|
|
TALER_json_to_rsa_public_key (json_t *json);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert JSON to RSA signature.
|
|
|
|
*
|
2015-06-12 11:00:04 +02:00
|
|
|
* @param json JSON encoding to convert
|
2015-05-17 17:28:18 +02:00
|
|
|
* @return corresponding signature
|
|
|
|
*/
|
|
|
|
struct GNUNET_CRYPTO_rsa_Signature *
|
|
|
|
TALER_json_to_rsa_signature (json_t *json);
|
|
|
|
|
|
|
|
|
2015-06-21 19:18:31 +02:00
|
|
|
/**
|
|
|
|
* Hash a JSON for binary signing.
|
|
|
|
*
|
|
|
|
* @param[in] json some JSON value to hash
|
|
|
|
* @param[out] hc resulting hash code
|
|
|
|
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
TALER_hash_json (json_t *json,
|
|
|
|
struct GNUNET_HashCode *hc);
|
|
|
|
|
|
|
|
|
2015-02-17 17:23:13 +01:00
|
|
|
/**
|
|
|
|
* Check if the given wire format JSON object is correctly formatted
|
|
|
|
*
|
2015-09-20 13:48:15 +02:00
|
|
|
* @param allowed NULL-terminated array of allowed wire format types
|
2015-02-17 17:23:13 +01:00
|
|
|
* @param wire the JSON wire format object
|
2015-03-13 10:01:57 +01:00
|
|
|
* @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not
|
2015-02-17 17:23:13 +01:00
|
|
|
*/
|
|
|
|
int
|
2015-09-20 13:48:15 +02:00
|
|
|
TALER_json_validate_wireformat (const char **allowed,
|
2015-03-13 10:01:57 +01:00
|
|
|
const json_t *wire);
|
2015-02-17 17:23:13 +01:00
|
|
|
|
2015-01-08 18:37:20 +01:00
|
|
|
|
2015-03-27 19:58:40 +01:00
|
|
|
#endif /* TALER_json_LIB_H_ */
|
2015-01-08 18:37:20 +01:00
|
|
|
|
|
|
|
/* End of taler_json_lib.h */
|