GNUnet 0.24.1-12-gebf1afa89
json_pack.c File Reference

functions to pack JSON objects More...

#include "platform.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. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_end_ (void)
 Do not use directly. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_allow_null (struct GNUNET_JSON_PackSpec in)
 Modify packer instruction to allow NULL as a value. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_bool (const char *name, bool b)
 Generate packer instruction for a JSON field of type bool. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_double (const char *name, double f)
 Generate packer instruction for a JSON field of type double. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_string (const char *name, const char *s)
 Generate packer instruction for a JSON field of type string. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_uint64 (const char *name, uint64_t num)
 Generate packer instruction for a JSON field of type unsigned integer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_int64 (const char *name, int64_t num)
 Generate packer instruction for a JSON field of type signed integer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_steal (const char *name, json_t *o)
 Generate packer instruction for a JSON field of type JSON object where the reference is taken over by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_incref (const char *name, json_t *o)
 Generate packer instruction for a JSON field of type JSON object where the reference counter is incremented by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_steal (const char *name, json_t *a)
 Generate packer instruction for a JSON field of type JSON array where the reference is taken over by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_incref (const char *name, json_t *a)
 Generate packer instruction for a JSON field of type JSON array where the reference counter is incremented by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data_varsize (const char *name, const void *blob, size_t blob_size)
 Generate packer instruction for a JSON field of type variable size binary blob. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data64_varsize (const char *name, const void *blob, size_t blob_size)
 Generate packer instruction for a JSON field of type variable size binary blob. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp (const char *name, struct GNUNET_TIME_Timestamp t)
 Generate packer instruction for a JSON field of type timestamp. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO at)
 Generate packer instruction for a JSON field of type timestamp in network byte order. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel (const char *name, struct GNUNET_TIME_Relative rt)
 Generate packer instruction for a JSON field of type relative time. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel_nbo (const char *name, struct GNUNET_TIME_RelativeNBO rt)
 Generate packer instruction for a JSON field of type relative time in network byte order. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_public_key (const char *name, const struct GNUNET_CRYPTO_RsaPublicKey *pk)
 Generate packer instruction for a JSON field of type RSA public key. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_signature (const char *name, const struct GNUNET_CRYPTO_RsaSignature *sig)
 Generate packer instruction for a JSON field of type RSA signature. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_unblinded_signature (const char *name, const struct GNUNET_CRYPTO_UnblindedSignature *sig)
 Generate packer instruction for a JSON field of type unblinded signature. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_message (const char *name, const struct GNUNET_CRYPTO_BlindedMessage *msg)
 Generate packer instruction for a JSON field of type blinded message. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_sig (const char *name, const struct GNUNET_CRYPTO_BlindedSignature *sig)
 Generate packer instruction for a JSON field of type blinded signature. More...
 

Detailed Description

functions to 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 29 of file json_pack.c.

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

76{
77 struct GNUNET_JSON_PackSpec ps = {
78 .final = true
79 };
80
81 return ps;
82}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
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 86 of file json_pack.c.

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

References GNUNET_JSON_PackSpec::allow_null.

◆ GNUNET_JSON_pack_bool()

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

Generate packer instruction for a JSON field of type bool.

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

Definition at line 94 of file json_pack.c.

96{
97 struct GNUNET_JSON_PackSpec ps = {
98 .field_name = name,
99 .object = json_boolean (b)
100 };
101
102 GNUNET_assert (NULL != name);
103 return ps;
104}
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 108 of file json_pack.c.

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

References GNUNET_assert, name, and ps.

◆ GNUNET_JSON_pack_string()

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

Generate packer instruction for a JSON field of type string.

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

Definition at line 122 of file json_pack.c.

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

References GNUNET_assert, name, and ps.

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

Here is the caller graph for this function:

◆ GNUNET_JSON_pack_uint64()

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

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

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

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

Definition at line 136 of file json_pack.c.

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

References GNUNET_assert, name, and ps.

Referenced by GNUNET_JSON_pack_blinded_sig().

Here is the caller graph for this function:

◆ GNUNET_JSON_pack_int64()

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

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

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

Definition at line 155 of file json_pack.c.

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

References GNUNET_assert, name, and ps.

◆ GNUNET_JSON_pack_object_steal()

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

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

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

Definition at line 176 of file json_pack.c.

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

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

Referenced by GNUNET_JSON_pack_time_rel().

Here is the caller graph for this function:

◆ GNUNET_JSON_pack_object_incref()

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

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

Note that a deep copy is not performed.

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

Definition at line 198 of file json_pack.c.

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

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

◆ GNUNET_JSON_pack_array_steal()

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

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

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

Definition at line 221 of file json_pack.c.

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

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

◆ GNUNET_JSON_pack_array_incref()

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

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

Note that a deep copy is not performed.

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

Definition at line 244 of file json_pack.c.

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

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

◆ GNUNET_JSON_pack_data_varsize()

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

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

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

Definition at line 268 of file json_pack.c.

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

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

Referenced by GNUNET_JSON_pack_blinded_message().

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

◆ GNUNET_JSON_pack_data64_varsize()

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

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

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

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

Definition at line 286 of file json_pack.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_pack_timestamp()

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

Generate packer instruction for a JSON field of type timestamp.

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

Definition at line 304 of file json_pack.c.

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

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

Referenced by GNUNET_JSON_pack_timestamp_nbo().

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

◆ GNUNET_JSON_pack_timestamp_nbo()

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

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

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

Definition at line 326 of file json_pack.c.

328{
331}
struct GNUNET_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:304

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

Here is the call graph for this function:

◆ GNUNET_JSON_pack_time_rel()

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

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

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

Definition at line 335 of file json_pack.c.

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

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

Referenced by GNUNET_JSON_pack_time_rel_nbo().

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

◆ GNUNET_JSON_pack_time_rel_nbo()

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

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

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

Definition at line 349 of file json_pack.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_pack_rsa_public_key()

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

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

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

Definition at line 358 of file json_pack.c.

360{
361 struct GNUNET_JSON_PackSpec ps = {
362 .field_name = name,
364 };
365
366 return ps;
367}
struct GNUNET_CRYPTO_PrivateKey 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 371 of file json_pack.c.

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

References GNUNET_JSON_from_rsa_signature(), name, and ps.

Referenced by GNUNET_JSON_pack_blinded_sig(), and GNUNET_JSON_pack_unblinded_signature().

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

◆ GNUNET_JSON_pack_unblinded_signature()

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

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

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

Definition at line 384 of file json_pack.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_pack_blinded_message()

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

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

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

Definition at line 422 of file json_pack.c.

425{
426 struct GNUNET_JSON_PackSpec ps = {
427 .field_name = name,
428 };
429
430 switch (msg->cipher)
431 {
433 break;
435 ps.object = GNUNET_JSON_PACK (
436 GNUNET_JSON_pack_string ("cipher",
437 "RSA"),
439 "rsa_blinded_planchet",
440 msg->details.rsa_blinded_message.blinded_msg,
441 msg->details.rsa_blinded_message.blinded_msg_size));
442 return ps;
444 ps.object = GNUNET_JSON_PACK (
445 GNUNET_JSON_pack_string ("cipher",
446 "CS"),
448 "cs_nonce",
449 &msg->details.cs_blinded_message.nonce),
451 "cs_blinded_c0",
452 &msg->details.cs_blinded_message.c[0]),
454 "cs_blinded_c1",
455 &msg->details.cs_blinded_message.c[1]));
456 return ps;
457 }
458 GNUNET_assert (0);
459 return ps;
460}
struct GNUNET_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:268

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

Here is the call graph for this function:

◆ GNUNET_JSON_pack_blinded_sig()

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

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

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

Definition at line 464 of file json_pack.c.

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

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

Here is the call graph for this function: