2 This file is part of GNUnet.
3 Copyright (C) 2017 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Martin Schanzenbach
25 * Identity attribute definitions
27 * @defgroup reclaim-attribute reclaim attributes
30 #ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H
31 #define GNUNET_RECLAIM_ATTRIBUTE_LIB_H
35 #if 0 /* keep Emacsens' auto-indent happy */
40 #include "gnunet_util_lib.h"
46 #define GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE 0
51 #define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING 1
54 * No value attestation.
56 #define GNUNET_RECLAIM_ATTESTATION_TYPE_NONE 10
59 * A JSON Web Token attestation.
61 #define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT 11
66 struct GNUNET_RECLAIM_ATTRIBUTE_Claim
83 * The name of the attribute. Note "name" must never be individually
89 * Number of bytes in @e data.
94 * Binary value stored as attribute value. Note: "data" must never
95 * be individually 'malloc'ed, but instead always points into some
104 struct GNUNET_RECLAIM_ATTESTATION_Claim
112 * Type/Format of Claim
122 * The name of the attribute. Note "name" must never be individually
128 * Number of bytes in @e data.
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.
141 * A reference to an Attestatiom.
143 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE
151 * Referenced ID of Attestation
156 * The name of the attribute/attestation reference value. Note "name" must never be individually
162 * The name of the attribute/attestation reference value. Note "name" must never be individually
165 const char *reference_value;
169 * A list of GNUNET_RECLAIM_ATTRIBUTE_Claim structures.
171 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList
176 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_head;
181 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_tail;
185 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry
190 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *prev;
195 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *next;
198 * The attribute claim
200 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
202 * The attestation claim
204 struct GNUNET_RECLAIM_ATTESTATION_Claim *attest;
209 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference;
212 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType
219 * Create a new attribute claim.
221 * @param attr_name the attribute name
222 * @param type the attribute type
223 * @param data the attribute value
224 * @param data_size the attribute value size
225 * @return the new attribute
227 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
228 GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name,
235 * Get required size for serialization buffer
237 * @param attrs the attribute list to serialize
238 * @return the required buffer size
241 GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (
242 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
248 * @param attrs list to destroy
251 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (
252 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
256 * Add a new attribute to a claim list
258 * @param attr_name the name of the new attribute claim
259 * @param type the type of the claim
260 * @param data claim payload
261 * @param data_size claim payload size
264 GNUNET_RECLAIM_ATTRIBUTE_list_add (
265 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
266 const char *attr_name,
273 * Serialize an attribute list
275 * @param attrs the attribute list to serialize
276 * @param result the serialized attribute
277 * @return length of serialized data
280 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (
281 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
286 * Deserialize an attribute list
288 * @param data the serialized attribute list
289 * @param data_size the length of the serialized data
290 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller
292 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
293 GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size);
296 * Count attestations in claim list
301 GNUNET_RECLAIM_ATTRIBUTE_list_count_attest (
302 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
305 * Get required size for serialization buffer
307 * @param attr the attribute to serialize
308 * @return the required buffer size
311 GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (
312 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr);
316 * Serialize an attribute
318 * @param attr the attribute to serialize
319 * @param result the serialized attribute
320 * @return length of serialized data
323 GNUNET_RECLAIM_ATTRIBUTE_serialize (
324 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
329 * Deserialize an attribute
331 * @param data the serialized attribute
332 * @param data_size the length of the serialized data
334 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
336 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
337 GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size);
341 * Make a (deep) copy of a claim list
342 * @param attrs claim list to copy
343 * @return copied claim list
345 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
346 GNUNET_RECLAIM_ATTRIBUTE_list_dup (
347 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
351 * Convert a type name to the corresponding number
353 * @param typename name to convert
354 * @return corresponding number, UINT32_MAX on error
357 GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename);
360 * Convert human-readable version of a 'claim' of an attribute to the binary
363 * @param type type of the claim
364 * @param s human-readable string
365 * @param data set to value in binary encoding (will be allocated)
366 * @param data_size set to number of bytes in @a data
367 * @return #GNUNET_OK on success
370 GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type,
377 * Convert the 'claim' of an attribute to a string
379 * @param type the type of attribute
380 * @param data claim in binary encoding
381 * @param data_size number of bytes in @a data
382 * @return NULL on error, otherwise human-readable representation of the claim
385 GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type,
391 * Convert a type number to the corresponding type string
393 * @param type number of a type
394 * @return corresponding typestring, NULL on error
397 GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type);
400 * Get required size for serialization buffer
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.
408 * @param attr the attestation to serialize
409 * @return the required buffer size
412 GNUNET_RECLAIM_ATTESTATION_serialize_get_size (
413 const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr);
417 * Serialize an attestation
419 * @param attr the attestation to serialize
420 * @param result the serialized attestation
421 * @return length of serialized data
424 GNUNET_RECLAIM_ATTESTATION_serialize (
425 const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr,
430 * Deserialize an attestation
432 * @param data the serialized attestation
433 * @param data_size the length of the serialized data
435 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
437 struct GNUNET_RECLAIM_ATTESTATION_Claim *
438 GNUNET_RECLAIM_ATTESTATION_deserialize (const char *data, size_t data_size);
442 * Create a new attestation.
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
450 struct GNUNET_RECLAIM_ATTESTATION_Claim *
451 GNUNET_RECLAIM_ATTESTATION_claim_new (const char *attr_name,
457 * Convert the 'claim' of an attestation to a string
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
465 GNUNET_RECLAIM_ATTESTATION_value_to_string (uint32_t type,
470 * Convert human-readable version of a 'claim' of an attestation to the binary
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
480 GNUNET_RECLAIM_ATTESTATION_string_to_value (uint32_t type,
486 * Convert an attestation type number to the corresponding attestation type string
488 * @param type number of a type
489 * @return corresponding typestring, NULL on error
492 GNUNET_RECLAIM_ATTESTATION_number_to_typename (uint32_t type);
495 * Convert an attestation type name to the corresponding number
497 * @param typename name to convert
498 * @return corresponding number, UINT32_MAX on error
501 GNUNET_RECLAIM_ATTESTATION_typename_to_number (const char *typename);
504 * Create a new attestation reference.
506 * @param attr_name the referenced claim name
507 * @param ref_value the claim name in the attestation
508 * @return the new reference
510 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *
511 GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name,
512 const char *ref_value);
516 * Get required size for serialization buffer
518 * @param attr the reference to serialize
519 * @return the required buffer size
522 GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (
523 const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr);
526 * Serialize a reference
528 * @param attr the reference to serialize
529 * @param result the serialized reference
530 * @return length of serialized data
533 GNUNET_RECLAIM_ATTESTATION_REF_serialize (
534 const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr,
538 * Deserialize a reference
540 * @param data the serialized reference
541 * @param data_size the length of the serialized data
543 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
545 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *
546 GNUNET_RECLAIM_ATTESTATION_REF_deserialize (const char *data, size_t data_size);
548 #if 0 /* keep Emacsens' auto-indent happy */
556 /* ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H */
559 /** @} */ /* end of group reclaim-attribute */
561 /* end of gnunet_reclaim_attribute_lib.h */