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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @author Martin Schanzenbach
25 * Identity attribute definitions
27 * @defgroup identity-provider Identity Provider service
30 #ifndef GNUNET_IDENTITY_ATTRIBUTE_LIB_H
31 #define GNUNET_IDENTITY_ATTRIBUTE_LIB_H
36 #if 0 /* keep Emacsens' auto-indent happy */
41 #include "gnunet_util_lib.h"
47 #define GNUNET_IDENTITY_ATTRIBUTE_TYPE_NONE 0
52 #define GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING 1
59 struct GNUNET_IDENTITY_ATTRIBUTE_Claim
62 * The name of the attribute. Note "name" must never be individually
78 * Number of bytes in @e data.
83 * Binary value stored as attribute value. Note: "data" must never
84 * be individually 'malloc'ed, but instead always points into some
91 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList
96 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *list_head;
101 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *list_tail;
104 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry
109 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *prev;
114 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *next;
117 * The attribute claim
119 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim;
123 * Create a new attribute claim.
125 * @param attr_name the attribute name
126 * @param type the attribute type
127 * @param data the attribute value
128 * @param data_size the attribute value size
129 * @return the new attribute
131 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *
132 GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name,
139 * Get required size for serialization buffer
141 * @param attrs the attribute list to serialize
143 * @return the required buffer size
146 GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs);
149 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs);
152 GNUNET_IDENTITY_ATTRIBUTE_list_add (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
153 const char* attr_name,
159 * Serialize an attribute list
161 * @param attrs the attribute list to serialize
162 * @param result the serialized attribute
164 * @return length of serialized data
167 GNUNET_IDENTITY_ATTRIBUTE_list_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
171 * Deserialize an attribute list
173 * @param data the serialized attribute list
174 * @param data_size the length of the serialized data
176 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller
178 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *
179 GNUNET_IDENTITY_ATTRIBUTE_list_deserialize (const char* data,
184 * Get required size for serialization buffer
186 * @param attr the attribute to serialize
188 * @return the required buffer size
191 GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr);
196 * Serialize an attribute
198 * @param attr the attribute to serialize
199 * @param result the serialized attribute
201 * @return length of serialized data
204 GNUNET_IDENTITY_ATTRIBUTE_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr,
208 * Deserialize an attribute
210 * @param data the serialized attribute
211 * @param data_size the length of the serialized data
213 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
215 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *
216 GNUNET_IDENTITY_ATTRIBUTE_deserialize (const char* data,
219 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList*
220 GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs);
223 * Convert a type name to the corresponding number
225 * @param typename name to convert
226 * @return corresponding number, UINT32_MAX on error
229 GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (const char *typename);
232 * Convert human-readable version of a 'claim' of an attribute to the binary
235 * @param type type of the claim
236 * @param s human-readable string
237 * @param data set to value in binary encoding (will be allocated)
238 * @param data_size set to number of bytes in @a data
239 * @return #GNUNET_OK on success
242 GNUNET_IDENTITY_ATTRIBUTE_string_to_value (uint32_t type,
248 * Convert the 'claim' of an attribute to a string
250 * @param type the type of attribute
251 * @param data claim in binary encoding
252 * @param data_size number of bytes in @a data
253 * @return NULL on error, otherwise human-readable representation of the claim
256 GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type,
261 * Convert a type number to the corresponding type string
263 * @param type number of a type
264 * @return corresponding typestring, NULL on error
267 GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type);
270 #if 0 /* keep Emacsens' auto-indent happy */
278 /* ifndef GNUNET_IDENTITY_ATTRIBUTE_LIB_H */
281 /** @} */ /* end of group identity */
283 /* end of gnunet_identity_attribute_lib.h */