diff options
Diffstat (limited to 'src/include/gnunet_reclaim_attribute_lib.h')
-rw-r--r-- | src/include/gnunet_reclaim_attribute_lib.h | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/src/include/gnunet_reclaim_attribute_lib.h b/src/include/gnunet_reclaim_attribute_lib.h index 4563a5f67..004f2bd10 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 10 | ||
57 | |||
58 | /** | ||
59 | * A JSON Web Token attestation. | ||
60 | */ | ||
61 | #define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT 11 | ||
53 | 62 | ||
54 | /** | 63 | /** |
55 | * An attribute. | 64 | * An attribute. |
@@ -67,9 +76,48 @@ struct GNUNET_RECLAIM_ATTRIBUTE_Claim | |||
67 | uint32_t type; | 76 | uint32_t type; |
68 | 77 | ||
69 | /** | 78 | /** |
79 | * Flags | ||
80 | */ | ||
81 | uint32_t flag; | ||
82 | /** | ||
83 | * The name of the attribute. Note "name" must never be individually | ||
84 | * free'd | ||
85 | */ | ||
86 | const char *name; | ||
87 | |||
88 | /** | ||
89 | * Number of bytes in @e data. | ||
90 | */ | ||
91 | size_t data_size; | ||
92 | |||
93 | /** | ||
94 | * Binary value stored as attribute value. Note: "data" must never | ||
95 | * be individually 'malloc'ed, but instead always points into some | ||
96 | * existing data area. | ||
97 | */ | ||
98 | const void *data; | ||
99 | }; | ||
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 | /** | ||
70 | * Version | 117 | * Version |
71 | */ | 118 | */ |
72 | uint32_t version; | 119 | uint32_t version; |
120 | |||
73 | /** | 121 | /** |
74 | * The name of the attribute. Note "name" must never be individually | 122 | * The name of the attribute. Note "name" must never be individually |
75 | * free'd | 123 | * free'd |
@@ -89,6 +137,33 @@ struct GNUNET_RECLAIM_ATTRIBUTE_Claim | |||
89 | const void *data; | 137 | const void *data; |
90 | }; | 138 | }; |
91 | 139 | ||
140 | /** | ||
141 | * A reference to an Attestatiom. | ||
142 | */ | ||
143 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE | ||
144 | { | ||
145 | /** | ||
146 | * ID | ||
147 | */ | ||
148 | uint64_t id; | ||
149 | |||
150 | /** | ||
151 | * Referenced ID of Attestation | ||
152 | */ | ||
153 | uint64_t id_attest; | ||
154 | |||
155 | /** | ||
156 | * The name of the attribute/attestation reference value. Note "name" must never be individually | ||
157 | * free'd | ||
158 | */ | ||
159 | const char *name; | ||
160 | |||
161 | /** | ||
162 | * The name of the attribute/attestation reference value. Note "name" must never be individually | ||
163 | * free'd | ||
164 | */ | ||
165 | const char *reference_value; | ||
166 | }; | ||
92 | 167 | ||
93 | /** | 168 | /** |
94 | * A list of GNUNET_RECLAIM_ATTRIBUTE_Claim structures. | 169 | * A list of GNUNET_RECLAIM_ATTRIBUTE_Claim structures. |
@@ -123,6 +198,20 @@ struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry | |||
123 | * The attribute claim | 198 | * The attribute claim |
124 | */ | 199 | */ |
125 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; | 200 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; |
201 | /** | ||
202 | * The attestation claim | ||
203 | */ | ||
204 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; | ||
205 | |||
206 | /** | ||
207 | * The reference | ||
208 | */ | ||
209 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference; | ||
210 | }; | ||
211 | |||
212 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType | ||
213 | { | ||
214 | uint32_t type; | ||
126 | }; | 215 | }; |
127 | 216 | ||
128 | 217 | ||
@@ -203,6 +292,14 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( | |||
203 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * | 292 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * |
204 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size); | 293 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size); |
205 | 294 | ||
295 | /** | ||
296 | * Count attestations in claim list | ||
297 | * | ||
298 | * @param attrs list | ||
299 | */ | ||
300 | int | ||
301 | GNUNET_RECLAIM_ATTRIBUTE_list_count_attest ( | ||
302 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs); | ||
206 | 303 | ||
207 | /** | 304 | /** |
208 | * Get required size for serialization buffer | 305 | * Get required size for serialization buffer |
@@ -299,6 +396,154 @@ GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, | |||
299 | const char * | 396 | const char * |
300 | GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type); | 397 | GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type); |
301 | 398 | ||
399 | /** | ||
400 | * Get required size for serialization buffer | ||
401 | * FIXME: | ||
402 | * 1. The naming convention is violated here. | ||
403 | * It should GNUNET_RECLAIM_ATTRIBUTE_<lowercase from here>. | ||
404 | * It might make sense to refactor attestations into a separate folder. | ||
405 | * 2. The struct should be called GNUNET_RECLAIM_ATTESTATION_Data or | ||
406 | * GNUNET_RECLAIM_ATTRIBUTE_Attestation depending on location in source. | ||
407 | * | ||
408 | * @param attr the attestation to serialize | ||
409 | * @return the required buffer size | ||
410 | */ | ||
411 | size_t | ||
412 | GNUNET_RECLAIM_ATTESTATION_serialize_get_size ( | ||
413 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr); | ||
414 | |||
415 | |||
416 | /** | ||
417 | * Serialize an attestation | ||
418 | * | ||
419 | * @param attr the attestation to serialize | ||
420 | * @param result the serialized attestation | ||
421 | * @return length of serialized data | ||
422 | */ | ||
423 | size_t | ||
424 | GNUNET_RECLAIM_ATTESTATION_serialize ( | ||
425 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr, | ||
426 | char *result); | ||
427 | |||
428 | |||
429 | /** | ||
430 | * Deserialize an attestation | ||
431 | * | ||
432 | * @param data the serialized attestation | ||
433 | * @param data_size the length of the serialized data | ||
434 | * | ||
435 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | ||
436 | */ | ||
437 | struct GNUNET_RECLAIM_ATTESTATION_Claim * | ||
438 | GNUNET_RECLAIM_ATTESTATION_deserialize (const char *data, size_t data_size); | ||
439 | |||
440 | |||
441 | /** | ||
442 | * Create a new attestation. | ||
443 | * | ||
444 | * @param attr_name the attestation name | ||
445 | * @param type the attestation type | ||
446 | * @param data the attestation value | ||
447 | * @param data_size the attestation value size | ||
448 | * @return the new attestation | ||
449 | */ | ||
450 | struct GNUNET_RECLAIM_ATTESTATION_Claim * | ||
451 | GNUNET_RECLAIM_ATTESTATION_claim_new (const char *attr_name, | ||
452 | uint32_t type, | ||
453 | const void *data, | ||
454 | size_t data_size); | ||
455 | |||
456 | /** | ||
457 | * Convert the 'claim' of an attestation to a string | ||
458 | * | ||
459 | * @param type the type of attestation | ||
460 | * @param data claim in binary encoding | ||
461 | * @param data_size number of bytes in @a data | ||
462 | * @return NULL on error, otherwise human-readable representation of the claim | ||
463 | */ | ||
464 | char * | ||
465 | GNUNET_RECLAIM_ATTESTATION_value_to_string (uint32_t type, | ||
466 | const void *data, | ||
467 | size_t data_size); | ||
468 | |||
469 | /** | ||
470 | * Convert human-readable version of a 'claim' of an attestation to the binary | ||
471 | * representation | ||
472 | * | ||
473 | * @param type type of the claim | ||
474 | * @param s human-readable string | ||
475 | * @param data set to value in binary encoding (will be allocated) | ||
476 | * @param data_size set to number of bytes in @a data | ||
477 | * @return #GNUNET_OK on success | ||
478 | */ | ||
479 | int | ||
480 | GNUNET_RECLAIM_ATTESTATION_string_to_value (uint32_t type, | ||
481 | const char *s, | ||
482 | void **data, | ||
483 | size_t *data_size); | ||
484 | |||
485 | /** | ||
486 | * Convert an attestation type number to the corresponding attestation type string | ||
487 | * | ||
488 | * @param type number of a type | ||
489 | * @return corresponding typestring, NULL on error | ||
490 | */ | ||
491 | const char * | ||
492 | GNUNET_RECLAIM_ATTESTATION_number_to_typename (uint32_t type); | ||
493 | |||
494 | /** | ||
495 | * Convert an attestation type name to the corresponding number | ||
496 | * | ||
497 | * @param typename name to convert | ||
498 | * @return corresponding number, UINT32_MAX on error | ||
499 | */ | ||
500 | uint32_t | ||
501 | GNUNET_RECLAIM_ATTESTATION_typename_to_number (const char *typename); | ||
502 | |||
503 | /** | ||
504 | * Create a new attestation reference. | ||
505 | * | ||
506 | * @param attr_name the referenced claim name | ||
507 | * @param ref_value the claim name in the attestation | ||
508 | * @return the new reference | ||
509 | */ | ||
510 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * | ||
511 | GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name, | ||
512 | const char *ref_value); | ||
513 | |||
514 | |||
515 | /** | ||
516 | * Get required size for serialization buffer | ||
517 | * | ||
518 | * @param attr the reference to serialize | ||
519 | * @return the required buffer size | ||
520 | */ | ||
521 | size_t | ||
522 | GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size ( | ||
523 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr); | ||
524 | |||
525 | /** | ||
526 | * Serialize a reference | ||
527 | * | ||
528 | * @param attr the reference to serialize | ||
529 | * @param result the serialized reference | ||
530 | * @return length of serialized data | ||
531 | */ | ||
532 | size_t | ||
533 | GNUNET_RECLAIM_ATTESTATION_REF_serialize ( | ||
534 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr, | ||
535 | char *result); | ||
536 | |||
537 | /** | ||
538 | * Deserialize a reference | ||
539 | * | ||
540 | * @param data the serialized reference | ||
541 | * @param data_size the length of the serialized data | ||
542 | * | ||
543 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | ||
544 | */ | ||
545 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * | ||
546 | GNUNET_RECLAIM_ATTESTATION_REF_deserialize (const char *data, size_t data_size); | ||
302 | 547 | ||
303 | #if 0 /* keep Emacsens' auto-indent happy */ | 548 | #if 0 /* keep Emacsens' auto-indent happy */ |
304 | { | 549 | { |