GNUnet debian-0.26.1
 
Loading...
Searching...
No Matches
json_pack.c File Reference

functions to pack JSON objects More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_json_lib.h"
Include dependency graph for json_pack.c:

Go to the source code of this file.

Functions

json_t * GNUNET_JSON_pack_ (struct GNUNET_JSON_PackSpec spec[])
 Pack a JSON object from a spec.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_end_ (void)
 Do not use directly.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_allow_null (struct GNUNET_JSON_PackSpec in)
 Modify packer instruction to allow NULL as a value.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_bool (const char *name, bool b)
 Generate packer instruction for a JSON field of type bool.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_double (const char *name, double f)
 Generate packer instruction for a JSON field of type double.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_string (const char *name, const char *s)
 Generate packer instruction for a JSON field of type string.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rounder_interval (const char *name, enum GNUNET_TIME_RounderInterval ri)
 Generate packer instruction of a time rounder interval.
 

Detailed Description

functions to pack JSON objects

Author
Christian Grothoff

Definition in file json_pack.c.

Function Documentation

◆ 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 30 of file json_pack.c.

31{
32 json_t *ret;
33
34 if (NULL == spec[0].field_name)
35 {
36 ret = spec[0].object;
37 spec[0].object = NULL;
38 return ret;
39 }
40 ret = json_object ();
41 GNUNET_assert (NULL != ret);
42 for (unsigned int i = 0;
43 ! spec[i].final;
44 i++)
45 {
46 if (NULL == spec[i].object)
47 {
48 if (! spec[i].allow_null)
49 {
51 "NULL not allowed for `%s'\n",
52 spec[i].field_name);
53 GNUNET_assert (0);
54 }
55 }
56 else
57 {
58 if (NULL == spec[i].field_name)
59 GNUNET_assert (0 ==
60 json_object_update_new (ret,
61 spec[i].object));
62 else
63 GNUNET_assert (0 ==
64 json_object_set_new (ret,
65 spec[i].field_name,
66 spec[i].object));
67
68 spec[i].object = NULL;
69 }
70 }
71 return ret;
72}
static int ret
Final status code.
Definition gnunet-arm.c:93
#define GNUNET_log(kind,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ 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 76 of file json_pack.c.

77{
78 struct GNUNET_JSON_PackSpec ps = {
79 .final = true
80 };
81
82 return ps;
83}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
Element in the array to give to the packer.

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 87 of file json_pack.c.

88{
89 in.allow_null = true;
90 return in;
91}
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 95 of file json_pack.c.

97{
98 struct GNUNET_JSON_PackSpec ps = {
99 .field_name = name,
100 .object = json_boolean (b)
101 };
102
103 GNUNET_assert (NULL != name);
104 return ps;
105}
static char * name
Name (label) of the records to list.

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 109 of file json_pack.c.

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

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 123 of file json_pack.c.

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

References GNUNET_assert, name, and ps.

Referenced by GNUNET_JSON_pack_blinded_message(), GNUNET_JSON_pack_blinded_sig(), GNUNET_JSON_pack_time_rounder_interval(), 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 137 of file json_pack.c.

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

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 156 of file json_pack.c.

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

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 177 of file json_pack.c.

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

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 199 of file json_pack.c.

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

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 222 of file json_pack.c.

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

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 245 of file json_pack.c.

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

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 269 of file json_pack.c.

272{
273 struct GNUNET_JSON_PackSpec ps = {
274 .field_name = name,
275 .object = (NULL != blob)
276 ? GNUNET_JSON_from_data (blob,
277 blob_size)
278 : NULL
279 };
280
281 GNUNET_assert (NULL != name);
282 return ps;
283}
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 287 of file json_pack.c.

290{
291 struct GNUNET_JSON_PackSpec ps = {
292 .field_name = name,
293 .object = (NULL != blob)
295 blob_size)
296 : NULL
297 };
298
299 GNUNET_assert (NULL != name);
300 return ps;
301}
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 305 of file json_pack.c.

307{
308 struct GNUNET_JSON_PackSpec ps = {
309 .field_name = name
310 };
311
312 GNUNET_assert (NULL != name);
313 if (! GNUNET_TIME_absolute_is_zero (t.abs_time))
314 {
316 GNUNET_assert (NULL != ps.object);
317 }
318 else
319 {
320 ps.object = NULL;
321 }
322 return ps;
323}
static struct GNUNET_SCHEDULER_Task * t
Main task.
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:844

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 327 of file json_pack.c.

329{
332}
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_ntoh(struct GNUNET_TIME_TimestampNBO tn)
Convert timestamp from network byte order.
Definition time.c:101
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:305

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 336 of file json_pack.c.

338{
339 json_t *json;
340
341 GNUNET_assert (NULL != name);
342 json = GNUNET_JSON_from_time_rel (rt);
343 GNUNET_assert (NULL != json);
345 json);
346}
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:177

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 350 of file json_pack.c.

352{
355}
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition time.c:626
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:336

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 359 of file json_pack.c.

361{
362 struct GNUNET_JSON_PackSpec ps = {
363 .field_name = name,
365 };
366
367 return ps;
368}
struct GNUNET_CRYPTO_BlindablePrivateKey pk
Private key from command line option, or NULL.
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 372 of file json_pack.c.

374{
375 struct GNUNET_JSON_PackSpec ps = {
376 .field_name = name,
377 .object = GNUNET_JSON_from_rsa_signature (sig)
378 };
379
380 return ps;
381}
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 385 of file json_pack.c.

388{
389 struct GNUNET_JSON_PackSpec ps = {
390 .field_name = name
391 };
392
393 if (NULL == sig)
394 return ps;
395
396 switch (sig->cipher)
397 {
399 break;
401 ps.object = GNUNET_JSON_PACK (
402 GNUNET_JSON_pack_string ("cipher",
403 "RSA"),
404 GNUNET_JSON_pack_rsa_signature ("rsa_signature",
405 sig->details.rsa_signature));
406 return ps;
408 ps.object = GNUNET_JSON_PACK (
409 GNUNET_JSON_pack_string ("cipher",
410 "CS"),
411 GNUNET_JSON_pack_data_auto ("cs_signature_r",
413 GNUNET_JSON_pack_data_auto ("cs_signature_s",
415 return ps;
416 }
417 GNUNET_assert (0);
418 return ps;
419}
#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:372
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:123
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.
union GNUNET_CRYPTO_UnblindedSignature::@18 details
Details, depending on cipher.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in 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 423 of file json_pack.c.

426{
427 struct GNUNET_JSON_PackSpec ps = {
428 .field_name = name,
429 };
430
431 switch (msg->cipher)
432 {
434 break;
436 ps.object = GNUNET_JSON_PACK (
437 GNUNET_JSON_pack_string ("cipher",
438 "RSA"),
440 "rsa_blinded_planchet",
441 msg->details.rsa_blinded_message.blinded_msg,
442 msg->details.rsa_blinded_message.blinded_msg_size));
443 return ps;
445 ps.object = GNUNET_JSON_PACK (
446 GNUNET_JSON_pack_string ("cipher",
447 "CS"),
449 "cs_nonce",
450 &msg->details.cs_blinded_message.nonce),
452 "cs_blinded_c0",
453 &msg->details.cs_blinded_message.c[0]),
455 "cs_blinded_c1",
456 &msg->details.cs_blinded_message.c[1]));
457 return ps;
458 }
459 GNUNET_assert (0);
460 return ps;
461}
struct GNUNET_MessageHeader * msg
Definition 005.c:2
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:269

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 465 of file json_pack.c.

468{
469 struct GNUNET_JSON_PackSpec ps = {
470 .field_name = name,
471 };
472
473 if (NULL == sig)
474 return ps;
475 switch (sig->cipher)
476 {
478 break;
480 ps.object = GNUNET_JSON_PACK (
481 GNUNET_JSON_pack_string ("cipher",
482 "RSA"),
483 GNUNET_JSON_pack_rsa_signature ("blinded_rsa_signature",
485 return ps;
487 ps.object = GNUNET_JSON_PACK (
488 GNUNET_JSON_pack_string ("cipher",
489 "CS"),
494 return ps;
495 }
496 GNUNET_assert (0);
497 return ps;
498}
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:137
struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer
If we use GNUNET_CRYPTO_BSA_CS in 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.
union GNUNET_CRYPTO_BlindedSignature::@19 details
Details, depending on 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:

◆ GNUNET_JSON_pack_time_rounder_interval()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rounder_interval ( const char *  name,
enum GNUNET_TIME_RounderInterval  ri 
)

Generate packer instruction of a time rounder interval.

Parameters
namename of the field to add to the object
rirounder interval to add
Returns
json pack specification

Definition at line 502 of file json_pack.c.

504{
505 const char *str = "INVALID";
506
508 if (NULL == str)
509 {
510 GNUNET_break (0);
511 str = "INVALID";
512 }
514 str);
515}
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_TIME_round_interval2s(enum GNUNET_TIME_RounderInterval ri)
Convert rounding interval to string.
Definition time.c:1293
enum GNUNET_TIME_RounderInterval ri
Definition time.c:1251
const char * str
Definition time.c:1252

References GNUNET_break, GNUNET_JSON_pack_string(), GNUNET_TIME_round_interval2s(), name, ri, and str.

Here is the call graph for this function: