GNUnet 0.24.1-15-gab6ed22f1
gnunet_json_lib.h File Reference

functions to parse JSON objects into GNUnet objects More...

#include "gnunet_util_lib.h"
#include <jansson.h>
Include dependency graph for gnunet_json_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_JSON_Specification
 Entry in parser specification for GNUNET_JSON_parse(). More...
 
struct  GNUNET_JSON_PackSpec
 Element in the array to give to the packer. More...
 

Macros

#define GNUNET_JSON_spec_fixed_auto(name, obj)    GNUNET_JSON_spec_fixed (name, (obj), sizeof(*(obj)))
 Fixed size object (in network byte order, encoded using Crockford Base32hex encoding). More...
 
#define GNUNET_JSON_spec_fixed64_auto(name, obj)    GNUNET_JSON_spec_fixed (name, (obj), sizeof(*(obj)))
 Fixed size object (in network byte order, encoded using base64 encoding). More...
 
#define GNUNET_JSON_from_data_auto(ptr)    GNUNET_JSON_from_data (ptr, sizeof(*(ptr)))
 Convert binary data to a JSON string with the base32crockford encoding. More...
 
#define GNUNET_JSON_from_data64_auto(ptr)    GNUNET_JSON_from_data64 (ptr, sizeof(*(ptr)))
 Convert binary data to a JSON string with base64 encoding. More...
 
#define GNUNET_JSON_PACK(...)
 Pack a JSON object from a spec. More...
 
#define GNUNET_JSON_pack_data_auto(name, blob)    GNUNET_JSON_pack_data_varsize (name, (blob), sizeof (*(blob)))
 Generate packer instruction for a JSON field where the size is automatically determined from the argument. More...
 
#define GNUNET_JSON_pack_data64_auto(name, blob)    GNUNET_JSON_pack_data64_varsize (name, (blob), sizeof (*(blob)))
 Generate packer instruction for a JSON field where the size is automatically determined from the argument. More...
 

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_JSON_Parser) (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Function called to parse JSON argument. More...
 
typedef void(* GNUNET_JSON_Cleaner) (void *cls, struct GNUNET_JSON_Specification *spec)
 Function called to clean up data from earlier parsing. More...
 
typedef json_t *(* GNUNET_JSON_PackCallback) (const struct GNUNET_JSON_PackSpec *se)
 Function called to pack an element into the JSON object as part of GNUNET_JSON_pack_(). More...
 

Functions

enum GNUNET_GenericReturnValue GNUNET_JSON_parse (const json_t *root, struct GNUNET_JSON_Specification *spec, const char **error_json_name, unsigned int *error_line)
 Navigate and parse data in a JSON tree. More...
 
void GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec)
 Frees all elements allocated during a GNUNET_JSON_parse() operation. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end (void)
 End of a parser specification. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec, bool *missing)
 Set the "optional" flag for a parser specification entry. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed (const char *name, void *obj, size_t size)
 Variable size object (in network byte order, encoded using Crockford Base32hex encoding). More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed64 (const char *name, void *obj, size_t size)
 Variable size object (in network byte order, encoded using base64 encoding). More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_varsize (const char *name, void **obj, size_t *size)
 Variable size object (in network byte order, encoded using Crockford Base32hex encoding). More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string (const char *name, const char **strptr)
 The expected field stores a string. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string_copy (const char *name, char **strptr)
 The expected field stores a string. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json (const char *name, json_t **jsonp)
 JSON object or array. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_copy (const char *name, json_t **jsonp)
 JSON object, reference counter not incremented. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_copy (const char *name, json_t **jsonp)
 JSON array, reference counter not incremented. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const (const char *name, const json_t **jsonp)
 JSON object, reference counter not incremented. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const (const char *name, const json_t **jsonp)
 JSON array, reference counter not incremented. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool (const char *name, bool *b)
 boolean. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_double (const char *name, double *f)
 double. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8)
 8-bit integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16)
 16-bit integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32)
 32-bit integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint (const char *name, unsigned int *ui)
 Unsigned integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_ull (const char *name, unsigned long long *ull)
 Unsigned long long. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64)
 64-bit integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int16 (const char *name, int16_t *i16)
 16-bit signed integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64 (const char *name, int64_t *i64)
 64-bit signed integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_boolean (const char *name, int *boolean)
 Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO). More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp (const char *name, struct GNUNET_TIME_Timestamp *t)
 Timestamp. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *tn)
 Timestamp in network byte order. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt)
 Relative time. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_public_key (const char *name, struct GNUNET_CRYPTO_RsaPublicKey **pk)
 Specification for parsing an RSA public key. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
 Specification for parsing an RSA signature. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_message (const char *name, struct GNUNET_CRYPTO_BlindedMessage **msg)
 Specification for parsing a blinded message. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_signature (const char *field, struct GNUNET_CRYPTO_BlindedSignature **b_sig)
 Specification for parsing a blinded signature. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_unblinded_signature (const char *field, struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
 Specification for parsing an unblinded signature. More...
 
json_t * GNUNET_JSON_from_data (const void *data, size_t size)
 Convert binary data to a JSON string with the base32crockford encoding. More...
 
json_t * GNUNET_JSON_from_data64 (const void *data, size_t size)
 Convert binary data to a JSON string with base64 encoding. More...
 
json_t * GNUNET_JSON_from_timestamp (struct GNUNET_TIME_Timestamp stamp)
 Convert timestamp to a json string. More...
 
json_t * GNUNET_JSON_from_timestamp_nbo (struct GNUNET_TIME_TimestampNBO stamp)
 Convert timestamp to a json string. More...
 
json_t * GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp)
 Convert relative timestamp to a json string. More...
 
json_t * GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk)
 Convert RSA public key to JSON. More...
 
json_t * GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig)
 Convert RSA signature to JSON. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_JSON_getopt (char shortName, const char *name, const char *argumentHelp, const char *description, json_t **json)
 Allow user to specify a JSON input value. More...
 
json_t * GNUNET_JSON_pack_ (struct GNUNET_JSON_PackSpec spec[])
 Pack a JSON object from a spec. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_end_ (void)
 Do not use directly. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_allow_null (struct GNUNET_JSON_PackSpec in)
 Modify packer instruction to allow NULL as a value. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_bool (const char *name, bool b)
 Generate packer instruction for a JSON field of type bool. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_double (const char *name, double f)
 Generate packer instruction for a JSON field of type double. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_string (const char *name, const char *s)
 Generate packer instruction for a JSON field of type string. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_uint64 (const char *name, uint64_t num)
 Generate packer instruction for a JSON field of type unsigned integer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_int64 (const char *name, int64_t num)
 Generate packer instruction for a JSON field of type signed integer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_steal (const char *name, json_t *o)
 Generate packer instruction for a JSON field of type JSON object where the reference is taken over by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_incref (const char *name, json_t *o)
 Generate packer instruction for a JSON field of type JSON object where the reference counter is incremented by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_steal (const char *name, json_t *a)
 Generate packer instruction for a JSON field of type JSON array where the reference is taken over by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_incref (const char *name, json_t *a)
 Generate packer instruction for a JSON field of type JSON array where the reference counter is incremented by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data_varsize (const char *name, const void *blob, size_t blob_size)
 Generate packer instruction for a JSON field of type variable size binary blob. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data64_varsize (const char *name, const void *blob, size_t blob_size)
 Generate packer instruction for a JSON field of type variable size binary blob. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp (const char *name, struct GNUNET_TIME_Timestamp at)
 Generate packer instruction for a JSON field of type timestamp. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO at)
 Generate packer instruction for a JSON field of type timestamp in network byte order. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel (const char *name, struct GNUNET_TIME_Relative rt)
 Generate packer instruction for a JSON field of type relative time. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel_nbo (const char *name, struct GNUNET_TIME_RelativeNBO rt)
 Generate packer instruction for a JSON field of type relative time in network byte order. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_public_key (const char *name, const struct GNUNET_CRYPTO_RsaPublicKey *pk)
 Generate packer instruction for a JSON field of type RSA public key. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_signature (const char *name, const struct GNUNET_CRYPTO_RsaSignature *sig)
 Generate packer instruction for a JSON field of type RSA signature. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_unblinded_signature (const char *name, const struct GNUNET_CRYPTO_UnblindedSignature *sig)
 Generate packer instruction for a JSON field of type unblinded signature. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_message (const char *name, const struct GNUNET_CRYPTO_BlindedMessage *msg)
 Generate packer instruction for a JSON field of type blinded message. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_sig (const char *name, const struct GNUNET_CRYPTO_BlindedSignature *sig)
 Generate packer instruction for a JSON field of type blinded signature. More...
 

Detailed Description

functions to parse JSON objects into GNUnet objects

Author
Florian Dold
Benedikt Mueller
Christian Grothoff

Definition in file gnunet_json_lib.h.

Macro Definition Documentation

◆ GNUNET_JSON_spec_fixed_auto

#define GNUNET_JSON_spec_fixed_auto (   name,
  obj 
)     GNUNET_JSON_spec_fixed (name, (obj), sizeof(*(obj)))

Fixed size object (in network byte order, encoded using Crockford Base32hex encoding).

Parameters
namename of the JSON field
objpointer where to write the data (type of *obj will determine size)

Definition at line 200 of file gnunet_json_lib.h.

◆ GNUNET_JSON_spec_fixed64_auto

#define GNUNET_JSON_spec_fixed64_auto (   name,
  obj 
)     GNUNET_JSON_spec_fixed (name, (obj), sizeof(*(obj)))

Fixed size object (in network byte order, encoded using base64 encoding).

Parameters
namename of the JSON field
objpointer where to write the data (type of *obj will determine size)

Definition at line 223 of file gnunet_json_lib.h.

◆ GNUNET_JSON_from_data_auto

#define GNUNET_JSON_from_data_auto (   ptr)     GNUNET_JSON_from_data (ptr, sizeof(*(ptr)))

Convert binary data to a JSON string with the base32crockford encoding.

Parameters
ptrbinary data, sizeof (*ptr) must yield correct size
Returns
json string that encodes data

Definition at line 566 of file gnunet_json_lib.h.

◆ GNUNET_JSON_from_data64_auto

#define GNUNET_JSON_from_data64_auto (   ptr)     GNUNET_JSON_from_data64 (ptr, sizeof(*(ptr)))

Convert binary data to a JSON string with base64 encoding.

Parameters
ptrbinary data, sizeof (*ptr) must yield correct size
Returns
json string that encodes data

Definition at line 577 of file gnunet_json_lib.h.

◆ GNUNET_JSON_PACK

#define GNUNET_JSON_PACK (   ...)
Value:
GNUNET_JSON_pack_ ((struct GNUNET_JSON_PackSpec[]) {__VA_ARGS__, \
GNUNET_JSON_pack_end_ ()})
json_t * GNUNET_JSON_pack_(struct GNUNET_JSON_PackSpec spec[])
Pack a JSON object from a spec.
Definition: json_pack.c:29
Element in the array to give to the packer.

Pack a JSON object from a spec.

Aborts if packing fails.

Parameters
...list of specification objects
Returns
JSON object

Definition at line 720 of file gnunet_json_lib.h.

◆ GNUNET_JSON_pack_data_auto

#define GNUNET_JSON_pack_data_auto (   name,
  blob 
)     GNUNET_JSON_pack_data_varsize (name, (blob), sizeof (*(blob)))

Generate packer instruction for a JSON field where the size is automatically determined from the argument.

Parameters
namename of the field to add to the object
blobdata to pack, must not be an array
Returns
json pack specification

Definition at line 891 of file gnunet_json_lib.h.

◆ GNUNET_JSON_pack_data64_auto

#define GNUNET_JSON_pack_data64_auto (   name,
  blob 
)     GNUNET_JSON_pack_data64_varsize (name, (blob), sizeof (*(blob)))

Generate packer instruction for a JSON field where the size is automatically determined from the argument.

Use base64-encoding, instead of the more common Crockford base32-encoding.

Parameters
namename of the field to add to the object
blobdata to pack, must not be an array
Returns
json pack specification

Definition at line 922 of file gnunet_json_lib.h.

Typedef Documentation

◆ GNUNET_JSON_Parser

typedef enum GNUNET_GenericReturnValue(* GNUNET_JSON_Parser) (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)

Function called to parse JSON argument.

Parameters
clsclosure
rootJSON to parse
specour specification entry with further details
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 1 of file gnunet_json_lib.h.

◆ GNUNET_JSON_Cleaner

typedef void(* GNUNET_JSON_Cleaner) (void *cls, struct GNUNET_JSON_Specification *spec)

Function called to clean up data from earlier parsing.

Parameters
clsclosure
specour specification entry with data to clean.

Definition at line 62 of file gnunet_json_lib.h.

◆ GNUNET_JSON_PackCallback

typedef json_t *(* GNUNET_JSON_PackCallback) (const struct GNUNET_JSON_PackSpec *se)

Function called to pack an element into the JSON object as part of GNUNET_JSON_pack_().

Parameters
sepack specification to execute
Returns
json object to pack, NULL to pack nothing

Definition at line 666 of file gnunet_json_lib.h.

Function Documentation

◆ GNUNET_JSON_parse()

enum GNUNET_GenericReturnValue GNUNET_JSON_parse ( const json_t *  root,
struct GNUNET_JSON_Specification spec,
const char **  error_json_name,
unsigned int *  error_line 
)

Navigate and parse data in a JSON tree.

Tries to parse the root to find all of the values given in the spec. If one of the entries in spec cannot be found or parsed, the name of the JSON field is returned in error_json_name, and the offset of the entry in spec is returned in error_line.

Parameters
rootthe JSON node to start the navigation at.
[in,out]specparse specification array
[out]error_json_namewhich JSON field was problematic
[out]error_linewhich index into spec did we encounter an error
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 32 of file json.c.

36{
37 if (NULL == root)
38 {
39 if (NULL != error_json_name)
40 *error_json_name = "root is NULL";
41 if (NULL != error_line)
42 *error_line = 0;
43 return GNUNET_SYSERR;
44 }
45 for (unsigned int i = 0; NULL != spec[i].parser; i++)
46 {
47 json_t *pos;
48
49 if (NULL == spec[i].field)
50 pos = (json_t *) root;
51 else
52 pos = json_object_get (root,
53 spec[i].field);
54 if ( ( (NULL == pos) ||
55 (json_is_null (pos) ) ) &&
56 (spec[i].is_optional) )
57 {
58 if (NULL != spec[i].missing)
59 *spec[i].missing = true;
60 continue;
61 }
62 if ( (NULL == pos) ||
63 (GNUNET_OK !=
64 spec[i].parser (spec[i].cls,
65 pos,
66 &spec[i])) )
67 {
68 if (NULL != error_json_name)
69 *error_json_name = spec[i].field;
70 else
72 "Parsing failed for field `%s:%u`\n",
73 spec[i].field,
74 i);
75 if (NULL != error_line)
76 *error_line = i;
78 return GNUNET_SYSERR;
79 }
80 if (NULL != spec[i].missing)
81 *spec[i].missing = false;
82 }
83 return GNUNET_OK; /* all OK! */
84}
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_WARNING
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:100
bool * missing
Pointer to set to true if this argument is indeed missing.
const char * field
Name of the field to parse, use NULL to get the JSON of the main object instead of the JSON of an ind...
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.

References GNUNET_JSON_Specification::field, GNUNET_ERROR_TYPE_WARNING, GNUNET_JSON_parse_free(), GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_JSON_Specification::missing, warningfilter::parser, and GNUNET_JSON_Specification::parser.

Referenced by add_attribute_cont(), add_credential_cont(), bulk_tx_start(), consume_ticket_cont(), namestore_add_or_update(), parse_blinded_message(), parse_blinded_sig(), parse_unblinded_sig(), and revoke_ticket_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_parse_free()

void GNUNET_JSON_parse_free ( struct GNUNET_JSON_Specification spec)

Frees all elements allocated during a GNUNET_JSON_parse() operation.

Convenience function to be called if cleaning up all heap-allocated data from a GNUNET_JSON_parse() is desired. The function does not have to be called if no data was heap-allocated (e.g. only integers, strings and fixed-sized data was used), or if the application calls the respective code to free the heap (not always GNUNET_free(), depends on the data type!) on the returned heap-allocated data itself.

Parameters
[in,out]specspecification of the parse operation

Definition at line 100 of file json.c.

101{
102 for (unsigned int i = 0; NULL != spec[i].parser; i++)
103 if (NULL != spec[i].cleaner)
104 spec[i].cleaner (spec[i].cls,
105 &spec[i]);
106}
GNUNET_JSON_Cleaner cleaner
Function for how to clean up this type of entry.

References GNUNET_JSON_Specification::cleaner, GNUNET_JSON_Specification::cls, and GNUNET_JSON_Specification::parser.

Referenced by add_attribute_cont(), add_credential_cont(), consume_ticket_cont(), GNUNET_JSON_parse(), namestore_add_or_update(), and revoke_ticket_cont().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_end()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_end ( void  )

End of a parser specification.

Definition at line 33 of file json_helper.c.

34{
36 .parser = NULL,
37 };
38
39 return ret;
40}
static int ret
Final status code.
Definition: gnunet-arm.c:93
Entry in parser specification for GNUNET_JSON_parse().

References ret.

Referenced by add_attribute_cont(), add_credential_cont(), bulk_tx_start(), consume_ticket_cont(), namestore_add_or_update(), parse_blinded_message(), parse_blinded_sig(), parse_unblinded_sig(), and revoke_ticket_cont().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_mark_optional()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_mark_optional ( struct GNUNET_JSON_Specification  spec,
bool *  missing 
)

Set the "optional" flag for a parser specification entry.

Parameters
specspecification to modify
[out]missingset to true if the argument is missing, NULL is allowed.
Returns
spec copy of spec with optional bit set

Definition at line 88 of file json.c.

90{
91 struct GNUNET_JSON_Specification ret = spec;
92
93 ret.is_optional = true;
94 ret.missing = missing;
95 return ret;
96}

References GNUNET_JSON_Specification::missing, and ret.

◆ GNUNET_JSON_spec_fixed()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed ( const char *  name,
void *  obj,
size_t  size 
)

Variable size object (in network byte order, encoded using Crockford Base32hex encoding).

Parameters
namename of the JSON field
[out]objpointer where to write the data, must have size bytes
sizenumber of bytes expected in obj

Definition at line 115 of file json_helper.c.

118{
120 .parser = &parse_fixed_data,
121 .field = name,
122 .ptr = obj,
123 .ptr_size = size,
124 };
125
126 return ret;
127}
static char * name
Name (label) of the records to list.
static enum GNUNET_GenericReturnValue parse_fixed_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:75
static unsigned int size
Size of the "table".
Definition: peer.c:68

References name, parse_fixed_data(), ret, and size.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_fixed64()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed64 ( const char *  name,
void *  obj,
size_t  size 
)

Variable size object (in network byte order, encoded using base64 encoding).

Parameters
namename of the JSON field
[out]objpointer where to write the data, must have size bytes
sizenumber of bytes expected in obj

Definition at line 176 of file json_helper.c.

179{
181 .parser = &parse_fixed64_data,
182 .field = name,
183 .ptr = obj,
184 .ptr_size = size,
185 };
186
187 return ret;
188}
static enum GNUNET_GenericReturnValue parse_fixed64_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:139

References name, parse_fixed64_data(), ret, and size.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_varsize()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_varsize ( const char *  name,
void **  obj,
size_t *  size 
)

Variable size object (in network byte order, encoded using Crockford Base32hex encoding).

Parameters
namename of the JSON field
[out]objpointer where to write the data, will be allocated
[out]sizewhere to store the number of bytes allocated for obj

Definition at line 250 of file json_helper.c.

253{
255 .parser = &parse_variable_data,
256 .cleaner = &clean_variable_data,
257 .field = name,
258 .ptr = obj,
259 .size_ptr = size
260 };
261
262 *obj = NULL;
263 *size = 0;
264 return ret;
265}
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:236
static enum GNUNET_GenericReturnValue parse_variable_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to variable size data.
Definition: json_helper.c:200

References clean_variable_data(), name, parse_variable_data(), ret, and size.

Referenced by parse_blinded_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_string()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_string ( const char *  name,
const char **  strptr 
)

The expected field stores a string.

Parameters
namename of the JSON field
strptrwhere to store a pointer to the field

Definition at line 296 of file json_helper.c.

298{
300 .parser = &parse_string,
301 .field = name,
302 .ptr = strptr
303 };
304
305 *strptr = NULL;
306 return ret;
307}
static enum GNUNET_GenericReturnValue parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:277

References name, parse_string(), and ret.

Referenced by consume_ticket_cont(), parse_blinded_message(), parse_blinded_sig(), and parse_unblinded_sig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_string_copy()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_string_copy ( const char *  name,
char **  strptr 
)

The expected field stores a string.

Parameters
namename of the JSON field
strptrwhere to store a pointer to the field

Definition at line 338 of file json_helper.c.

340{
342 .parser = &parse_string_copy,
343 .field = name,
344 .ptr = strptr
345 };
346
347 *strptr = NULL;
348 return ret;
349}
static enum GNUNET_GenericReturnValue parse_string_copy(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string, and make a copy.
Definition: json_helper.c:319

References name, parse_string_copy(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_json()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_json ( const char *  name,
json_t **  jsonp 
)

JSON object or array.

Reference counter is incremented.

Parameters
namename of the JSON field
[out]jsonpwhere to store the JSON found under name

Definition at line 396 of file json_helper.c.

398{
400 .parser = &parse_json,
401 .cleaner = &clean_json,
402 .field = name,
403 .ptr = jsonp,
404 };
405
406 *jsonp = NULL;
407 return ret;
408}
static void clean_json(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:382
static enum GNUNET_GenericReturnValue parse_json(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:361

References clean_json(), name, parse_json(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_object_copy()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_copy ( const char *  name,
json_t **  jsonp 
)

JSON object, reference counter not incremented.

Parameters
namename of the JSON field
[out]jsonpwhere to store the JSON found under name

Definition at line 477 of file json_helper.c.

479{
481 .parser = &parse_object_copy,
482 .cls = &clean_json,
483 .field = name,
484 .ptr = jsonp,
485 };
486
487 *jsonp = NULL;
488 return ret;
489}
static enum GNUNET_GenericReturnValue parse_object_copy(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object and increment the reference counter.
Definition: json_helper.c:460

References clean_json(), name, parse_object_copy(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_array_copy()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_copy ( const char *  name,
json_t **  jsonp 
)

JSON array, reference counter not incremented.

Parameters
namename of the JSON field
[out]jsonpwhere to store the JSON found under name

Definition at line 558 of file json_helper.c.

560{
562 .parser = &parse_array_copy,
563 .cleaner = &clean_json,
564 .field = name,
565 .ptr = jsonp
566 };
567
568 *jsonp = NULL;
569 return ret;
570}
static enum GNUNET_GenericReturnValue parse_array_copy(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON to a JSON array and increment the reference counter.
Definition: json_helper.c:541

References clean_json(), name, parse_array_copy(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_object_const()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const ( const char *  name,
const json_t **  jsonp 
)

JSON object, reference counter not incremented.

Parameters
namename of the JSON field
[out]jsonpwhere to store the JSON found under name

Definition at line 437 of file json_helper.c.

439{
441 .parser = &parse_object_const,
442 .field = name,
443 .ptr = jsonp,
444 };
445
446 *jsonp = NULL;
447 return ret;
448}
static enum GNUNET_GenericReturnValue parse_object_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:420

References name, parse_object_const(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_array_const()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const ( const char *  name,
const json_t **  jsonp 
)

JSON array, reference counter not incremented.

Parameters
namename of the JSON field
[out]jsonpwhere to store the JSON found under name

Definition at line 518 of file json_helper.c.

520{
522 .parser = &parse_array_const,
523 .field = name,
524 .ptr = jsonp
525 };
526
527 *jsonp = NULL;
528 return ret;
529}
static enum GNUNET_GenericReturnValue parse_array_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON to a JSON array.
Definition: json_helper.c:501

References name, parse_array_const(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_bool()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool ( const char *  name,
bool *  b 
)

boolean.

Parameters
namename of the JSON field
[out]bwhere to store the boolean found under name

Definition at line 604 of file json_helper.c.

606{
608 .parser = &parse_bool,
609 .field = name,
610 .ptr = b,
611 .ptr_size = sizeof(bool),
612 };
613
614 return ret;
615}
static enum GNUNET_GenericReturnValue parse_bool(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a bool.
Definition: json_helper.c:582

References name, parse_bool(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_double()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_double ( const char *  name,
double *  f 
)

double.

Parameters
namename of the JSON field
[out]fwhere to store the double found under name

Definition at line 644 of file json_helper.c.

646{
648 .parser = &parse_double,
649 .field = name,
650 .ptr = f,
651 .ptr_size = sizeof(double),
652 };
653
654 return ret;
655}
static enum GNUNET_GenericReturnValue parse_double(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a double.
Definition: json_helper.c:627

References name, parse_double(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_uint8()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8 ( const char *  name,
uint8_t *  u8 
)

8-bit integer.

Parameters
namename of the JSON field
[out]u8where to store the integer found under name

Definition at line 691 of file json_helper.c.

693{
695 .parser = &parse_u8,
696 .field = name,
697 .ptr = u8,
698 .ptr_size = sizeof(uint8_t),
699 };
700
701 return ret;
702}
static enum GNUNET_GenericReturnValue parse_u8(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.
Definition: json_helper.c:667

References name, parse_u8(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_uint16()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16 ( const char *  name,
uint16_t *  u16 
)

16-bit integer.

Parameters
namename of the JSON field
[out]u16where to store the integer found under name

Definition at line 738 of file json_helper.c.

740{
742 .parser = &parse_u16,
743 .field = name,
744 .ptr = u16,
745 .ptr_size = sizeof(uint16_t),
746 };
747
748 return ret;
749}
static enum GNUNET_GenericReturnValue parse_u16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint16_t.
Definition: json_helper.c:714

References name, parse_u16(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_uint32()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32 ( const char *  name,
uint32_t *  u32 
)

32-bit integer.

Parameters
namename of the JSON field
[out]u32where to store the integer found under name

Definition at line 785 of file json_helper.c.

787{
789 .parser = &parse_u32,
790 .field = name,
791 .ptr = u32,
792 .ptr_size = sizeof(uint32_t),
793 };
794
795 return ret;
796}
static enum GNUNET_GenericReturnValue parse_u32(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint32_t.
Definition: json_helper.c:761

References name, parse_u32(), and ret.

Referenced by parse_blinded_sig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_uint()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint ( const char *  name,
unsigned int *  ui 
)

Unsigned integer.

Parameters
namename of the JSON field
[out]uiwhere to store the integer found under name

Definition at line 832 of file json_helper.c.

834{
836 .parser = &parse_ui,
837 .field = name,
838 .ptr = ui,
839 .ptr_size = sizeof(unsigned int),
840 };
841
842 return ret;
843}
static enum GNUNET_GenericReturnValue parse_ui(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to an unsigned int.
Definition: json_helper.c:808

References name, parse_ui(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_ull()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_ull ( const char *  name,
unsigned long long *  ull 
)

Unsigned long long.

Parameters
namename of the JSON field
[out]ullwhere to store the unsigned long long found under name

Definition at line 879 of file json_helper.c.

881{
883 .parser = &parse_ull,
884 .field = name,
885 .ptr = ull,
886 .ptr_size = sizeof(unsigned long long),
887 };
888
889 return ret;
890}
static enum GNUNET_GenericReturnValue parse_ull(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to an unsigned long long.
Definition: json_helper.c:855

References name, parse_ull(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_uint64()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64 ( const char *  name,
uint64_t *  u64 
)

64-bit integer.

Parameters
namename of the JSON field
[out]u64where to store the integer found under name

Definition at line 921 of file json_helper.c.

923{
925 .parser = &parse_u64,
926 .field = name,
927 .ptr = u64,
928 .ptr_size = sizeof(uint64_t),
929 };
930
931 return ret;
932}
static enum GNUNET_GenericReturnValue parse_u64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint64_t.
Definition: json_helper.c:902

References name, parse_u64(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_int16()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_int16 ( const char *  name,
int16_t *  i16 
)

16-bit signed integer.

Parameters
namename of the JSON field
[out]i16where to store the integer found under name

Definition at line 969 of file json_helper.c.

971{
973 .parser = &parse_i16,
974 .field = name,
975 .ptr = i16,
976 .ptr_size = sizeof(int16_t),
977 };
978
979 return ret;
980}
static enum GNUNET_GenericReturnValue parse_i16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int16_t.
Definition: json_helper.c:944

References name, parse_i16(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_int64()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64 ( const char *  name,
int64_t *  i64 
)

64-bit signed integer.

Parameters
namename of the JSON field
[out]i64where to store the integer found under name

Definition at line 1011 of file json_helper.c.

1013{
1015 .parser = &parse_i64,
1016 .field = name,
1017 .ptr = i64,
1018 .ptr_size = sizeof(int64_t),
1019 };
1020
1021 return ret;
1022}
static enum GNUNET_GenericReturnValue parse_i64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int64_t.
Definition: json_helper.c:992

References name, parse_i64(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_boolean()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_boolean ( const char *  name,
int *  boolean 
)

Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO).

Parameters
namename of the JSON field
[out]booleanwhere to store the boolean found under name

Definition at line 1415 of file json_helper.c.

1417{
1419 .parser = &parse_boolean,
1420 .field = name,
1421 .ptr = boolean,
1422 .ptr_size = sizeof(int),
1423 };
1424
1425 return ret;
1426}
static enum GNUNET_GenericReturnValue parse_boolean(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to an int as a boolean.
Definition: json_helper.c:1398

References name, parse_boolean(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_timestamp()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp ( const char *  name,
struct GNUNET_TIME_Timestamp t 
)

Timestamp.

Parameters
namename of the JSON field
[out]tat where to store the absolute time found under name

Definition at line 1087 of file json_helper.c.

1089{
1091 .parser = &parse_timestamp,
1092 .field = name,
1093 .ptr = t,
1094 .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
1095 };
1096
1097 return ret;
1098}
static struct GNUNET_SCHEDULER_Task * t
Main task.
static enum GNUNET_GenericReturnValue parse_timestamp(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a timestamp.
Definition: json_helper.c:1036
Time for timestamps used by GNUnet, in microseconds rounded to seconds.

References name, parse_timestamp(), ret, and t.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_timestamp_nbo()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo ( const char *  name,
struct GNUNET_TIME_TimestampNBO tn 
)

Timestamp in network byte order.

Parameters
namename of the JSON field
[out]tnwhere to store the absolute time found under name

Definition at line 1132 of file json_helper.c.

1134{
1136 .parser = &parse_timestamp_nbo,
1137 .field = name,
1138 .ptr = at,
1139 .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
1140 };
1141
1142 return ret;
1143}
static enum GNUNET_GenericReturnValue parse_timestamp_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:1110
Time for timestamps used by GNUnet, in seconds and in network byte order.

References name, parse_timestamp_nbo(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_relative_time()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time ( const char *  name,
struct GNUNET_TIME_Relative rt 
)

Relative time.

Parameters
namename of the JSON field
[out]rtwhere to store the relative time found under name

Definition at line 1202 of file json_helper.c.

1204{
1206 .parser = &parse_rel_time,
1207 .field = name,
1208 .ptr = rt,
1209 .ptr_size = sizeof(struct GNUNET_TIME_Relative)
1210 };
1211
1212 return ret;
1213}
static enum GNUNET_GenericReturnValue parse_rel_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to relative time.
Definition: json_helper.c:1155
Time for relative time used by GNUnet, in microseconds.

References name, parse_rel_time(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_rsa_public_key()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_public_key ( const char *  name,
struct GNUNET_CRYPTO_RsaPublicKey **  pk 
)

Specification for parsing an RSA public key.

Parameters
namename of the JSON field
pkwhere to store the RSA key found under name

Definition at line 1286 of file json_helper.c.

1288{
1290 .parser = &parse_rsa_public_key,
1291 .cleaner = &clean_rsa_public_key,
1292 .field = name,
1293 .ptr = pk
1294 };
1295
1296 *pk = NULL;
1297 return ret;
1298}
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static void clean_rsa_public_key(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_helper.c:1272
static enum GNUNET_GenericReturnValue parse_rsa_public_key(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA public key.
Definition: json_helper.c:1225

References clean_rsa_public_key(), name, parse_rsa_public_key(), pk, and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_rsa_signature()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature ( const char *  name,
struct GNUNET_CRYPTO_RsaSignature **  sig 
)

Specification for parsing an RSA signature.

Parameters
namename of the JSON field
sigwhere to store the RSA signature found under name

Definition at line 1371 of file json_helper.c.

1373{
1375 .parser = &parse_rsa_signature,
1376 .cleaner = &clean_rsa_signature,
1377 .cls = NULL,
1378 .field = name,
1379 .ptr = sig,
1380 .ptr_size = 0,
1381 .size_ptr = NULL
1382 };
1383
1384 *sig = NULL;
1385 return ret;
1386}
static enum GNUNET_GenericReturnValue parse_rsa_signature(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA signature.
Definition: json_helper.c:1310
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:1357

References clean_rsa_signature(), name, parse_rsa_signature(), and ret.

Referenced by parse_blinded_sig(), and parse_unblinded_sig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_blinded_message()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_message ( const char *  name,
struct GNUNET_CRYPTO_BlindedMessage **  msg 
)

Specification for parsing a blinded message.

Parameters
namename of the JSON field
sigwhere to store the blinded message found under name

Definition at line 1552 of file json_helper.c.

1554{
1556 .parser = &parse_blinded_message,
1557 .cleaner = &clean_blinded_message,
1558 .cls = NULL,
1559 .field = name,
1560 .ptr = msg,
1561 .ptr_size = 0,
1562 .size_ptr = NULL
1563 };
1564
1565 *msg = NULL;
1566 return ret;
1567}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static enum GNUNET_GenericReturnValue parse_blinded_message(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a blinded message.
Definition: json_helper.c:1438
static void clean_blinded_message(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded message.
Definition: json_helper.c:1537

References clean_blinded_message(), msg, name, parse_blinded_message(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_blinded_signature()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_signature ( const char *  field,
struct GNUNET_CRYPTO_BlindedSignature **  b_sig 
)

Specification for parsing a blinded signature.

Parameters
namename of the JSON field
sigwhere to store the blinded signature found under name

Definition at line 1687 of file json_helper.c.

1690{
1692 .parser = &parse_blinded_sig,
1693 .cleaner = &clean_blinded_sig,
1694 .field = field,
1695 .ptr = b_sig
1696 };
1697
1698 *b_sig = NULL;
1699 return ret;
1700}
static enum GNUNET_GenericReturnValue parse_blinded_sig(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a blinded signature.
Definition: json_helper.c:1579
static void clean_blinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded sig.
Definition: json_helper.c:1671

References clean_blinded_sig(), GNUNET_JSON_Specification::field, parse_blinded_sig(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_unblinded_signature()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_unblinded_signature ( const char *  field,
struct GNUNET_CRYPTO_UnblindedSignature **  ub_sig 
)

Specification for parsing an unblinded signature.

Parameters
namename of the JSON field
sigwhere to store the unblinded signature found under name

Definition at line 1820 of file json_helper.c.

1823{
1825 .parser = &parse_unblinded_sig,
1826 .cleaner = &clean_unblinded_sig,
1827 .field = field,
1828 .ptr = ub_sig
1829 };
1830
1831 *ub_sig = NULL;
1832 return ret;
1833}
static void clean_unblinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing unblinded signature.
Definition: json_helper.c:1805
static enum GNUNET_GenericReturnValue parse_unblinded_sig(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to unblinded signature.
Definition: json_helper.c:1712

References clean_unblinded_sig(), GNUNET_JSON_Specification::field, parse_unblinded_sig(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_from_data()

json_t * GNUNET_JSON_from_data ( const void *  data,
size_t  size 
)

Convert binary data to a JSON string with the base32crockford encoding.

Parameters
databinary data
sizesize of data in bytes
Returns
json string that encodes data

Definition at line 31 of file json_generator.c.

33{
34 char *buf;
35 json_t *json;
36
37 if (size >= ( (GNUNET_MAX_MALLOC_CHECKED - 1) * 5) - 4 / 8)
38 {
39 GNUNET_break (0);
40 return NULL;
41 }
43 size);
44 json = json_string (buf);
45 GNUNET_free (buf);
46 GNUNET_break (NULL != json);
47 return json;
48}
static char * data
The data to insert into the dht.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:791

References data, GNUNET_break, GNUNET_free, GNUNET_MAX_MALLOC_CHECKED, GNUNET_STRINGS_data_to_string_alloc(), and size.

Referenced by GNUNET_JSON_from_rsa_public_key(), GNUNET_JSON_from_rsa_signature(), and GNUNET_JSON_pack_data_varsize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_from_data64()

json_t * GNUNET_JSON_from_data64 ( const void *  data,
size_t  size 
)

Convert binary data to a JSON string with base64 encoding.

Parameters
databinary data
sizesize of data in bytes
Returns
json string that encodes data

Definition at line 52 of file json_generator.c.

54{
55 char *buf = NULL;
56 json_t *json;
57 size_t len;
58
59 if (size >= ( ( (GNUNET_MAX_MALLOC_CHECKED - 1) * 6) - 5) / 8)
60 {
61 GNUNET_break (0);
62 return NULL;
63 }
65 size,
66 &buf);
67 if (NULL == buf)
68 {
69 GNUNET_break (0);
70 return NULL;
71 }
72 json = json_stringn (buf,
73 len);
74 GNUNET_free (buf);
75 GNUNET_break (NULL != json);
76 return json;
77}
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1602

References data, GNUNET_break, GNUNET_free, GNUNET_MAX_MALLOC_CHECKED, GNUNET_STRINGS_base64_encode(), and size.

Referenced by GNUNET_JSON_pack_data64_varsize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_from_timestamp()

json_t * GNUNET_JSON_from_timestamp ( struct GNUNET_TIME_Timestamp  stamp)

Convert timestamp to a json string.

Parameters
stampthe time stamp
Returns
a json string with the timestamp in stamp

Definition at line 81 of file json_generator.c.

82{
83 json_t *j;
84
85 j = json_object ();
86 if (NULL == j)
87 {
88 GNUNET_break (0);
89 return NULL;
90 }
92 {
93 if (0 !=
94 json_object_set_new (j,
95 "t_s",
96 json_string ("never")))
97 {
98 GNUNET_break (0);
99 json_decref (j);
100 return NULL;
101 }
102 return j;
103 }
105 0 ==
107 % GNUNET_TIME_UNIT_SECONDS.rel_value_us));
108 if (0 !=
109 json_object_set_new (
110 j,
111 "t_s",
112 json_integer (
113 (json_int_t) (stamp.abs_time.abs_value_us
114 / GNUNET_TIME_UNIT_SECONDS.rel_value_us))))
115 {
116 GNUNET_break (0);
117 json_decref (j);
118 return NULL;
119 }
120 return j;
121}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_SECONDS
One second.
bool GNUNET_TIME_absolute_is_never(struct GNUNET_TIME_Absolute abs)
Test if abs is never.
Definition: time.c:650
uint64_t abs_value_us
The actual value.
struct GNUNET_TIME_Absolute abs_time
The actual value.

References GNUNET_TIME_Timestamp::abs_time, GNUNET_TIME_Absolute::abs_value_us, GNUNET_assert, GNUNET_break, GNUNET_TIME_absolute_is_never(), and GNUNET_TIME_UNIT_SECONDS.

Referenced by GNUNET_JSON_from_timestamp_nbo(), and GNUNET_JSON_pack_timestamp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_from_timestamp_nbo()

json_t * GNUNET_JSON_from_timestamp_nbo ( struct GNUNET_TIME_TimestampNBO  stamp)

Convert timestamp to a json string.

Parameters
stampthe time stamp
Returns
a json string with the timestamp in stamp

Definition at line 125 of file json_generator.c.

126{
128}
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_ntoh(struct GNUNET_TIME_TimestampNBO tn)
Convert timestamp from network byte order.
Definition: time.c:101
json_t * GNUNET_JSON_from_timestamp(struct GNUNET_TIME_Timestamp stamp)
Convert timestamp to a json string.

References GNUNET_JSON_from_timestamp(), and GNUNET_TIME_timestamp_ntoh().

Here is the call graph for this function:

◆ GNUNET_JSON_from_time_rel()

json_t * GNUNET_JSON_from_time_rel ( struct GNUNET_TIME_Relative  stamp)

Convert relative timestamp to a json string.

Parameters
stampthe time stamp
Returns
a json string with the timestamp in stamp

Definition at line 132 of file json_generator.c.

133{
134 json_t *j;
135
136 j = json_object ();
137 if (NULL == j)
138 {
139 GNUNET_break (0);
140 return NULL;
141 }
143 {
144 if (0 !=
145 json_object_set_new (j,
146 "d_us",
147 json_string ("forever")))
148 {
149 GNUNET_break (0);
150 json_decref (j);
151 return NULL;
152 }
153 return j;
154 }
155 if (stamp.rel_value_us >= (1LLU << 53))
156 {
157 /* value is larger than allowed */
158 GNUNET_break (0);
159 return NULL;
160 }
161 if (0 !=
162 json_object_set_new (
163 j,
164 "d_us",
165 json_integer ((json_int_t) stamp.rel_value_us)))
166 {
167 GNUNET_break (0);
168 json_decref (j);
169 return NULL;
170 }
171 return j;
172}
bool GNUNET_TIME_relative_is_forever(struct GNUNET_TIME_Relative rel)
Test if rel is forever.
Definition: time.c:657
uint64_t rel_value_us
The actual value.

References GNUNET_break, GNUNET_TIME_relative_is_forever(), and GNUNET_TIME_Relative::rel_value_us.

Referenced by GNUNET_JSON_pack_time_rel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_from_rsa_public_key()

json_t * GNUNET_JSON_from_rsa_public_key ( const struct GNUNET_CRYPTO_RsaPublicKey pk)

Convert RSA public key to JSON.

Parameters
pkpublic key to convert
Returns
corresponding JSON encoding

Definition at line 176 of file json_generator.c.

177{
178 void *buf;
179 size_t buf_len;
180 json_t *ret;
181
183 &buf);
185 buf_len);
186 GNUNET_free (buf);
187 return ret;
188}
size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, void **buffer)
Encode the public key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:325
json_t * GNUNET_JSON_from_data(const void *data, size_t size)
Convert binary data to a JSON string with the base32crockford encoding.

References GNUNET_CRYPTO_rsa_public_key_encode(), GNUNET_free, GNUNET_JSON_from_data(), pk, and ret.

Referenced by GNUNET_JSON_pack_rsa_public_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_from_rsa_signature()

json_t * GNUNET_JSON_from_rsa_signature ( const struct GNUNET_CRYPTO_RsaSignature sig)

Convert RSA signature to JSON.

Parameters
sigsignature to convert
Returns
corresponding JSON encoding

Definition at line 192 of file json_generator.c.

193{
194 void *buf;
195 size_t buf_len;
196 json_t *ret;
197
199 &buf);
201 buf_len);
202 GNUNET_free (buf);
203 return ret;
204}
size_t GNUNET_CRYPTO_rsa_signature_encode(const struct GNUNET_CRYPTO_RsaSignature *sig, void **buffer)
Encode the given signature in a format suitable for storing it into a file.
Definition: crypto_rsa.c:1023

References GNUNET_CRYPTO_rsa_signature_encode(), GNUNET_free, GNUNET_JSON_from_data(), and ret.

Referenced by GNUNET_JSON_pack_rsa_signature().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_getopt()

struct GNUNET_GETOPT_CommandLineOption GNUNET_JSON_getopt ( char  shortName,
const char *  name,
const char *  argumentHelp,
const char *  description,
json_t **  json 
)

Allow user to specify a JSON input value.

Parameters
shortNameshort name of the option
namelong name of the option
argumentHelphelp text for the option argument
descriptionlong help text for the option
[out]valset to the JSON specified at the command line

Definition at line 147 of file json.c.

152{
155 .name = name,
156 .argumentHelp = argumentHelp,
157 .description = description,
158 .require_argument = 1,
159 .processor = &set_json,
160 .scls = (void *) json
161 };
162
163 return clo;
164}
static enum GNUNET_GenericReturnValue set_json(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option with a JSON value from the command line.
Definition: json.c:122
Definition of a command line option.
const char * description
Help text for the option (description)
const char * argumentHelp
Name of the argument for the user in help text.
const char shortName
Short name of the option.

References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_json(), and GNUNET_GETOPT_CommandLineOption::shortName.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_()

json_t * GNUNET_JSON_pack_ ( struct GNUNET_JSON_PackSpec  spec[])

Pack a JSON object from a spec.

Aborts if packing fails.

Parameters
specspecification object
Returns
JSON object

Definition at line 29 of file json_pack.c.

30{
31 json_t *ret;
32
33 if (NULL == spec[0].field_name)
34 {
35 ret = spec[0].object;
36 spec[0].object = NULL;
37 return ret;
38 }
39 ret = json_object ();
40 GNUNET_assert (NULL != ret);
41 for (unsigned int i = 0;
42 ! spec[i].final;
43 i++)
44 {
45 if (NULL == spec[i].object)
46 {
47 if (! spec[i].allow_null)
48 {
50 "NULL not allowed for `%s'\n",
51 spec[i].field_name);
52 GNUNET_assert (0);
53 }
54 }
55 else
56 {
57 if (NULL == spec[i].field_name)
58 GNUNET_assert (0 ==
59 json_object_update_new (ret,
60 spec[i].object));
61 else
62 GNUNET_assert (0 ==
63 json_object_set_new (ret,
64 spec[i].field_name,
65 spec[i].object));
66
67 spec[i].object = NULL;
68 }
69 }
70 return ret;
71}
@ GNUNET_ERROR_TYPE_ERROR
json_t * object
Object to pack.
bool final
True if last element in the spec array.

References GNUNET_JSON_PackSpec::final, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_JSON_PackSpec::object, and ret.

◆ GNUNET_JSON_pack_end_()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_end_ ( void  )

Do not use directly.

Use GNUNET_JSON_PACK.

Returns
array terminator

Definition at line 75 of file json_pack.c.

76{
77 struct GNUNET_JSON_PackSpec ps = {
78 .final = true
79 };
80
81 return ps;
82}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.

References ps.

◆ GNUNET_JSON_pack_allow_null()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_allow_null ( struct GNUNET_JSON_PackSpec  in)

Modify packer instruction to allow NULL as a value.

Parameters
injson pack specification to modify
Returns
json pack specification

Definition at line 86 of file json_pack.c.

87{
88 in.allow_null = true;
89 return in;
90}
bool allow_null
True if a NULL (or 0) argument is allowed.

References GNUNET_JSON_PackSpec::allow_null.

◆ GNUNET_JSON_pack_bool()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_bool ( const char *  name,
bool  b 
)

Generate packer instruction for a JSON field of type bool.

Parameters
namename of the field to add to the object
bboolean value
Returns
json pack specification

Definition at line 94 of file json_pack.c.

96{
97 struct GNUNET_JSON_PackSpec ps = {
98 .field_name = name,
99 .object = json_boolean (b)
100 };
101
102 GNUNET_assert (NULL != name);
103 return ps;
104}

References GNUNET_assert, name, and ps.

◆ GNUNET_JSON_pack_double()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_double ( const char *  name,
double  f 
)

Generate packer instruction for a JSON field of type double.

Parameters
namename of the field to add to the object
fdouble value
Returns
json pack specification

Definition at line 108 of file json_pack.c.

110{
111 struct GNUNET_JSON_PackSpec ps = {
112 .field_name = name,
113 .object = json_real (f)
114 };
115
116 GNUNET_assert (NULL != name);
117 return ps;
118}

References GNUNET_assert, name, and ps.

◆ GNUNET_JSON_pack_string()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_string ( const char *  name,
const char *  s 
)

Generate packer instruction for a JSON field of type string.

Parameters
namename of the field to add to the object
sstring value
Returns
json pack specification

Definition at line 122 of file json_pack.c.

124{
125 struct GNUNET_JSON_PackSpec ps = {
126 .field_name = name,
127 .object = json_string (s)
128 };
129
130 GNUNET_assert (NULL != name);
131 return ps;
132}

References GNUNET_assert, name, and ps.

Referenced by GNUNET_JSON_pack_blinded_message(), GNUNET_JSON_pack_blinded_sig(), and GNUNET_JSON_pack_unblinded_signature().

Here is the caller graph for this function:

◆ GNUNET_JSON_pack_uint64()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_uint64 ( const char *  name,
uint64_t  num 
)

Generate packer instruction for a JSON field of type unsigned integer.

Note that the maximum allowed value is still limited by JSON and not UINT64_MAX.

Parameters
namename of the field to add to the object
numnumeric value
Returns
json pack specification

Definition at line 136 of file json_pack.c.

138{
139 struct GNUNET_JSON_PackSpec ps = {
140 .field_name = name,
141 .object = json_integer ((json_int_t) num)
142 };
143
144 GNUNET_assert (NULL != name);
145#if JSON_INTEGER_IS_LONG_LONG
146 GNUNET_assert (num <= LLONG_MAX);
147#else
148 GNUNET_assert (num <= LONG_MAX);
149#endif
150 return ps;
151}

References GNUNET_assert, name, and ps.

Referenced by GNUNET_JSON_pack_blinded_sig().

Here is the caller graph for this function:

◆ GNUNET_JSON_pack_int64()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_int64 ( const char *  name,
int64_t  num 
)

Generate packer instruction for a JSON field of type signed integer.

Parameters
namename of the field to add to the object
numnumeric value
Returns
json pack specification

Definition at line 155 of file json_pack.c.

157{
158 struct GNUNET_JSON_PackSpec ps = {
159 .field_name = name,
160 .object = json_integer ((json_int_t) num)
161 };
162
163 GNUNET_assert (NULL != name);
164#if JSON_INTEGER_IS_LONG_LONG
165 GNUNET_assert (num <= LLONG_MAX);
166 GNUNET_assert (num >= LLONG_MIN);
167#else
168 GNUNET_assert (num <= LONG_MAX);
169 GNUNET_assert (num >= LONG_MIN);
170#endif
171 return ps;
172}

References GNUNET_assert, name, and ps.

◆ GNUNET_JSON_pack_object_steal()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_steal ( const char *  name,
json_t *  o 
)

Generate packer instruction for a JSON field of type JSON object where the reference is taken over by the packer.

Parameters
namename of the field to add to the object, if NULL, the keys of o will be placed in the top level of the resulting object
oobject to steal
Returns
json pack specification

Definition at line 176 of file json_pack.c.

178{
179 struct GNUNET_JSON_PackSpec ps = {
180 .field_name = name,
181 .object = o
182 };
183
184 if (NULL == o)
185 return ps;
186 if (! json_is_object (o))
187 {
189 "Expected JSON object for field `%s'\n",
190 name);
191 GNUNET_assert (0);
192 }
193 return ps;
194}

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.

Referenced by GNUNET_JSON_pack_time_rel().

Here is the caller graph for this function:

◆ GNUNET_JSON_pack_object_incref()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_incref ( const char *  name,
json_t *  o 
)

Generate packer instruction for a JSON field of type JSON object where the reference counter is incremented by the packer.

Note that a deep copy is not performed.

Parameters
namename of the field to add to the object, if NULL, the keys of o will be placed in the top level of the resulting object
oobject to increment reference counter of
Returns
json pack specification

Definition at line 198 of file json_pack.c.

200{
201 struct GNUNET_JSON_PackSpec ps = {
202 .field_name = name,
203 .object = o
204 };
205
206 if (NULL == o)
207 return ps;
208 (void) json_incref (o);
209 if (! json_is_object (o))
210 {
212 "Expected JSON object for field `%s'\n",
213 name);
214 GNUNET_assert (0);
215 }
216 return ps;
217}

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.

◆ GNUNET_JSON_pack_array_steal()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_steal ( const char *  name,
json_t *  a 
)

Generate packer instruction for a JSON field of type JSON array where the reference is taken over by the packer.

Parameters
namename of the field to add to the object
aarray to steal
Returns
json pack specification

Definition at line 221 of file json_pack.c.

223{
224 struct GNUNET_JSON_PackSpec ps = {
225 .field_name = name,
226 .object = a
227 };
228
229 GNUNET_assert (NULL != name);
230 if (NULL == a)
231 return ps;
232 if (! json_is_array (a))
233 {
235 "Expected JSON array for field `%s'\n",
236 name);
237 GNUNET_assert (0);
238 }
239 return ps;
240}

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.

◆ GNUNET_JSON_pack_array_incref()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_incref ( const char *  name,
json_t *  a 
)

Generate packer instruction for a JSON field of type JSON array where the reference counter is incremented by the packer.

Note that a deep copy is not performed.

Parameters
namename of the field to add to the object
aarray to increment reference counter of
Returns
json pack specification

Definition at line 244 of file json_pack.c.

246{
247 struct GNUNET_JSON_PackSpec ps = {
248 .field_name = name,
249 .object = a
250 };
251
252 GNUNET_assert (NULL != name);
253 if (NULL == a)
254 return ps;
255 (void) json_incref (a);
256 if (! json_is_array (a))
257 {
259 "Expected JSON array for field `%s'\n",
260 name);
261 GNUNET_assert (0);
262 }
263 return ps;
264}

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.

◆ GNUNET_JSON_pack_data_varsize()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data_varsize ( const char *  name,
const void *  blob,
size_t  blob_size 
)

Generate packer instruction for a JSON field of type variable size binary blob.

Parameters
namename of the field to add to the object
blobbinary data to pack
blob_sizenumber of bytes in blob
Returns
json pack specification

Definition at line 268 of file json_pack.c.

271{
272 struct GNUNET_JSON_PackSpec ps = {
273 .field_name = name,
274 .object = (NULL != blob)
275 ? GNUNET_JSON_from_data (blob,
276 blob_size)
277 : NULL
278 };
279
280 GNUNET_assert (NULL != name);
281 return ps;
282}
json_t * GNUNET_JSON_from_data(const void *data, size_t size)
Convert binary data to a JSON string with the base32crockford encoding.

References GNUNET_assert, GNUNET_JSON_from_data(), name, and ps.

Referenced by GNUNET_JSON_pack_blinded_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_pack_data64_varsize()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data64_varsize ( const char *  name,
const void *  blob,
size_t  blob_size 
)

Generate packer instruction for a JSON field of type variable size binary blob.

Use base64-encoding, instead of the more common Crockford base32-encoding.

Parameters
namename of the field to add to the object
blobbinary data to pack
blob_sizenumber of bytes in blob
Returns
json pack specification

Definition at line 286 of file json_pack.c.

289{
290 struct GNUNET_JSON_PackSpec ps = {
291 .field_name = name,
292 .object = (NULL != blob)
294 blob_size)
295 : NULL
296 };
297
298 GNUNET_assert (NULL != name);
299 return ps;
300}
json_t * GNUNET_JSON_from_data64(const void *data, size_t size)
Convert binary data to a JSON string with base64 encoding.

References GNUNET_assert, GNUNET_JSON_from_data64(), name, and ps.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_timestamp()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp ( const char *  name,
struct GNUNET_TIME_Timestamp  at 
)

Generate packer instruction for a JSON field of type timestamp.

Parameters
namename of the field to add to the object
attimestamp pack, a value of 0 is only allowed with GNUNET_JSON_pack_allow_null()!
Returns
json pack specification

Definition at line 304 of file json_pack.c.

306{
307 struct GNUNET_JSON_PackSpec ps = {
308 .field_name = name
309 };
310
311 GNUNET_assert (NULL != name);
312 if (! GNUNET_TIME_absolute_is_zero (t.abs_time))
313 {
315 GNUNET_assert (NULL != ps.object);
316 }
317 else
318 {
319 ps.object = NULL;
320 }
321 return ps;
322}
json_t * GNUNET_JSON_from_timestamp(struct GNUNET_TIME_Timestamp stamp)
Convert timestamp to a json string.
bool GNUNET_TIME_absolute_is_zero(struct GNUNET_TIME_Absolute abs)
Test if abs is truly zero.
Definition: time.c:848

References GNUNET_assert, GNUNET_JSON_from_timestamp(), GNUNET_TIME_absolute_is_zero(), name, ps, and t.

Referenced by GNUNET_JSON_pack_timestamp_nbo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_pack_timestamp_nbo()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp_nbo ( const char *  name,
struct GNUNET_TIME_TimestampNBO  at 
)

Generate packer instruction for a JSON field of type timestamp in network byte order.

Parameters
namename of the field to add to the object
attimestamp to pack, a value of 0 is only allowed with GNUNET_JSON_pack_allow_null()!
Returns
json pack specification

Definition at line 326 of file json_pack.c.

328{
331}
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp(const char *name, struct GNUNET_TIME_Timestamp t)
Generate packer instruction for a JSON field of type timestamp.
Definition: json_pack.c:304

References GNUNET_JSON_pack_timestamp(), GNUNET_TIME_timestamp_ntoh(), and name.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_time_rel()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel ( const char *  name,
struct GNUNET_TIME_Relative  rt 
)

Generate packer instruction for a JSON field of type relative time.

Parameters
namename of the field to add to the object
rtrelative time to pack
Returns
json pack specification

Definition at line 335 of file json_pack.c.

337{
338 json_t *json;
339
340 GNUNET_assert (NULL != name);
341 json = GNUNET_JSON_from_time_rel (rt);
342 GNUNET_assert (NULL != json);
344 json);
345}
json_t * GNUNET_JSON_from_time_rel(struct GNUNET_TIME_Relative stamp)
Convert relative timestamp to a json string.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_steal(const char *name, json_t *o)
Generate packer instruction for a JSON field of type JSON object where the reference is taken over by...
Definition: json_pack.c:176

References GNUNET_assert, GNUNET_JSON_from_time_rel(), GNUNET_JSON_pack_object_steal(), and name.

Referenced by GNUNET_JSON_pack_time_rel_nbo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_pack_time_rel_nbo()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel_nbo ( const char *  name,
struct GNUNET_TIME_RelativeNBO  rt 
)

Generate packer instruction for a JSON field of type relative time in network byte order.

Parameters
namename of the field to add to the object
rtrelative time to pack
Returns
json pack specification

Definition at line 349 of file json_pack.c.

351{
354}
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:630
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel(const char *name, struct GNUNET_TIME_Relative rt)
Generate packer instruction for a JSON field of type relative time.
Definition: json_pack.c:335

References GNUNET_JSON_pack_time_rel(), GNUNET_TIME_relative_ntoh(), and name.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_rsa_public_key()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_public_key ( const char *  name,
const struct GNUNET_CRYPTO_RsaPublicKey pk 
)

Generate packer instruction for a JSON field of type RSA public key.

Parameters
namename of the field to add to the object
pkRSA public key
Returns
json pack specification

Definition at line 358 of file json_pack.c.

360{
361 struct GNUNET_JSON_PackSpec ps = {
362 .field_name = name,
364 };
365
366 return ps;
367}
json_t * GNUNET_JSON_from_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *pk)
Convert RSA public key to JSON.

References GNUNET_JSON_from_rsa_public_key(), name, pk, and ps.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_rsa_signature()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_signature ( const char *  name,
const struct GNUNET_CRYPTO_RsaSignature sig 
)

Generate packer instruction for a JSON field of type RSA signature.

Parameters
namename of the field to add to the object
sigRSA signature
Returns
json pack specification

Definition at line 371 of file json_pack.c.

373{
374 struct GNUNET_JSON_PackSpec ps = {
375 .field_name = name,
376 .object = GNUNET_JSON_from_rsa_signature (sig)
377 };
378
379 return ps;
380}
json_t * GNUNET_JSON_from_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *sig)
Convert RSA signature to JSON.

References GNUNET_JSON_from_rsa_signature(), name, and ps.

Referenced by GNUNET_JSON_pack_blinded_sig(), and GNUNET_JSON_pack_unblinded_signature().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_pack_unblinded_signature()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_unblinded_signature ( const char *  name,
const struct GNUNET_CRYPTO_UnblindedSignature sig 
)

Generate packer instruction for a JSON field of type unblinded signature.

Parameters
namename of the field to add to the object
sigunblinded signature
Returns
json pack specification

Definition at line 384 of file json_pack.c.

387{
388 struct GNUNET_JSON_PackSpec ps = {
389 .field_name = name
390 };
391
392 if (NULL == sig)
393 return ps;
394
395 switch (sig->cipher)
396 {
398 break;
400 ps.object = GNUNET_JSON_PACK (
401 GNUNET_JSON_pack_string ("cipher",
402 "RSA"),
403 GNUNET_JSON_pack_rsa_signature ("rsa_signature",
404 sig->details.rsa_signature));
405 return ps;
407 ps.object = GNUNET_JSON_PACK (
408 GNUNET_JSON_pack_string ("cipher",
409 "CS"),
410 GNUNET_JSON_pack_data_auto ("cs_signature_r",
412 GNUNET_JSON_pack_data_auto ("cs_signature_s",
414 return ps;
415 }
416 GNUNET_assert (0);
417 return ps;
418}
#define GNUNET_JSON_PACK(...)
Pack a JSON object from a spec.
#define GNUNET_JSON_pack_data_auto(name, blob)
Generate packer instruction for a JSON field where the size is automatically determined from the argu...
@ GNUNET_CRYPTO_BSA_INVALID
Invalid type of signature.
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_signature(const char *name, const struct GNUNET_CRYPTO_RsaSignature *sig)
Generate packer instruction for a JSON field of type RSA signature.
Definition: json_pack.c:371
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_string(const char *name, const char *s)
Generate packer instruction for a JSON field of type string.
Definition: json_pack.c:122
struct GNUNET_CRYPTO_CsS s_scalar
Schnorr signatures are composed of a scalar s and a curve point.
struct GNUNET_CRYPTO_CsRPublic r_point
Curve point of the Schnorr signature.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
union GNUNET_CRYPTO_UnblindedSignature::@14 details
Details, depending on cipher.
struct GNUNET_CRYPTO_CsSignature cs_signature
If we use GNUNET_CRYPTO_BSA_CS in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.

References GNUNET_assert, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_JSON_PACK, GNUNET_JSON_pack_data_auto, GNUNET_JSON_pack_rsa_signature(), GNUNET_JSON_pack_string(), name, and ps.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_blinded_message()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_message ( const char *  name,
const struct GNUNET_CRYPTO_BlindedMessage msg 
)

Generate packer instruction for a JSON field of type blinded message.

Parameters
namename of the field to add to the object
msgblinded message
Returns
json pack specification

Definition at line 422 of file json_pack.c.

425{
426 struct GNUNET_JSON_PackSpec ps = {
427 .field_name = name,
428 };
429
430 switch (msg->cipher)
431 {
433 break;
435 ps.object = GNUNET_JSON_PACK (
436 GNUNET_JSON_pack_string ("cipher",
437 "RSA"),
439 "rsa_blinded_planchet",
440 msg->details.rsa_blinded_message.blinded_msg,
441 msg->details.rsa_blinded_message.blinded_msg_size));
442 return ps;
444 ps.object = GNUNET_JSON_PACK (
445 GNUNET_JSON_pack_string ("cipher",
446 "CS"),
448 "cs_nonce",
449 &msg->details.cs_blinded_message.nonce),
451 "cs_blinded_c0",
452 &msg->details.cs_blinded_message.c[0]),
454 "cs_blinded_c1",
455 &msg->details.cs_blinded_message.c[1]));
456 return ps;
457 }
458 GNUNET_assert (0);
459 return ps;
460}
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data_varsize(const char *name, const void *blob, size_t blob_size)
Generate packer instruction for a JSON field of type variable size binary blob.
Definition: json_pack.c:268

References GNUNET_assert, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_JSON_PACK, GNUNET_JSON_pack_data_auto, GNUNET_JSON_pack_data_varsize(), GNUNET_JSON_pack_string(), msg, name, and ps.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_blinded_sig()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_sig ( const char *  name,
const struct GNUNET_CRYPTO_BlindedSignature sig 
)

Generate packer instruction for a JSON field of type blinded signature.

Parameters
namename of the field to add to the object
sigblinded signature
Returns
json pack specification

Definition at line 464 of file json_pack.c.

467{
468 struct GNUNET_JSON_PackSpec ps = {
469 .field_name = name,
470 };
471
472 if (NULL == sig)
473 return ps;
474 switch (sig->cipher)
475 {
477 break;
479 ps.object = GNUNET_JSON_PACK (
480 GNUNET_JSON_pack_string ("cipher",
481 "RSA"),
482 GNUNET_JSON_pack_rsa_signature ("blinded_rsa_signature",
484 return ps;
486 ps.object = GNUNET_JSON_PACK (
487 GNUNET_JSON_pack_string ("cipher",
488 "CS"),
493 return ps;
494 }
495 GNUNET_assert (0);
496 return ps;
497}
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_uint64(const char *name, uint64_t num)
Generate packer instruction for a JSON field of type unsigned integer.
Definition: json_pack.c:136
struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer
If we use GNUNET_CRYPTO_BSA_CS in cipher.
union GNUNET_CRYPTO_BlindedSignature::@15 details
Details, depending on cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
struct GNUNET_CRYPTO_RsaSignature * blinded_rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
struct GNUNET_CRYPTO_CsBlindS s_scalar
The blinded s scalar calculated from c_b.
unsigned int b
To make ROS problem harder, the signer chooses an unpredictable b and only calculates signature of c_...

References GNUNET_assert, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_JSON_PACK, GNUNET_JSON_pack_data_auto, GNUNET_JSON_pack_rsa_signature(), GNUNET_JSON_pack_string(), GNUNET_JSON_pack_uint64(), name, and ps.

Here is the call graph for this function: