GNUnet 0.28.0-dev.2-5-gff43856e1
 
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 ret = json_object ();
35 GNUNET_assert (NULL != ret);
36 for (unsigned int i = 0;
37 ! spec[i].final;
38 i++)
39 {
40 if (NULL == spec[i].object)
41 {
42 if (! spec[i].allow_null)
43 {
45 "NULL not allowed for `%s'\n",
46 spec[i].field_name);
47 GNUNET_assert (0);
48 }
49 }
50 else
51 {
52 if (NULL == spec[i].field_name)
53 GNUNET_assert (0 ==
54 json_object_update_new (ret,
55 spec[i].object));
56 else
57 GNUNET_assert (0 ==
58 json_object_set_new (ret,
59 spec[i].field_name,
60 spec[i].object));
61
62 spec[i].object = NULL;
63 }
64 }
65 return ret;
66}
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 70 of file json_pack.c.

71{
72 struct GNUNET_JSON_PackSpec ps = {
73 .final = true
74 };
75
76 return ps;
77}
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 81 of file json_pack.c.

82{
83 in.allow_null = true;
84 return in;
85}
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 89 of file json_pack.c.

91{
92 struct GNUNET_JSON_PackSpec ps = {
93 .field_name = name,
94 .object = json_boolean (b)
95 };
96
97 GNUNET_assert (NULL != name);
98 return ps;
99}
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 103 of file json_pack.c.

105{
106 struct GNUNET_JSON_PackSpec ps = {
107 .field_name = name,
108 .object = json_real (f)
109 };
110
111 GNUNET_assert (NULL != name);
112 return ps;
113}

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

119{
120 struct GNUNET_JSON_PackSpec ps = {
121 .field_name = name,
122 .object = json_string (s)
123 };
124
125 GNUNET_assert (NULL != name);
126 return ps;
127}

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

133{
134 struct GNUNET_JSON_PackSpec ps = {
135 .field_name = name,
136 .object = json_integer ((json_int_t) num)
137 };
138
139 GNUNET_assert (NULL != name);
140#if JSON_INTEGER_IS_LONG_LONG
141 GNUNET_assert (num <= LLONG_MAX);
142#else
143 GNUNET_assert (num <= LONG_MAX);
144#endif
145 return ps;
146}

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

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

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

173{
174 struct GNUNET_JSON_PackSpec ps = {
175 .field_name = name,
176 .object = o
177 };
178
179 if (NULL == o)
180 return ps;
181 if (! json_is_object (o))
182 {
184 "Expected JSON object for field `%s'\n",
185 name);
186 GNUNET_assert (0);
187 }
188 return ps;
189}

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

195{
196 struct GNUNET_JSON_PackSpec ps = {
197 .field_name = name,
198 .object = o
199 };
200
201 if (NULL == o)
202 return ps;
203 (void) json_incref (o);
204 if (! json_is_object (o))
205 {
207 "Expected JSON object for field `%s'\n",
208 name);
209 GNUNET_assert (0);
210 }
211 return ps;
212}

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

218{
219 struct GNUNET_JSON_PackSpec ps = {
220 .field_name = name,
221 .object = a
222 };
223
224 GNUNET_assert (NULL != name);
225 if (NULL == a)
226 return ps;
227 if (! json_is_array (a))
228 {
230 "Expected JSON array for field `%s'\n",
231 name);
232 GNUNET_assert (0);
233 }
234 return ps;
235}

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

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

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

266{
267 struct GNUNET_JSON_PackSpec ps = {
268 .field_name = name,
269 .object = (NULL != blob)
270 ? GNUNET_JSON_from_data (blob,
271 blob_size)
272 : NULL
273 };
274
275 GNUNET_assert (NULL != name);
276 return ps;
277}
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 281 of file json_pack.c.

284{
285 struct GNUNET_JSON_PackSpec ps = {
286 .field_name = name,
287 .object = (NULL != blob)
289 blob_size)
290 : NULL
291 };
292
293 GNUNET_assert (NULL != name);
294 return ps;
295}
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 299 of file json_pack.c.

301{
302 struct GNUNET_JSON_PackSpec ps = {
303 .field_name = name
304 };
305
306 GNUNET_assert (NULL != name);
307 if (! GNUNET_TIME_absolute_is_zero (t.abs_time))
308 {
310 GNUNET_assert (NULL != ps.object);
311 }
312 else
313 {
314 ps.object = NULL;
315 }
316 return ps;
317}
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 321 of file json_pack.c.

323{
326}
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:299

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

332{
333 json_t *json;
334
335 GNUNET_assert (NULL != name);
336 json = GNUNET_JSON_from_time_rel (rt);
337 GNUNET_assert (NULL != json);
339 json);
340}
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:171

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

346{
349}
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:330

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

355{
356 struct GNUNET_JSON_PackSpec ps = {
357 .field_name = name,
359 };
360
361 return ps;
362}
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 366 of file json_pack.c.

368{
369 struct GNUNET_JSON_PackSpec ps = {
370 .field_name = name,
371 .object = GNUNET_JSON_from_rsa_signature (sig)
372 };
373
374 return ps;
375}
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 379 of file json_pack.c.

382{
383 struct GNUNET_JSON_PackSpec ps = {
384 .field_name = name
385 };
386
387 if (NULL == sig)
388 return ps;
389
390 switch (sig->cipher)
391 {
393 break;
395 ps.object = GNUNET_JSON_PACK (
396 GNUNET_JSON_pack_string ("cipher",
397 "RSA"),
398 GNUNET_JSON_pack_rsa_signature ("rsa_signature",
399 sig->details.rsa_signature));
400 return ps;
402 ps.object = GNUNET_JSON_PACK (
403 GNUNET_JSON_pack_string ("cipher",
404 "CS"),
405 GNUNET_JSON_pack_data_auto ("cs_signature_r",
407 GNUNET_JSON_pack_data_auto ("cs_signature_s",
409 return ps;
410 }
411 GNUNET_assert (0);
412 return ps;
413}
#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:366
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:117
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 417 of file json_pack.c.

420{
421 struct GNUNET_JSON_PackSpec ps = {
422 .field_name = name,
423 };
424
425 switch (msg->cipher)
426 {
428 break;
430 ps.object = GNUNET_JSON_PACK (
431 GNUNET_JSON_pack_string ("cipher",
432 "RSA"),
434 "rsa_blinded_planchet",
435 msg->details.rsa_blinded_message.blinded_msg,
436 msg->details.rsa_blinded_message.blinded_msg_size));
437 return ps;
439 ps.object = GNUNET_JSON_PACK (
440 GNUNET_JSON_pack_string ("cipher",
441 "CS"),
443 "cs_nonce",
444 &msg->details.cs_blinded_message.nonce),
446 "cs_blinded_c0",
447 &msg->details.cs_blinded_message.c[0]),
449 "cs_blinded_c1",
450 &msg->details.cs_blinded_message.c[1]));
451 return ps;
452 }
453 GNUNET_assert (0);
454 return ps;
455}
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:263

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

462{
463 struct GNUNET_JSON_PackSpec ps = {
464 .field_name = name,
465 };
466
467 if (NULL == sig)
468 return ps;
469 switch (sig->cipher)
470 {
472 break;
474 ps.object = GNUNET_JSON_PACK (
475 GNUNET_JSON_pack_string ("cipher",
476 "RSA"),
477 GNUNET_JSON_pack_rsa_signature ("blinded_rsa_signature",
479 return ps;
481 ps.object = GNUNET_JSON_PACK (
482 GNUNET_JSON_pack_string ("cipher",
483 "CS"),
488 return ps;
489 }
490 GNUNET_assert (0);
491 return ps;
492}
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:131
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 496 of file json_pack.c.

498{
499 const char *str = "INVALID";
500
502 if (NULL == str)
503 {
504 GNUNET_break (0);
505 str = "INVALID";
506 }
508 str);
509}
#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: