diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-10-09 21:10:14 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:01 +0100 |
commit | e6eb523e12729ef1d6a6ee3f140671e5e51d8d1c (patch) | |
tree | 746c6b899bc5fdc491ad477463dda3b56295304e /src/include/gnunet_reclaim_attribute_lib.h | |
parent | 60d2660de243053bc0f41657ad9d67537723276c (diff) | |
download | gnunet-e6eb523e12729ef1d6a6ee3f140671e5e51d8d1c.tar.gz gnunet-e6eb523e12729ef1d6a6ee3f140671e5e51d8d1c.zip |
Adapted JSON Conversion and Serialization
Diffstat (limited to 'src/include/gnunet_reclaim_attribute_lib.h')
-rw-r--r-- | src/include/gnunet_reclaim_attribute_lib.h | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/src/include/gnunet_reclaim_attribute_lib.h b/src/include/gnunet_reclaim_attribute_lib.h index 4563a5f67..c23b39383 100644 --- a/src/include/gnunet_reclaim_attribute_lib.h +++ b/src/include/gnunet_reclaim_attribute_lib.h | |||
@@ -50,6 +50,15 @@ extern "C" { | |||
50 | */ | 50 | */ |
51 | #define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING 1 | 51 | #define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING 1 |
52 | 52 | ||
53 | /** | ||
54 | * No value attestation. | ||
55 | */ | ||
56 | #define GNUNET_RECLAIM_ATTESTATION_TYPE_NONE 0 | ||
57 | |||
58 | /** | ||
59 | * A JSON Web Token attestation. | ||
60 | */ | ||
61 | #define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT 1 | ||
53 | 62 | ||
54 | /** | 63 | /** |
55 | * An attribute. | 64 | * An attribute. |
@@ -89,6 +98,44 @@ struct GNUNET_RECLAIM_ATTRIBUTE_Claim | |||
89 | const void *data; | 98 | const void *data; |
90 | }; | 99 | }; |
91 | 100 | ||
101 | /** | ||
102 | * An attestation. | ||
103 | */ | ||
104 | struct GNUNET_RECLAIM_ATTESTATION_Claim | ||
105 | { | ||
106 | /** | ||
107 | * ID | ||
108 | */ | ||
109 | uint64_t id; | ||
110 | |||
111 | /** | ||
112 | * Type/Format of Claim | ||
113 | */ | ||
114 | uint32_t type; | ||
115 | |||
116 | /** | ||
117 | * Version | ||
118 | */ | ||
119 | uint32_t version; | ||
120 | |||
121 | /** | ||
122 | * The name of the attribute. Note "name" must never be individually | ||
123 | * free'd | ||
124 | */ | ||
125 | const char *name; | ||
126 | |||
127 | /** | ||
128 | * Number of bytes in @e data. | ||
129 | */ | ||
130 | size_t data_size; | ||
131 | |||
132 | /** | ||
133 | * Binary value stored as attribute value. Note: "data" must never | ||
134 | * be individually 'malloc'ed, but instead always points into some | ||
135 | * existing data area. | ||
136 | */ | ||
137 | const void *data; | ||
138 | }; | ||
92 | 139 | ||
93 | /** | 140 | /** |
94 | * A list of GNUNET_RECLAIM_ATTRIBUTE_Claim structures. | 141 | * A list of GNUNET_RECLAIM_ATTRIBUTE_Claim structures. |
@@ -299,6 +346,103 @@ GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, | |||
299 | const char * | 346 | const char * |
300 | GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type); | 347 | GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type); |
301 | 348 | ||
349 | /** | ||
350 | * Get required size for serialization buffer | ||
351 | * | ||
352 | * @param attr the attestation to serialize | ||
353 | * @return the required buffer size | ||
354 | */ | ||
355 | size_t | ||
356 | GNUNET_RECLAIM_ATTESTATION_serialize_get_size ( | ||
357 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr); | ||
358 | |||
359 | |||
360 | /** | ||
361 | * Serialize an attestation | ||
362 | * | ||
363 | * @param attr the attestation to serialize | ||
364 | * @param result the serialized attestation | ||
365 | * @return length of serialized data | ||
366 | */ | ||
367 | size_t | ||
368 | GNUNET_RECLAIM_ATTESTATION_serialize ( | ||
369 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr, | ||
370 | char *result); | ||
371 | |||
372 | |||
373 | /** | ||
374 | * Deserialize an attestation | ||
375 | * | ||
376 | * @param data the serialized attestation | ||
377 | * @param data_size the length of the serialized data | ||
378 | * | ||
379 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | ||
380 | */ | ||
381 | struct GNUNET_RECLAIM_ATTESTATION_Claim * | ||
382 | GNUNET_RECLAIM_ATTESTATION_deserialize (const char *data, size_t data_size); | ||
383 | |||
384 | |||
385 | /** | ||
386 | * Create a new attestation. | ||
387 | * | ||
388 | * @param attr_name the attestation name | ||
389 | * @param type the attestation type | ||
390 | * @param data the attestation value | ||
391 | * @param data_size the attestation value size | ||
392 | * @return the new attestation | ||
393 | */ | ||
394 | struct GNUNET_RECLAIM_ATTESTATION_Claim * | ||
395 | GNUNET_RECLAIM_ATTESTATION_claim_new (const char *attr_name, | ||
396 | uint32_t type, | ||
397 | const void *data, | ||
398 | size_t data_size); | ||
399 | |||
400 | /** | ||
401 | * Convert the 'claim' of an attestation to a string | ||
402 | * | ||
403 | * @param type the type of attestation | ||
404 | * @param data claim in binary encoding | ||
405 | * @param data_size number of bytes in @a data | ||
406 | * @return NULL on error, otherwise human-readable representation of the claim | ||
407 | */ | ||
408 | char * | ||
409 | GNUNET_RECLAIM_ATTESTATION_value_to_string (uint32_t type, | ||
410 | const void *data, | ||
411 | size_t data_size); | ||
412 | |||
413 | /** | ||
414 | * Convert human-readable version of a 'claim' of an attestation to the binary | ||
415 | * representation | ||
416 | * | ||
417 | * @param type type of the claim | ||
418 | * @param s human-readable string | ||
419 | * @param data set to value in binary encoding (will be allocated) | ||
420 | * @param data_size set to number of bytes in @a data | ||
421 | * @return #GNUNET_OK on success | ||
422 | */ | ||
423 | int | ||
424 | GNUNET_RECLAIM_ATTESTATION_string_to_value (uint32_t type, | ||
425 | const char *s, | ||
426 | void **data, | ||
427 | size_t *data_size); | ||
428 | |||
429 | /** | ||
430 | * Convert an attestation type number to the corresponding attestation type string | ||
431 | * | ||
432 | * @param type number of a type | ||
433 | * @return corresponding typestring, NULL on error | ||
434 | */ | ||
435 | const char * | ||
436 | GNUNET_RECLAIM_ATTESTATION_number_to_typename (uint32_t type); | ||
437 | |||
438 | /** | ||
439 | * Convert an attestation type name to the corresponding number | ||
440 | * | ||
441 | * @param typename name to convert | ||
442 | * @return corresponding number, UINT32_MAX on error | ||
443 | */ | ||
444 | uint32_t | ||
445 | GNUNET_RECLAIM_ATTESTATION_typename_to_number (const char *typename); | ||
302 | 446 | ||
303 | #if 0 /* keep Emacsens' auto-indent happy */ | 447 | #if 0 /* keep Emacsens' auto-indent happy */ |
304 | { | 448 | { |