aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_reclaim_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_reclaim_lib.h')
-rw-r--r--src/include/gnunet_reclaim_lib.h394
1 files changed, 311 insertions, 83 deletions
diff --git a/src/include/gnunet_reclaim_lib.h b/src/include/gnunet_reclaim_lib.h
index 7d521ffa8..f5c3d3864 100644
--- a/src/include/gnunet_reclaim_lib.h
+++ b/src/include/gnunet_reclaim_lib.h
@@ -39,26 +39,34 @@ extern "C" {
39 39
40#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
41 41
42enum GNUNET_RECLAIM_AttributeType {
43 /**
44 * No value attribute.
45 */
46 GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE = 0,
42 47
43/** 48 /**
44 * No value attribute. 49 * String attribute.
45 */ 50 */
46#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE 0 51 GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING = 1
52};
47 53
48/** 54enum GNUNET_RECLAIM_CredentialType {
49 * String attribute. 55 /**
50 */ 56 * No value credential.
51#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING 1 57 */
58 GNUNET_RECLAIM_CREDENTIAL_TYPE_NONE = 0,
52 59
53/** 60 /**
54* No value attestation. 61 * A JSON Web Token credential.
55*/ 62 */
56#define GNUNET_RECLAIM_ATTESTATION_TYPE_NONE 10 63 GNUNET_RECLAIM_CREDENTIAL_TYPE_JWT = 1,
57 64
58/** 65 /**
59* A JSON Web Token attestation. 66 * libpabc credential
60*/ 67 */
61#define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT 11 68 GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC = 2
69};
62 70
63/** 71/**
64 * We want an ID to be a 256-bit symmetric key 72 * We want an ID to be a 256-bit symmetric key
@@ -107,9 +115,10 @@ struct GNUNET_RECLAIM_Attribute
107 struct GNUNET_RECLAIM_Identifier id; 115 struct GNUNET_RECLAIM_Identifier id;
108 116
109 /** 117 /**
110 * Referenced ID of Attestation (may be 0 if self-attested) 118 * Referenced ID of credential
119 * (may be GNUNET_RECLAIM_ID_ZERO if self-creded)
111 */ 120 */
112 struct GNUNET_RECLAIM_Identifier attestation; 121 struct GNUNET_RECLAIM_Identifier credential;
113 122
114 /** 123 /**
115 * Type of Claim 124 * Type of Claim
@@ -141,9 +150,9 @@ struct GNUNET_RECLAIM_Attribute
141}; 150};
142 151
143/** 152/**
144 * An attestation. 153 * A credential.
145 */ 154 */
146struct GNUNET_RECLAIM_Attestation 155struct GNUNET_RECLAIM_Credential
147{ 156{
148 /** 157 /**
149 * ID 158 * ID
@@ -161,7 +170,7 @@ struct GNUNET_RECLAIM_Attestation
161 uint32_t flag; 170 uint32_t flag;
162 171
163 /** 172 /**
164 * The name of the attribute. Note "name" must never be individually 173 * The name of the credential. Note: must never be individually
165 * free'd 174 * free'd
166 */ 175 */
167 const char *name; 176 const char *name;
@@ -172,7 +181,36 @@ struct GNUNET_RECLAIM_Attestation
172 size_t data_size; 181 size_t data_size;
173 182
174 /** 183 /**
175 * Binary value stored as attribute value. Note: "data" must never 184 * Binary value stored as credential value. Note: "data" must never
185 * be individually 'malloc'ed, but instead always points into some
186 * existing data area.
187 */
188 const void *data;
189};
190
191
192/**
193 * A credential presentation.
194 */
195struct GNUNET_RECLAIM_Presentation
196{
197 /**
198 * The credential id of which this is a presentation.
199 */
200 struct GNUNET_RECLAIM_Identifier credential_id;
201
202 /**
203 * Type/Format of Claim
204 */
205 uint32_t type;
206
207 /**
208 * Number of bytes in @e data.
209 */
210 size_t data_size;
211
212 /**
213 * Binary value stored as presentation value. Note: "data" must never
176 * be individually 'malloc'ed, but instead always points into some 214 * be individually 'malloc'ed, but instead always points into some
177 * existing data area. 215 * existing data area.
178 */ 216 */
@@ -180,6 +218,7 @@ struct GNUNET_RECLAIM_Attestation
180}; 218};
181 219
182 220
221
183/** 222/**
184 * A list of GNUNET_RECLAIM_Attribute structures. 223 * A list of GNUNET_RECLAIM_Attribute structures.
185 */ 224 */
@@ -217,56 +256,94 @@ struct GNUNET_RECLAIM_AttributeListEntry
217}; 256};
218 257
219/** 258/**
220 * A list of GNUNET_RECLAIM_Attestation structures. 259 * A list of GNUNET_RECLAIM_Credential structures.
221 */ 260 */
222struct GNUNET_RECLAIM_AttestationList 261struct GNUNET_RECLAIM_CredentialList
223{ 262{
224 /** 263 /**
225 * List head 264 * List head
226 */ 265 */
227 struct GNUNET_RECLAIM_AttestationListEntry *list_head; 266 struct GNUNET_RECLAIM_CredentialListEntry *list_head;
228 267
229 /** 268 /**
230 * List tail 269 * List tail
231 */ 270 */
232 struct GNUNET_RECLAIM_AttestationListEntry *list_tail; 271 struct GNUNET_RECLAIM_CredentialListEntry *list_tail;
233}; 272};
234 273
235 274
236struct GNUNET_RECLAIM_AttestationListEntry 275struct GNUNET_RECLAIM_CredentialListEntry
237{ 276{
238 /** 277 /**
239 * DLL 278 * DLL
240 */ 279 */
241 struct GNUNET_RECLAIM_AttestationListEntry *prev; 280 struct GNUNET_RECLAIM_CredentialListEntry *prev;
242 281
243 /** 282 /**
244 * DLL 283 * DLL
245 */ 284 */
246 struct GNUNET_RECLAIM_AttestationListEntry *next; 285 struct GNUNET_RECLAIM_CredentialListEntry *next;
247 286
248 /** 287 /**
249 * The attestation 288 * The credential
250 */ 289 */
251 struct GNUNET_RECLAIM_Attestation *attestation; 290 struct GNUNET_RECLAIM_Credential *credential;
252 291
253}; 292};
254 293
255 294
256/** 295/**
296 * A list of GNUNET_RECLAIM_Presentation structures.
297 */
298struct GNUNET_RECLAIM_PresentationList
299{
300 /**
301 * List head
302 */
303 struct GNUNET_RECLAIM_PresentationListEntry *list_head;
304
305 /**
306 * List tail
307 */
308 struct GNUNET_RECLAIM_PresentationListEntry *list_tail;
309};
310
311
312struct GNUNET_RECLAIM_PresentationListEntry
313{
314 /**
315 * DLL
316 */
317 struct GNUNET_RECLAIM_PresentationListEntry *prev;
318
319 /**
320 * DLL
321 */
322 struct GNUNET_RECLAIM_PresentationListEntry *next;
323
324 /**
325 * The credential
326 */
327 struct GNUNET_RECLAIM_Presentation *presentation;
328
329};
330
331
332
333/**
257 * Create a new attribute claim. 334 * Create a new attribute claim.
258 * 335 *
259 * @param attr_name the attribute name 336 * @param attr_name the attribute name
260 * @param attestation ID of the attestation (may be NULL) 337 * @param credential ID of the credential (may be NULL)
261 * @param type the attribute type 338 * @param type the attribute type
262 * @param data the attribute value. Must be the mapped name if attestation not NULL 339 * @param data the attribute value. Must be #attr_name if credential not NULL
263 * @param data_size the attribute value size 340 * @param data_size the attribute value size
264 * @return the new attribute 341 * @return the new attribute
265 */ 342 */
266struct GNUNET_RECLAIM_Attribute * 343struct GNUNET_RECLAIM_Attribute *
267GNUNET_RECLAIM_attribute_new (const char *attr_name, 344GNUNET_RECLAIM_attribute_new (const char *attr_name,
268 const struct 345 const struct
269 GNUNET_RECLAIM_Identifier *attestation, 346 GNUNET_RECLAIM_Identifier *credential,
270 uint32_t type, 347 uint32_t type,
271 const void *data, 348 const void *data,
272 size_t data_size); 349 size_t data_size);
@@ -298,7 +375,7 @@ GNUNET_RECLAIM_attribute_list_destroy (
298 * 375 *
299 * @param attrs the attribute list to add to 376 * @param attrs the attribute list to add to
300 * @param attr_name the name of the new attribute claim 377 * @param attr_name the name of the new attribute claim
301 * @param attestation attestation ID (may be NULL) 378 * @param credential credential ID (may be NULL)
302 * @param type the type of the claim 379 * @param type the type of the claim
303 * @param data claim payload 380 * @param data claim payload
304 * @param data_size claim payload size 381 * @param data_size claim payload size
@@ -307,7 +384,7 @@ void
307GNUNET_RECLAIM_attribute_list_add ( 384GNUNET_RECLAIM_attribute_list_add (
308 struct GNUNET_RECLAIM_AttributeList *attrs, 385 struct GNUNET_RECLAIM_AttributeList *attrs,
309 const char *attr_name, 386 const char *attr_name,
310 const struct GNUNET_RECLAIM_Identifier *attestation, 387 const struct GNUNET_RECLAIM_Identifier *credential,
311 uint32_t type, 388 uint32_t type,
312 const void *data, 389 const void *data,
313 size_t data_size); 390 size_t data_size);
@@ -439,8 +516,8 @@ GNUNET_RECLAIM_attribute_number_to_typename (uint32_t type);
439 * @return the required buffer size 516 * @return the required buffer size
440 */ 517 */
441size_t 518size_t
442GNUNET_RECLAIM_attestation_list_serialize_get_size ( 519GNUNET_RECLAIM_credential_list_serialize_get_size (
443 const struct GNUNET_RECLAIM_AttestationList *attestations); 520 const struct GNUNET_RECLAIM_CredentialList *credentials);
444 521
445 522
446/** 523/**
@@ -449,8 +526,8 @@ GNUNET_RECLAIM_attestation_list_serialize_get_size (
449 * @param attrs list to destroy 526 * @param attrs list to destroy
450 */ 527 */
451void 528void
452GNUNET_RECLAIM_attestation_list_destroy ( 529GNUNET_RECLAIM_credential_list_destroy (
453 struct GNUNET_RECLAIM_AttestationList *attestations); 530 struct GNUNET_RECLAIM_CredentialList *credentials);
454 531
455 532
456/** 533/**
@@ -462,8 +539,8 @@ GNUNET_RECLAIM_attestation_list_destroy (
462 * @param data_size claim payload size 539 * @param data_size claim payload size
463 */ 540 */
464void 541void
465GNUNET_RECLAIM_attestation_list_add ( 542GNUNET_RECLAIM_credential_list_add (
466 struct GNUNET_RECLAIM_AttestationList *attrs, 543 struct GNUNET_RECLAIM_CredentialList *attrs,
467 const char *att_name, 544 const char *att_name,
468 uint32_t type, 545 uint32_t type,
469 const void *data, 546 const void *data,
@@ -478,8 +555,8 @@ GNUNET_RECLAIM_attestation_list_add (
478 * @return length of serialized data 555 * @return length of serialized data
479 */ 556 */
480size_t 557size_t
481GNUNET_RECLAIM_attestation_list_serialize ( 558GNUNET_RECLAIM_credential_list_serialize (
482 const struct GNUNET_RECLAIM_AttestationList *attrs, 559 const struct GNUNET_RECLAIM_CredentialList *attrs,
483 char *result); 560 char *result);
484 561
485 562
@@ -490,75 +567,75 @@ GNUNET_RECLAIM_attestation_list_serialize (
490 * @param data_size the length of the serialized data 567 * @param data_size the length of the serialized data
491 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller 568 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller
492 */ 569 */
493struct GNUNET_RECLAIM_AttestationList * 570struct GNUNET_RECLAIM_CredentialList *
494GNUNET_RECLAIM_attestation_list_deserialize (const char *data, 571GNUNET_RECLAIM_credential_list_deserialize (const char *data,
495 size_t data_size); 572 size_t data_size);
496 573
497 574
498/** 575/**
499 * @param attestation the attestation to serialize 576 * @param credential the credential to serialize
500 * @return the required buffer size 577 * @return the required buffer size
501 */ 578 */
502size_t 579size_t
503GNUNET_RECLAIM_attestation_serialize_get_size ( 580GNUNET_RECLAIM_credential_serialize_get_size (
504 const struct GNUNET_RECLAIM_Attestation *attestation); 581 const struct GNUNET_RECLAIM_Credential *credential);
505 582
506 583
507/** 584/**
508 * Serialize an attestation 585 * Serialize an credential
509 * 586 *
510 * @param attestation the attestation to serialize 587 * @param credential the credential to serialize
511 * @param result the serialized attestation 588 * @param result the serialized credential
512 * @return length of serialized data 589 * @return length of serialized data
513 */ 590 */
514size_t 591size_t
515GNUNET_RECLAIM_attestation_serialize ( 592GNUNET_RECLAIM_credential_serialize (
516 const struct GNUNET_RECLAIM_Attestation *attestation, 593 const struct GNUNET_RECLAIM_Credential *credential,
517 char *result); 594 char *result);
518 595
519 596
520/** 597/**
521 * Deserialize an attestation 598 * Deserialize an credential
522 * 599 *
523 * @param data the serialized attestation 600 * @param data the serialized credential
524 * @param data_size the length of the serialized data 601 * @param data_size the length of the serialized data
525 * 602 *
526 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller 603 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
527 */ 604 */
528struct GNUNET_RECLAIM_Attestation * 605struct GNUNET_RECLAIM_Credential *
529GNUNET_RECLAIM_attestation_deserialize (const char *data, size_t data_size); 606GNUNET_RECLAIM_credential_deserialize (const char *data, size_t data_size);
530 607
531 608
532/** 609/**
533 * Create a new attestation. 610 * Create a new credential.
534 * 611 *
535 * @param name the attestation name 612 * @param name the credential name
536 * @param type the attestation type 613 * @param type the credential type
537 * @param data the attestation value 614 * @param data the credential value
538 * @param data_size the attestation value size 615 * @param data_size the credential value size
539 * @return the new attestation 616 * @return the new credential
540 */ 617 */
541struct GNUNET_RECLAIM_Attestation * 618struct GNUNET_RECLAIM_Credential *
542GNUNET_RECLAIM_attestation_new (const char *name, 619GNUNET_RECLAIM_credential_new (const char *name,
543 uint32_t type, 620 uint32_t type,
544 const void *data, 621 const void *data,
545 size_t data_size); 622 size_t data_size);
546 623
547/** 624/**
548 * Convert the 'claim' of an attestation to a string 625 * Convert the 'claim' of an credential to a string
549 * 626 *
550 * @param type the type of attestation 627 * @param type the type of credential
551 * @param data claim in binary encoding 628 * @param data claim in binary encoding
552 * @param data_size number of bytes in @a data 629 * @param data_size number of bytes in @a data
553 * @return NULL on error, otherwise human-readable representation of the claim 630 * @return NULL on error, otherwise human-readable representation of the claim
554 */ 631 */
555char * 632char *
556GNUNET_RECLAIM_attestation_value_to_string (uint32_t type, 633GNUNET_RECLAIM_credential_value_to_string (uint32_t type,
557 const void *data, 634 const void *data,
558 size_t data_size); 635 size_t data_size);
559 636
560/** 637/**
561 * Convert human-readable version of a 'claim' of an attestation to the binary 638 * Convert human-readable version of a 'claim' of an credential to the binary
562 * representation 639 * representation
563 * 640 *
564 * @param type type of the claim 641 * @param type type of the claim
@@ -568,48 +645,199 @@ GNUNET_RECLAIM_attestation_value_to_string (uint32_t type,
568 * @return #GNUNET_OK on success 645 * @return #GNUNET_OK on success
569 */ 646 */
570int 647int
571GNUNET_RECLAIM_attestation_string_to_value (uint32_t type, 648GNUNET_RECLAIM_credential_string_to_value (uint32_t type,
572 const char *s, 649 const char *s,
573 void **data, 650 void **data,
574 size_t *data_size); 651 size_t *data_size);
575 652
576/** 653/**
577 * Convert an attestation type number to the corresponding attestation type string 654 * Convert an credential type number to the corresponding credential type string
578 * 655 *
579 * @param type number of a type 656 * @param type number of a type
580 * @return corresponding typestring, NULL on error 657 * @return corresponding typestring, NULL on error
581 */ 658 */
582const char * 659const char *
583GNUNET_RECLAIM_attestation_number_to_typename (uint32_t type); 660GNUNET_RECLAIM_credential_number_to_typename (uint32_t type);
584 661
585/** 662/**
586 * Convert an attestation type name to the corresponding number 663 * Convert an credential type name to the corresponding number
587 * 664 *
588 * @param typename name to convert 665 * @param typename name to convert
589 * @return corresponding number, UINT32_MAX on error 666 * @return corresponding number, UINT32_MAX on error
590 */ 667 */
591uint32_t 668uint32_t
592GNUNET_RECLAIM_attestation_typename_to_number (const char *typename); 669GNUNET_RECLAIM_credential_typename_to_number (const char *typename);
593 670
594/** 671/**
595 * Convert an attestation type name to the corresponding number 672 * Convert an credential type name to the corresponding number
596 * 673 *
597 * @param typename name to convert 674 * @param typename name to convert
598 * @return corresponding number, UINT32_MAX on error 675 * @return corresponding number, UINT32_MAX on error
599 */ 676 */
600struct GNUNET_RECLAIM_AttributeList* 677struct GNUNET_RECLAIM_AttributeList*
601GNUNET_RECLAIM_attestation_get_attributes (const struct 678GNUNET_RECLAIM_credential_get_attributes (const struct
602 GNUNET_RECLAIM_Attestation *attest); 679 GNUNET_RECLAIM_Credential *cred);
603 680
604char* 681char*
605GNUNET_RECLAIM_attestation_get_issuer (const struct 682GNUNET_RECLAIM_credential_get_issuer (const struct
606 GNUNET_RECLAIM_Attestation *attest); 683 GNUNET_RECLAIM_Credential *cred);
607 684
608int 685int
609GNUNET_RECLAIM_attestation_get_expiration (const struct 686GNUNET_RECLAIM_credential_get_expiration (const struct
610 GNUNET_RECLAIM_Attestation *attest, 687 GNUNET_RECLAIM_Credential *cred,
611 struct GNUNET_TIME_Absolute *exp); 688 struct GNUNET_TIME_Absolute *exp);
612 689
690/**
691 * Get required size for serialization buffer
692 *
693 * @param presentations the presentation list to serialize
694 * @return the required buffer size
695 */
696size_t
697GNUNET_RECLAIM_presentation_list_serialize_get_size (
698 const struct GNUNET_RECLAIM_PresentationList *presentations);
699
700
701/**
702 * Destroy presentations list
703 *
704 * @param presentations list to destroy
705 */
706void
707GNUNET_RECLAIM_presentation_list_destroy (
708 struct GNUNET_RECLAIM_PresentationList *presentations);
709
710
711/**
712 * Serialize a presentation list
713 *
714 * @param presentations the attribute list to serialize
715 * @param result the serialized list
716 * @return length of serialized data
717 */
718size_t
719GNUNET_RECLAIM_presentation_list_serialize (
720 const struct GNUNET_RECLAIM_PresentationList *presentations,
721 char *result);
722
723
724/**
725 * Deserialize a presentation list
726 *
727 * @param data the serialized list
728 * @param data_size the length of the serialized data
729 * @return a GNUNET_RECLAIM_PresentationList, must be free'd by caller
730 */
731struct GNUNET_RECLAIM_PresentationList *
732GNUNET_RECLAIM_presentation_list_deserialize (const char *data,
733 size_t data_size);
734
735
736/**
737 * @param presentation the presentation to serialize
738 * @return the required buffer size
739 */
740size_t
741GNUNET_RECLAIM_presentation_serialize_get_size (
742 const struct GNUNET_RECLAIM_Presentation *presentation);
743
744
745/**
746 * Serialize a presentation.
747 *
748 * @param presentation the presentation to serialize
749 * @param result the serialized presentation
750 * @return length of serialized data
751 */
752size_t
753GNUNET_RECLAIM_presentation_serialize (
754 const struct GNUNET_RECLAIM_Presentation *presentation,
755 char *result);
756
757
758/**
759 * Deserialize a presentation
760 *
761 * @param data the serialized presentation
762 * @param data_size the length of the serialized data
763 *
764 * @return a GNUNET_RECLAIM_Presentation, must be free'd by caller
765 */
766struct GNUNET_RECLAIM_Presentation *
767GNUNET_RECLAIM_presentation_deserialize (const char *data, size_t data_size);
768
769
770/**
771 * Convert the 'claim' of a presentation to a string
772 *
773 * @param type the type of presentation
774 * @param data presentation in binary encoding
775 * @param data_size number of bytes in @a data
776 * @return NULL on error, otherwise human-readable representation of the claim
777 */
778char *
779GNUNET_RECLAIM_presentation_value_to_string (uint32_t type,
780 const void *data,
781 size_t data_size);
782
783/**
784 * Convert human-readable version of a 'claim' of a presentation to the binary
785 * representation
786 *
787 * @param type type of the presentation
788 * @param s human-readable string
789 * @param data set to value in binary encoding (will be allocated)
790 * @param data_size set to number of bytes in @a data
791 * @return #GNUNET_OK on success
792 */
793int
794GNUNET_RECLAIM_presentation_string_to_value (uint32_t type,
795 const char *s,
796 void **data,
797 size_t *data_size);
798
799/**
800 * Convert a presentation type number to the corresponding credential type
801 * string.
802 *
803 * @param type number of a type
804 * @return corresponding typestring, NULL on error
805 */
806const char *
807GNUNET_RECLAIM_presentation_number_to_typename (uint32_t type);
808
809struct GNUNET_RECLAIM_AttributeList*
810GNUNET_RECLAIM_presentation_get_attributes (const struct
811 GNUNET_RECLAIM_Presentation *cred);
812
813char*
814GNUNET_RECLAIM_presentation_get_issuer (const struct
815 GNUNET_RECLAIM_Presentation *cred);
816
817int
818GNUNET_RECLAIM_presentation_get_expiration (const struct
819 GNUNET_RECLAIM_Presentation *cred,
820 struct GNUNET_TIME_Absolute *exp);
821
822
823
824/**
825 * Create a presentation from a credential and a lift of (selected)
826 * attributes in the credential.
827 * FIXME not yet implemented
828 *
829 * @param cred the credential to use
830 * @param attrs the attributes to present from the credential
831 * @return the credential presentation presenting the attributes according
832 * to the presentation mechanism of the credential
833 * or NULL on error.
834 */
835struct GNUNET_RECLAIM_Presentation*
836GNUNET_RECLAIM_credential_get_presentation (
837 const struct GNUNET_RECLAIM_Credential *cred,
838 const struct GNUNET_RECLAIM_AttributeList *attrs);
839
840
613#if 0 /* keep Emacsens' auto-indent happy */ 841#if 0 /* keep Emacsens' auto-indent happy */
614{ 842{
615#endif 843#endif