GNUnet 0.22.2
json_helper.c File Reference

functions to generate specifciations for JSON parsing More...

#include "platform.h"
#include "gnunet_json_lib.h"
#include "gnunet_common.h"
Include dependency graph for json_helper.c:

Go to the source code of this file.

Functions

struct GNUNET_JSON_Specification GNUNET_JSON_spec_end ()
 End of a parser specification. More...
 
static enum GNUNET_CRYPTO_BlindSignatureAlgorithm string_to_cipher (const char *cipher_s)
 Convert string value to numeric cipher value. More...
 
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. 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...
 
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. 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...
 
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. More...
 
static void clean_variable_data (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing variable size data. 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...
 
static enum GNUNET_GenericReturnValue parse_string (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to string. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string (const char *name, const char **strptr)
 The expected field stores a string. More...
 
static enum GNUNET_GenericReturnValue parse_json (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a JSON object. More...
 
static void clean_json (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing JSON object. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json (const char *name, json_t **jsonp)
 JSON object or array. More...
 
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. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const (const char *name, const json_t **jsonp)
 JSON object, reference counter not incremented. More...
 
static enum GNUNET_GenericReturnValue parse_array_const (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON to a JSON array. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const (const char *name, const json_t **jsonp)
 JSON array, reference counter not incremented. More...
 
static enum GNUNET_GenericReturnValue parse_bool (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a bool. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool (const char *name, bool *b)
 boolean. More...
 
static enum GNUNET_GenericReturnValue parse_double (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a double. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_double (const char *name, double *f)
 double. More...
 
static enum GNUNET_GenericReturnValue parse_u8 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint8_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8)
 8-bit integer. More...
 
static enum GNUNET_GenericReturnValue parse_u16 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint16_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16)
 16-bit integer. More...
 
static enum GNUNET_GenericReturnValue parse_u32 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint32_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32)
 32-bit integer. More...
 
static enum GNUNET_GenericReturnValue parse_u64 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint64_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64)
 64-bit integer. More...
 
static enum GNUNET_GenericReturnValue parse_i64 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a int64_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64 (const char *name, int64_t *i64)
 64-bit signed integer. More...
 
static enum GNUNET_GenericReturnValue parse_timestamp (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a timestamp. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp (const char *name, struct GNUNET_TIME_Timestamp *t)
 Timestamp. More...
 
static enum GNUNET_GenericReturnValue parse_timestamp_nbo (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to absolute time. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *at)
 Timestamp in network byte order. More...
 
static enum GNUNET_GenericReturnValue parse_rel_time (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to relative time. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt)
 Relative time. More...
 
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. More...
 
static void clean_rsa_public_key (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA public key. 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...
 
static enum GNUNET_GenericReturnValue parse_rsa_signature (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to RSA signature. More...
 
static void clean_rsa_signature (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA signature. 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...
 
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. 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...
 
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. More...
 
static void clean_blinded_message (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing blinded message. 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...
 
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. More...
 
static void clean_blinded_sig (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing blinded sig. 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...
 
static enum GNUNET_GenericReturnValue parse_unblinded_sig (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to unblinded signature. More...
 
static void clean_unblinded_sig (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing unblinded 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...
 

Detailed Description

functions to generate specifciations for JSON parsing

Author
Florian Dold
Benedikt Mueller
Christian Grothoff

Definition in file json_helper.c.

Function Documentation

◆ 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 .cleaner = NULL,
38 .cls = NULL
39 };
40
41 return ret;
42}
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:

◆ string_to_cipher()

static enum GNUNET_CRYPTO_BlindSignatureAlgorithm string_to_cipher ( const char *  cipher_s)
static

Convert string value to numeric cipher value.

Parameters
cipher_sinput string
Returns
numeric cipher value

Definition at line 52 of file json_helper.c.

53{
54 if ((0 == strcasecmp (cipher_s,
55 "RSA")) ||
56 (0 == strcasecmp (cipher_s,
57 "RSA+age_restricted")))
59 if ((0 == strcasecmp (cipher_s,
60 "CS")) ||
61 (0 == strcasecmp (cipher_s,
62 "CS+age_restricted")))
65}
@ GNUNET_CRYPTO_BSA_INVALID
Invalid type of signature.
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.

References GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, and GNUNET_CRYPTO_BSA_RSA.

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

Here is the caller graph for this function:

◆ parse_fixed_data()

static enum GNUNET_GenericReturnValue parse_fixed_data ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to fixed size data.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 77 of file json_helper.c.

80{
81 const char *enc;
82 size_t len;
83
84 if (NULL == (enc = json_string_value (root)))
85 {
87 return GNUNET_SYSERR;
88 }
89 len = strlen (enc);
90 if (len >= SIZE_MAX / 5)
91 {
93 return GNUNET_SYSERR;
94 }
95 if (((len * 5) / 8) != spec->ptr_size)
96 {
99 "Field `%s' has wrong length\n",
100 spec->field);
101 return GNUNET_SYSERR;
102 }
103 if (GNUNET_OK !=
105 len,
106 spec->ptr,
107 spec->ptr_size))
108 {
109 GNUNET_break_op (0);
110 return GNUNET_SYSERR;
111 }
112 return GNUNET_OK;
113}
static OpusEncoder * enc
OPUS encoder.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_WARNING
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:812
#define SIZE_MAX
Definition: platform.h:208
void * ptr
Pointer, details specific to the parser.
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...
size_t ptr_size
Number of bytes available in ptr.

References enc, GNUNET_JSON_Specification::field, GNUNET_break_op, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, GNUNET_JSON_Specification::ptr_size, and SIZE_MAX.

Referenced by GNUNET_JSON_spec_fixed().

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

◆ 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 117 of file json_helper.c.

120{
122 .parser = &parse_fixed_data,
123 .cleaner = NULL,
124 .cls = NULL,
125 .field = name,
126 .ptr = obj,
127 .ptr_size = size,
128 .size_ptr = NULL
129 };
130
131 return ret;
132}
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:77
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:

◆ parse_fixed64_data()

static enum GNUNET_GenericReturnValue parse_fixed64_data ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to fixed size data.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 144 of file json_helper.c.

147{
148 const char *enc;
149 unsigned int len;
150 void *output;
151 size_t olen;
152
153 if (NULL == (enc = json_string_value (root)))
154 {
155 GNUNET_break_op (0);
156 return GNUNET_SYSERR;
157 }
158 len = strlen (enc);
159 output = NULL;
161 len,
162 &output);
163 if (olen != spec->ptr_size)
164 {
165 GNUNET_break_op (0);
167 "Field `%s' has wrong length\n",
168 spec->field);
169 GNUNET_free (output);
170 return GNUNET_SYSERR;
171 }
172 memcpy (spec->ptr,
173 output,
174 olen);
175 GNUNET_free (output);
176 return GNUNET_OK;
177}
#define GNUNET_free(ptr)
Wrapper around free.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1701

References enc, GNUNET_JSON_Specification::field, GNUNET_break_op, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_STRINGS_base64_decode(), GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, and GNUNET_JSON_Specification::ptr_size.

Referenced by GNUNET_JSON_spec_fixed64().

Here is the call graph for this function:
Here is the caller 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 181 of file json_helper.c.

184{
186 .parser = &parse_fixed64_data,
187 .cleaner = NULL,
188 .cls = NULL,
189 .field = name,
190 .ptr = obj,
191 .ptr_size = size,
192 .size_ptr = NULL
193 };
194
195 return ret;
196}
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:144

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

Here is the call graph for this function:

◆ parse_variable_data()

static enum GNUNET_GenericReturnValue parse_variable_data ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to variable size data.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 208 of file json_helper.c.

211{
212 const char *str;
213 size_t size;
214 void *data;
215
216 str = json_string_value (root);
217 if (NULL == str)
218 {
219 GNUNET_break_op (0);
220 return GNUNET_SYSERR;
221 }
222 if (GNUNET_OK !=
224 strlen (str),
225 &data,
226 &size))
227 {
228 GNUNET_break_op (0);
229 return GNUNET_SYSERR;
230 }
231 *(void **) spec->ptr = data;
232 *spec->size_ptr = size;
233 return GNUNET_OK;
234}
static char * data
The data to insert into the dht.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data_alloc(const char *enc, size_t enclen, void **out, size_t *out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:878
size_t * size_ptr
Where should we store the final size of ptr.

References data, GNUNET_break_op, GNUNET_OK, GNUNET_STRINGS_string_to_data_alloc(), GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, size, and GNUNET_JSON_Specification::size_ptr.

Referenced by GNUNET_JSON_spec_varsize().

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

◆ clean_variable_data()

static void clean_variable_data ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing variable size data.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 244 of file json_helper.c.

246{
247 (void) cls;
248 if (0 != *spec->size_ptr)
249 {
250 GNUNET_free (*(void **) spec->ptr);
251 *(void **) spec->ptr = NULL;
252 *spec->size_ptr = 0;
253 }
254}

References GNUNET_JSON_Specification::cls, GNUNET_free, GNUNET_JSON_Specification::ptr, and GNUNET_JSON_Specification::size_ptr.

Referenced by GNUNET_JSON_spec_varsize().

Here is the caller 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 258 of file json_helper.c.

261{
263 .parser = &parse_variable_data,
264 .cleaner = &clean_variable_data,
265 .cls = NULL,
266 .field = name,
267 .ptr = obj,
268 .ptr_size = 0,
269 .size_ptr = size
270 };
271
272 *obj = NULL;
273 *size = 0;
274 return ret;
275}
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:244
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:208

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:

◆ parse_string()

static enum GNUNET_GenericReturnValue parse_string ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to string.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 287 of file json_helper.c.

290{
291 const char *str;
292
293 (void) cls;
294 str = json_string_value (root);
295 if (NULL == str)
296 {
297 GNUNET_break_op (0);
298 return GNUNET_SYSERR;
299 }
300 *(const char **) spec->ptr = str;
301 return GNUNET_OK;
302}

References GNUNET_JSON_Specification::cls, GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_string().

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 306 of file json_helper.c.

308{
310 .parser = &parse_string,
311 .field = name,
312 .ptr = strptr
313 };
314
315 *strptr = NULL;
316 return ret;
317}
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:287

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:

◆ parse_json()

static enum GNUNET_GenericReturnValue parse_json ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a JSON object.

(Yes, trivial.)

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 329 of file json_helper.c.

332{
333 if (! (json_is_object (root) || json_is_array (root)))
334 {
335 GNUNET_break_op (0);
336 return GNUNET_SYSERR;
337 }
338 json_incref (root);
339 *(json_t **) spec->ptr = root;
340 return GNUNET_OK;
341}

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_json().

Here is the caller graph for this function:

◆ clean_json()

static void clean_json ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing JSON object.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 351 of file json_helper.c.

353{
354 json_t **ptr = (json_t **) spec->ptr;
355
356 if (NULL != *ptr)
357 {
358 json_decref (*ptr);
359 *ptr = NULL;
360 }
361}

References GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_json().

Here is the caller 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 365 of file json_helper.c.

367{
369 .parser = &parse_json,
370 .cleaner = &clean_json,
371 .cls = NULL,
372 .field = name,
373 .ptr = jsonp,
374 .ptr_size = 0,
375 .size_ptr = NULL
376 };
377
378 *jsonp = NULL;
379 return ret;
380}
static void clean_json(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:351
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:329

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

Here is the call graph for this function:

◆ parse_object_const()

static enum GNUNET_GenericReturnValue parse_object_const ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a JSON object.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 392 of file json_helper.c.

395{
396 if (NULL == root)
397 return GNUNET_OK;
398 if (! json_is_object (root))
399 {
400 GNUNET_break_op (0);
401 return GNUNET_SYSERR;
402 }
403 *(const json_t **) spec->ptr = (const json_t *) root;
404 return GNUNET_OK;
405}

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_object_const().

Here is the caller 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 409 of file json_helper.c.

411{
413 .parser = &parse_object_const,
414 .cls = NULL,
415 .field = name,
416 .ptr = jsonp,
417 .ptr_size = 0,
418 .size_ptr = NULL
419 };
420
421 *jsonp = NULL;
422 return ret;
423}
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:392

References name, parse_object_const(), and ret.

Here is the call graph for this function:

◆ parse_array_const()

static enum GNUNET_GenericReturnValue parse_array_const ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON to a JSON array.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 435 of file json_helper.c.

438{
439 if (NULL == root)
440 return GNUNET_OK;
441 if (! json_is_array (root))
442 {
443 GNUNET_break_op (0);
444 return GNUNET_SYSERR;
445 }
446 *(const json_t **) spec->ptr = (const json_t *) root;
447 return GNUNET_OK;
448}

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_array_const().

Here is the caller 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 452 of file json_helper.c.

454{
456 .parser = &parse_array_const,
457 .cls = NULL,
458 .field = name,
459 .ptr = jsonp,
460 .ptr_size = 0,
461 .size_ptr = NULL
462 };
463
464 *jsonp = NULL;
465 return ret;
466}
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:435

References name, parse_array_const(), and ret.

Here is the call graph for this function:

◆ parse_bool()

static enum GNUNET_GenericReturnValue parse_bool ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a bool.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 478 of file json_helper.c.

481{
482 bool *b = spec->ptr;
483
484 if (json_true () == root)
485 {
486 *b = true;
487 return GNUNET_OK;
488 }
489 if (json_false () == root)
490 {
491 *b = false;
492 return GNUNET_OK;
493 }
494 GNUNET_break_op (0);
495 return GNUNET_SYSERR;
496}

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_bool().

Here is the caller 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 500 of file json_helper.c.

502{
504 .parser = &parse_bool,
505 .cleaner = NULL,
506 .cls = NULL,
507 .field = name,
508 .ptr = b,
509 .ptr_size = sizeof(bool),
510 .size_ptr = NULL
511 };
512
513 return ret;
514}
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:478

References name, parse_bool(), ret, and GNUNET_JSON_Specification::size_ptr.

Here is the call graph for this function:

◆ parse_double()

static enum GNUNET_GenericReturnValue parse_double ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a double.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 526 of file json_helper.c.

529{
530 double *f = spec->ptr;
531
532 if (! json_is_real (root))
533 {
534 GNUNET_break_op (0);
535 return GNUNET_SYSERR;
536 }
537 *f = json_real_value (root);
538 return GNUNET_OK;
539}

References removetrailingwhitespace::f, GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_double().

Here is the caller 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 543 of file json_helper.c.

545{
547 .parser = &parse_double,
548 .cleaner = NULL,
549 .cls = NULL,
550 .field = name,
551 .ptr = f,
552 .ptr_size = sizeof(double),
553 .size_ptr = NULL
554 };
555
556 return ret;
557}
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:526

References removetrailingwhitespace::f, name, parse_double(), ret, and GNUNET_JSON_Specification::size_ptr.

Here is the call graph for this function:

◆ parse_u8()

static enum GNUNET_GenericReturnValue parse_u8 ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a uint8_t.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 569 of file json_helper.c.

572{
573 json_int_t val;
574 uint8_t *up = spec->ptr;
575
576 if (! json_is_integer (root))
577 {
578 GNUNET_break_op (0);
579 return GNUNET_SYSERR;
580 }
581 val = json_integer_value (root);
582 if ((0 > val) || (val > UINT8_MAX))
583 {
584 GNUNET_break_op (0);
585 return GNUNET_SYSERR;
586 }
587 *up = (uint8_t) val;
588 return GNUNET_OK;
589}

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_uint8().

Here is the caller 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 593 of file json_helper.c.

595{
597 .parser = &parse_u8,
598 .cleaner = NULL,
599 .cls = NULL,
600 .field = name,
601 .ptr = u8,
602 .ptr_size = sizeof(uint8_t),
603 .size_ptr = NULL
604 };
605
606 return ret;
607}
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:569

References name, parse_u8(), ret, and GNUNET_JSON_Specification::size_ptr.

Here is the call graph for this function:

◆ parse_u16()

static enum GNUNET_GenericReturnValue parse_u16 ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a uint16_t.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 619 of file json_helper.c.

622{
623 json_int_t val;
624 uint16_t *up = spec->ptr;
625
626 if (! json_is_integer (root))
627 {
628 GNUNET_break_op (0);
629 return GNUNET_SYSERR;
630 }
631 val = json_integer_value (root);
632 if ((0 > val) || (val > UINT16_MAX))
633 {
634 GNUNET_break_op (0);
635 return GNUNET_SYSERR;
636 }
637 *up = (uint16_t) val;
638 return GNUNET_OK;
639}

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_uint16().

Here is the caller 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 643 of file json_helper.c.

645{
647 .parser = &parse_u16,
648 .cleaner = NULL,
649 .cls = NULL,
650 .field = name,
651 .ptr = u16,
652 .ptr_size = sizeof(uint16_t),
653 .size_ptr = NULL
654 };
655
656 return ret;
657}
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:619

References name, parse_u16(), ret, and GNUNET_JSON_Specification::size_ptr.

Here is the call graph for this function:

◆ parse_u32()

static enum GNUNET_GenericReturnValue parse_u32 ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a uint32_t.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 669 of file json_helper.c.

672{
673 json_int_t val;
674 uint32_t *up = spec->ptr;
675
676 if (! json_is_integer (root))
677 {
678 GNUNET_break_op (0);
679 return GNUNET_SYSERR;
680 }
681 val = json_integer_value (root);
682 if ((0 > val) || (val > UINT32_MAX))
683 {
684 GNUNET_break_op (0);
685 return GNUNET_SYSERR;
686 }
687 *up = (uint32_t) val;
688 return GNUNET_OK;
689}

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_uint32().

Here is the caller 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 693 of file json_helper.c.

695{
697 .parser = &parse_u32,
698 .cleaner = NULL,
699 .cls = NULL,
700 .field = name,
701 .ptr = u32,
702 .ptr_size = sizeof(uint32_t),
703 .size_ptr = NULL
704 };
705
706 return ret;
707}
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:669

References name, parse_u32(), ret, and GNUNET_JSON_Specification::size_ptr.

Referenced by parse_blinded_sig().

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

◆ parse_u64()

static enum GNUNET_GenericReturnValue parse_u64 ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a uint64_t.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 719 of file json_helper.c.

722{
723 json_int_t val;
724 uint64_t *up = spec->ptr;
725
726 if (! json_is_integer (root))
727 {
728 GNUNET_break_op (0);
729 return GNUNET_SYSERR;
730 }
731 val = json_integer_value (root);
732 *up = (uint64_t) val;
733 return GNUNET_OK;
734}

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_uint64().

Here is the caller 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 738 of file json_helper.c.

740{
742 .parser = &parse_u64,
743 .cleaner = NULL,
744 .cls = NULL,
745 .field = name,
746 .ptr = u64,
747 .ptr_size = sizeof(uint64_t),
748 .size_ptr = NULL
749 };
750
751 return ret;
752}
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:719

References name, parse_u64(), ret, and GNUNET_JSON_Specification::size_ptr.

Here is the call graph for this function:

◆ parse_i64()

static enum GNUNET_GenericReturnValue parse_i64 ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a int64_t.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 764 of file json_helper.c.

767{
768 json_int_t val;
769 int64_t *up = spec->ptr;
770
771 if (! json_is_integer (root))
772 {
773 GNUNET_break_op (0);
774 return GNUNET_SYSERR;
775 }
776 val = json_integer_value (root);
777 *up = (int64_t) val;
778 return GNUNET_OK;
779}

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_int64().

Here is the caller 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 783 of file json_helper.c.

785{
787 .parser = &parse_i64,
788 .cleaner = NULL,
789 .cls = NULL,
790 .field = name,
791 .ptr = i64,
792 .ptr_size = sizeof(int64_t),
793 .size_ptr = NULL
794 };
795
796 return ret;
797}
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:764

References name, parse_i64(), ret, and GNUNET_JSON_Specification::size_ptr.

Here is the call graph for this function:

◆ parse_timestamp()

static enum GNUNET_GenericReturnValue parse_timestamp ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a timestamp.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 811 of file json_helper.c.

814{
815 struct GNUNET_TIME_Timestamp *ts = spec->ptr;
816 json_t *json_t_s;
817 unsigned long long int tval;
818
819 if (! json_is_object (root))
820 {
821 GNUNET_break_op (0);
822 return GNUNET_SYSERR;
823 }
824 json_t_s = json_object_get (root,
825 "t_s");
826 if (json_is_integer (json_t_s))
827 {
828 tval = json_integer_value (json_t_s);
829 /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
831 = tval * GNUNET_TIME_UNIT_SECONDS.rel_value_us;
832 if (ts->abs_time.abs_value_us
833 / GNUNET_TIME_UNIT_SECONDS.rel_value_us
834 != tval)
835 {
836 /* Integer overflow */
837 GNUNET_break_op (0);
838 return GNUNET_SYSERR;
839 }
840 return GNUNET_OK;
841 }
842 if (json_is_string (json_t_s))
843 {
844 const char *val;
845
846 val = json_string_value (json_t_s);
847 if ((0 == strcasecmp (val,
848 "never")))
849 {
851 return GNUNET_OK;
852 }
853 GNUNET_break_op (0);
854 return GNUNET_SYSERR;
855 }
856 GNUNET_break_op (0);
857 return GNUNET_SYSERR;
858}
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
uint64_t abs_value_us
The actual value.
Time for timestamps used by GNUnet, in microseconds rounded to seconds.
struct GNUNET_TIME_Absolute abs_time
The actual value.

References GNUNET_TIME_Timestamp::abs_time, GNUNET_TIME_Absolute::abs_value_us, GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_SECONDS, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_timestamp(), and parse_timestamp_nbo().

Here is the caller 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 862 of file json_helper.c.

864{
866 .parser = &parse_timestamp,
867 .field = name,
868 .ptr = t,
869 .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
870 };
871
872 return ret;
873}
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:811

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

Here is the call graph for this function:

◆ parse_timestamp_nbo()

static enum GNUNET_GenericReturnValue parse_timestamp_nbo ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to absolute time.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 885 of file json_helper.c.

888{
889 struct GNUNET_TIME_TimestampNBO *ts = spec->ptr;
890 struct GNUNET_TIME_Timestamp a;
891 struct GNUNET_JSON_Specification ispec;
892
893 ispec = *spec;
894 ispec.parser = &parse_timestamp;
895 ispec.ptr = &a;
896 if (GNUNET_OK !=
897 parse_timestamp (NULL,
898 root,
899 &ispec))
900 return GNUNET_SYSERR;
902 return GNUNET_OK;
903}
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:91
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.
Time for timestamps used by GNUnet, in seconds and in network byte order.

References GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_timestamp_hton(), parse_timestamp(), GNUNET_JSON_Specification::parser, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_timestamp_nbo().

Here is the call graph for this function:
Here is the caller 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 907 of file json_helper.c.

909{
911 .parser = &parse_timestamp_nbo,
912 .field = name,
913 .ptr = at,
914 .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
915 };
916
917 return ret;
918}
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:885

References name, parse_timestamp_nbo(), and ret.

Here is the call graph for this function:

◆ parse_rel_time()

static enum GNUNET_GenericReturnValue parse_rel_time ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to relative time.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 930 of file json_helper.c.

933{
934 struct GNUNET_TIME_Relative *rel = spec->ptr;
935 json_t *json_d_us;
936 unsigned long long int tval;
937
938 if (! json_is_object (root))
939 {
940 GNUNET_break_op (0);
941 return GNUNET_SYSERR;
942 }
943 json_d_us = json_object_get (root,
944 "d_us");
945 if (json_is_integer (json_d_us))
946 {
947 tval = json_integer_value (json_d_us);
948 if (tval >= (1LLU << 53))
949 {
950 /* value is larger than allowed */
951 GNUNET_break_op (0);
952 return GNUNET_SYSERR;
953 }
954 rel->rel_value_us = tval;
955 return GNUNET_OK;
956 }
957 if (json_is_string (json_d_us))
958 {
959 const char *val;
960
961 val = json_string_value (json_d_us);
962 if ((0 == strcasecmp (val,
963 "forever")))
964 {
966 return GNUNET_OK;
967 }
968 GNUNET_break_op (0);
969 return GNUNET_SYSERR;
970 }
971 GNUNET_break_op (0);
972 return GNUNET_SYSERR;
973}
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_JSON_Specification::ptr, and GNUNET_TIME_Relative::rel_value_us.

Referenced by GNUNET_JSON_spec_relative_time().

Here is the caller 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 977 of file json_helper.c.

979{
981 .parser = &parse_rel_time,
982 .field = name,
983 .ptr = rt,
984 .ptr_size = sizeof(struct GNUNET_TIME_Relative)
985 };
986
987 return ret;
988}
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:930

References name, parse_rel_time(), and ret.

Here is the call graph for this function:

◆ parse_rsa_public_key()

static enum GNUNET_GenericReturnValue parse_rsa_public_key ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to RSA public key.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 1000 of file json_helper.c.

1003{
1004 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
1005 const char *enc;
1006 char *buf;
1007 size_t len;
1008 size_t buf_len;
1009
1010 if (NULL == (enc = json_string_value (root)))
1011 {
1012 GNUNET_break_op (0);
1013 return GNUNET_SYSERR;
1014 }
1015 len = strlen (enc);
1016 buf_len = (len * 5) / 8;
1017 buf = GNUNET_malloc (buf_len);
1018 if (GNUNET_OK !=
1020 len,
1021 buf,
1022 buf_len))
1023 {
1024 GNUNET_break_op (0);
1025 GNUNET_free (buf);
1026 return GNUNET_SYSERR;
1027 }
1028 if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
1029 buf_len)))
1030 {
1031 GNUNET_break_op (0);
1032 GNUNET_free (buf);
1033 return GNUNET_SYSERR;
1034 }
1035 GNUNET_free (buf);
1036 return GNUNET_OK;
1037}
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_public_key_decode(const char *buf, size_t len)
Decode the public key from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:423
#define GNUNET_malloc(size)
Wrapper around malloc.
The public information of an RSA key pair.
Definition: crypto_rsa.c:53

References enc, GNUNET_break_op, GNUNET_CRYPTO_rsa_public_key_decode(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, pk, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_rsa_public_key().

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

◆ clean_rsa_public_key()

static void clean_rsa_public_key ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing RSA public key.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 1047 of file json_helper.c.

1049{
1050 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
1051
1052 if (NULL != *pk)
1053 {
1055 *pk = NULL;
1056 }
1057}
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:268

References GNUNET_CRYPTO_rsa_public_key_free(), pk, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_rsa_public_key().

Here is the call graph for this function:
Here is the caller 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 1061 of file json_helper.c.

1063{
1065 .parser = &parse_rsa_public_key,
1066 .cleaner = &clean_rsa_public_key,
1067 .field = name,
1068 .ptr = pk
1069 };
1070
1071 *pk = NULL;
1072 return ret;
1073}
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:1047
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:1000

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

Here is the call graph for this function:

◆ parse_rsa_signature()

static enum GNUNET_GenericReturnValue parse_rsa_signature ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to RSA signature.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 1085 of file json_helper.c.

1088{
1089 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1090 size_t size;
1091 const char *str;
1092 int res;
1093 void *buf;
1094
1095 str = json_string_value (root);
1096 if (NULL == str)
1097 {
1098 GNUNET_break_op (0);
1099 return GNUNET_SYSERR;
1100 }
1101 size = (strlen (str) * 5) / 8;
1102 buf = GNUNET_malloc (size);
1104 strlen (str),
1105 buf,
1106 size);
1107 if (GNUNET_OK != res)
1108 {
1109 GNUNET_free (buf);
1110 GNUNET_break_op (0);
1111 return GNUNET_SYSERR;
1112 }
1113 if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
1114 size)))
1115 {
1116 GNUNET_break_op (0);
1117 GNUNET_free (buf);
1118 return GNUNET_SYSERR;
1119 }
1120 GNUNET_free (buf);
1121 return GNUNET_OK;
1122}
static char * res
Currently read line or NULL on EOF.
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode(const void *buf, size_t buf_size)
Decode the signature from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:1063
an RSA signature
Definition: crypto_rsa.c:65

References GNUNET_break_op, GNUNET_CRYPTO_rsa_signature_decode(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, res, and size.

Referenced by GNUNET_JSON_spec_rsa_signature().

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

◆ clean_rsa_signature()

static void clean_rsa_signature ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing RSA signature.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 1132 of file json_helper.c.

1134{
1135 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1136
1137 if (NULL != *sig)
1138 {
1140 *sig = NULL;
1141 }
1142}
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:1015

References GNUNET_CRYPTO_rsa_signature_free(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_rsa_signature().

Here is the call graph for this function:
Here is the caller 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 1146 of file json_helper.c.

1148{
1150 .parser = &parse_rsa_signature,
1151 .cleaner = &clean_rsa_signature,
1152 .cls = NULL,
1153 .field = name,
1154 .ptr = sig,
1155 .ptr_size = 0,
1156 .size_ptr = NULL
1157 };
1158
1159 *sig = NULL;
1160 return ret;
1161}
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:1085
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:1132

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:

◆ parse_boolean()

static enum GNUNET_GenericReturnValue parse_boolean ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to an int as a boolean.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 1173 of file json_helper.c.

1176{
1177 int *bp = spec->ptr;
1178
1179 if (! json_is_boolean (root))
1180 {
1181 GNUNET_break_op (0);
1182 return GNUNET_SYSERR;
1183 }
1184 *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
1185 return GNUNET_OK;
1186}
@ GNUNET_YES
@ GNUNET_NO

References GNUNET_break_op, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_boolean().

Here is the caller 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 1190 of file json_helper.c.

1192{
1194 .parser = &parse_boolean,
1195 .cleaner = NULL,
1196 .cls = NULL,
1197 .field = name,
1198 .ptr = boolean,
1199 .ptr_size = sizeof(int),
1200 .size_ptr = NULL
1201 };
1202
1203 return ret;
1204}
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:1173

References consensus-simulation::int, name, parse_boolean(), ret, and GNUNET_JSON_Specification::size_ptr.

Here is the call graph for this function:

◆ parse_blinded_message()

static enum GNUNET_GenericReturnValue parse_blinded_message ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a blinded message.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 1216 of file json_helper.c.

1219{
1220 struct GNUNET_CRYPTO_BlindedMessage **target = spec->ptr;
1221 struct GNUNET_CRYPTO_BlindedMessage *blinded_message;
1222 const char *cipher;
1223 struct GNUNET_JSON_Specification dspec[] = {
1224 GNUNET_JSON_spec_string ("cipher",
1225 &cipher),
1227 };
1228 const char *emsg;
1229 unsigned int eline;
1230
1231 (void) cls;
1232 if (GNUNET_OK !=
1233 GNUNET_JSON_parse (root,
1234 dspec,
1235 &emsg,
1236 &eline))
1237 {
1238 GNUNET_break_op (0);
1239 return GNUNET_SYSERR;
1240 }
1241 blinded_message = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
1242 blinded_message->rc = 1;
1243 blinded_message->cipher = string_to_cipher (cipher);
1244 switch (blinded_message->cipher)
1245 {
1247 break;
1249 {
1250 struct GNUNET_JSON_Specification ispec[] = {
1252 /* TODO: Change this field name to something
1253 more generic / pass in as argument. */
1254 "rsa_blinded_planchet",
1255 &blinded_message->details.rsa_blinded_message.blinded_msg,
1256 &blinded_message->details.rsa_blinded_message.blinded_msg_size),
1258 };
1259
1260 if (GNUNET_OK !=
1261 GNUNET_JSON_parse (root,
1262 ispec,
1263 &emsg,
1264 &eline))
1265 {
1266 GNUNET_break_op (0);
1267 GNUNET_free (blinded_message);
1268 return GNUNET_SYSERR;
1269 }
1270 *target = blinded_message;
1271 return GNUNET_OK;
1272 }
1274 {
1275 struct GNUNET_JSON_Specification ispec[] = {
1277 "cs_nonce",
1278 &blinded_message->details.cs_blinded_message.nonce),
1280 "cs_blinded_c0",
1281 &blinded_message->details.cs_blinded_message.c[0]),
1283 "cs_blinded_c1",
1284 &blinded_message->details.cs_blinded_message.c[1]),
1286 };
1287
1288 if (GNUNET_OK !=
1289 GNUNET_JSON_parse (root,
1290 ispec,
1291 &emsg,
1292 &eline))
1293 {
1294 GNUNET_break_op (0);
1295 GNUNET_free (blinded_message);
1296 return GNUNET_SYSERR;
1297 }
1298 *target = blinded_message;
1299 return GNUNET_OK;
1300 }
1301 }
1302 GNUNET_break_op (0);
1303 GNUNET_free (blinded_message);
1304 return GNUNET_SYSERR;
1305}
#define GNUNET_JSON_spec_fixed_auto(name, obj)
Fixed size object (in network byte order, encoded using Crockford Base32hex encoding).
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.
Definition: json.c:32
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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).
Definition: json_helper.c:258
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end()
End of a parser specification.
Definition: json_helper.c:33
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string(const char *name, const char **strptr)
The expected field stores a string.
Definition: json_helper.c:306
static enum GNUNET_CRYPTO_BlindSignatureAlgorithm string_to_cipher(const char *cipher_s)
Convert string value to numeric cipher value.
Definition: json_helper.c:52
Blinded message ready for blind signing.
unsigned int rc
Reference counter.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the sign blinded message.
struct GNUNET_CRYPTO_CsBlindedMessage cs_blinded_message
If we use GNUNET_CRYPTO_BSA_CS in cipher.
union GNUNET_CRYPTO_BlindedMessage::@18 details
Details, depending on cipher.
struct GNUNET_CRYPTO_RsaBlindedMessage rsa_blinded_message
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
struct GNUNET_CRYPTO_CsC c[2]
The Clause Schnorr c_0 and c_1 containing the blinded message.
struct GNUNET_CRYPTO_CsSessionNonce nonce
Nonce used in initial request.
size_t blinded_msg_size
Size of the blinded_msg to be signed.
void * blinded_msg
Blinded message to be signed Note: is malloc()'ed!
void * cls
Closure for parser and cleaner.

References GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg, GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg_size, GNUNET_CRYPTO_CsBlindedMessage::c, GNUNET_CRYPTO_BlindedMessage::cipher, GNUNET_JSON_Specification::cls, GNUNET_CRYPTO_BlindedMessage::cs_blinded_message, GNUNET_CRYPTO_BlindedMessage::details, GNUNET_break_op, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_free, GNUNET_JSON_parse(), GNUNET_JSON_spec_end(), GNUNET_JSON_spec_fixed_auto, GNUNET_JSON_spec_string(), GNUNET_JSON_spec_varsize(), GNUNET_new, GNUNET_OK, GNUNET_SYSERR, GNUNET_CRYPTO_CsBlindedMessage::nonce, GNUNET_JSON_Specification::ptr, GNUNET_CRYPTO_BlindedMessage::rc, GNUNET_CRYPTO_BlindedMessage::rsa_blinded_message, and string_to_cipher().

Referenced by GNUNET_JSON_spec_blinded_message().

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

◆ clean_blinded_message()

static void clean_blinded_message ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing blinded message.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 1315 of file json_helper.c.

1317{
1318 struct GNUNET_CRYPTO_BlindedMessage **blinded_message = spec->ptr;
1319
1320 (void) cls;
1321 if (NULL != blinded_message)
1322 {
1323 GNUNET_CRYPTO_blinded_message_decref (*blinded_message);
1324 *blinded_message = NULL;
1325 }
1326}
void GNUNET_CRYPTO_blinded_message_decref(struct GNUNET_CRYPTO_BlindedMessage *bm)
Decrement reference counter of a bm, and free it if it reaches zero.

References GNUNET_CRYPTO_blinded_message_decref(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_blinded_message().

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 1330 of file json_helper.c.

1332{
1334 .parser = &parse_blinded_message,
1335 .cleaner = &clean_blinded_message,
1336 .cls = NULL,
1337 .field = name,
1338 .ptr = msg,
1339 .ptr_size = 0,
1340 .size_ptr = NULL
1341 };
1342
1343 *msg = NULL;
1344 return ret;
1345}
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:1216
static void clean_blinded_message(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded message.
Definition: json_helper.c:1315

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

Here is the call graph for this function:

◆ parse_blinded_sig()

static enum GNUNET_GenericReturnValue parse_blinded_sig ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a blinded signature.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 1357 of file json_helper.c.

1360{
1361 struct GNUNET_CRYPTO_BlindedSignature **target = spec->ptr;
1362 struct GNUNET_CRYPTO_BlindedSignature *blinded_sig;
1363 const char *cipher;
1364 struct GNUNET_JSON_Specification dspec[] = {
1365 GNUNET_JSON_spec_string ("cipher",
1366 &cipher),
1368 };
1369 const char *emsg;
1370 unsigned int eline;
1371
1372 (void) cls;
1373 if (GNUNET_OK !=
1374 GNUNET_JSON_parse (root,
1375 dspec,
1376 &emsg,
1377 &eline))
1378 {
1379 GNUNET_break_op (0);
1380 return GNUNET_SYSERR;
1381 }
1382 blinded_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
1383 blinded_sig->cipher = string_to_cipher (cipher);
1384 blinded_sig->rc = 1;
1385 switch (blinded_sig->cipher)
1386 {
1388 break;
1390 {
1391 struct GNUNET_JSON_Specification ispec[] = {
1393 "blinded_rsa_signature",
1394 &blinded_sig->details.blinded_rsa_signature),
1396 };
1397
1398 if (GNUNET_OK !=
1399 GNUNET_JSON_parse (root,
1400 ispec,
1401 &emsg,
1402 &eline))
1403 {
1404 GNUNET_break_op (0);
1405 GNUNET_free (blinded_sig);
1406 return GNUNET_SYSERR;
1407 }
1408 *target = blinded_sig;
1409 return GNUNET_OK;
1410 }
1412 {
1413 struct GNUNET_JSON_Specification ispec[] = {
1415 &blinded_sig->details.blinded_cs_answer.b),
1417 &blinded_sig->details.blinded_cs_answer.
1418 s_scalar),
1420 };
1421
1422 if (GNUNET_OK !=
1423 GNUNET_JSON_parse (root,
1424 ispec,
1425 &emsg,
1426 &eline))
1427 {
1428 GNUNET_break_op (0);
1429 GNUNET_free (blinded_sig);
1430 return GNUNET_SYSERR;
1431 }
1432 *target = blinded_sig;
1433 return GNUNET_OK;
1434 }
1435 }
1436 GNUNET_break_op (0);
1437 GNUNET_free (blinded_sig);
1438 return GNUNET_SYSERR;
1439}
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32(const char *name, uint32_t *u32)
32-bit integer.
Definition: json_helper.c:693
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature(const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
Specification for parsing an RSA signature.
Definition: json_helper.c:1146
Type for blinded signatures.
unsigned int rc
Reference counter.
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.
unsigned int b
To make ROS problem harder, the signer chooses an unpredictable b and only calculates signature of c_...

References GNUNET_CRYPTO_CsBlindSignature::b, GNUNET_CRYPTO_BlindedSignature::blinded_cs_answer, GNUNET_CRYPTO_BlindedSignature::blinded_rsa_signature, GNUNET_CRYPTO_BlindedSignature::cipher, GNUNET_JSON_Specification::cls, GNUNET_CRYPTO_BlindedSignature::details, GNUNET_break_op, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_free, GNUNET_JSON_parse(), GNUNET_JSON_spec_end(), GNUNET_JSON_spec_fixed_auto, GNUNET_JSON_spec_rsa_signature(), GNUNET_JSON_spec_string(), GNUNET_JSON_spec_uint32(), GNUNET_new, GNUNET_OK, GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, GNUNET_CRYPTO_BlindedSignature::rc, and string_to_cipher().

Referenced by GNUNET_JSON_spec_blinded_signature().

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

◆ clean_blinded_sig()

static void clean_blinded_sig ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing blinded sig.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 1449 of file json_helper.c.

1451{
1452 struct GNUNET_CRYPTO_BlindedSignature **b_sig = spec->ptr;
1453
1454 (void) cls;
1455
1456 if (NULL != *b_sig)
1457 {
1459 *b_sig = NULL;
1460 }
1461}
void GNUNET_CRYPTO_blinded_sig_decref(struct GNUNET_CRYPTO_BlindedSignature *blind_sig)
Decrement reference counter of a blind_sig, and free it if it reaches zero.

References GNUNET_CRYPTO_blinded_sig_decref(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_blinded_signature().

Here is the call graph for this function:
Here is the caller 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 1465 of file json_helper.c.

1468{
1470 .parser = &parse_blinded_sig,
1471 .cleaner = &clean_blinded_sig,
1472 .field = field,
1473 .ptr = b_sig
1474 };
1475
1476 *b_sig = NULL;
1477 return ret;
1478}
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:1357
static void clean_blinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded sig.
Definition: json_helper.c:1449

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

Here is the call graph for this function:

◆ parse_unblinded_sig()

static enum GNUNET_GenericReturnValue parse_unblinded_sig ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to unblinded signature.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 1490 of file json_helper.c.

1493{
1494 struct GNUNET_CRYPTO_UnblindedSignature **target = spec->ptr;
1495 struct GNUNET_CRYPTO_UnblindedSignature *unblinded_sig;
1496 const char *cipher;
1497 struct GNUNET_JSON_Specification dspec[] = {
1498 GNUNET_JSON_spec_string ("cipher",
1499 &cipher),
1501 };
1502 const char *emsg;
1503 unsigned int eline;
1504
1505 (void) cls;
1506 if (GNUNET_OK !=
1507 GNUNET_JSON_parse (root,
1508 dspec,
1509 &emsg,
1510 &eline))
1511 {
1512 GNUNET_break_op (0);
1513 return GNUNET_SYSERR;
1514 }
1515 unblinded_sig = GNUNET_new (struct GNUNET_CRYPTO_UnblindedSignature);
1516 unblinded_sig->cipher = string_to_cipher (cipher);
1517 unblinded_sig->rc = 1;
1518 switch (unblinded_sig->cipher)
1519 {
1521 break;
1523 {
1524 struct GNUNET_JSON_Specification ispec[] = {
1526 "rsa_signature",
1527 &unblinded_sig->details.rsa_signature),
1529 };
1530
1531 if (GNUNET_OK !=
1532 GNUNET_JSON_parse (root,
1533 ispec,
1534 &emsg,
1535 &eline))
1536 {
1537 GNUNET_break_op (0);
1538 GNUNET_free (unblinded_sig);
1539 return GNUNET_SYSERR;
1540 }
1541 *target = unblinded_sig;
1542 return GNUNET_OK;
1543 }
1545 {
1546 struct GNUNET_JSON_Specification ispec[] = {
1547 GNUNET_JSON_spec_fixed_auto ("cs_signature_r",
1548 &unblinded_sig->details.cs_signature.
1549 r_point),
1550 GNUNET_JSON_spec_fixed_auto ("cs_signature_s",
1551 &unblinded_sig->details.cs_signature.
1552 s_scalar),
1554 };
1555
1556 if (GNUNET_OK !=
1557 GNUNET_JSON_parse (root,
1558 ispec,
1559 &emsg,
1560 &eline))
1561 {
1562 GNUNET_break_op (0);
1563 GNUNET_free (unblinded_sig);
1564 return GNUNET_SYSERR;
1565 }
1566 *target = unblinded_sig;
1567 return GNUNET_OK;
1568 }
1569 }
1570 GNUNET_break_op (0);
1571 GNUNET_free (unblinded_sig);
1572 return GNUNET_SYSERR;
1573}
Type of (unblinded) signatures.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
unsigned int rc
Reference counter.
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_CRYPTO_UnblindedSignature::cipher, GNUNET_JSON_Specification::cls, GNUNET_CRYPTO_UnblindedSignature::cs_signature, GNUNET_CRYPTO_UnblindedSignature::details, GNUNET_break_op, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_free, GNUNET_JSON_parse(), GNUNET_JSON_spec_end(), GNUNET_JSON_spec_fixed_auto, GNUNET_JSON_spec_rsa_signature(), GNUNET_JSON_spec_string(), GNUNET_new, GNUNET_OK, GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, GNUNET_CRYPTO_UnblindedSignature::rc, GNUNET_CRYPTO_UnblindedSignature::rsa_signature, and string_to_cipher().

Referenced by GNUNET_JSON_spec_unblinded_signature().

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

◆ clean_unblinded_sig()

static void clean_unblinded_sig ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing unblinded signature.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 1583 of file json_helper.c.

1585{
1586 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig = spec->ptr;
1587
1588 (void) cls;
1589 if (NULL != *ub_sig)
1590 {
1592 *ub_sig = NULL;
1593 }
1594}
void GNUNET_CRYPTO_unblinded_sig_decref(struct GNUNET_CRYPTO_UnblindedSignature *ub_sig)
Decrement reference counter of a ub_sig, and free it if it reaches zero.

References GNUNET_CRYPTO_unblinded_sig_decref(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_unblinded_signature().

Here is the call graph for this function:
Here is the caller 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 1598 of file json_helper.c.

1601{
1603 .parser = &parse_unblinded_sig,
1604 .cleaner = &clean_unblinded_sig,
1605 .field = field,
1606 .ptr = ub_sig
1607 };
1608
1609 *ub_sig = NULL;
1610 return ret;
1611}
static void clean_unblinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing unblinded signature.
Definition: json_helper.c:1583
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:1490

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

Here is the call graph for this function: