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 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.
17 * @author Martin Schanzenbach
20 * Identity attribute definitions
22 * @defgroup identity-provider Identity Provider service
25 #ifndef GNUNET_IDENTITY_ATTRIBUTE_LIB_H
26 #define GNUNET_IDENTITY_ATTRIBUTE_LIB_H
31 #if 0 /* keep Emacsens' auto-indent happy */
36 #include "gnunet_util_lib.h"
42 #define GNUNET_IDENTITY_ATTRIBUTE_TYPE_NONE 0
47 #define GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING 1
54 struct GNUNET_IDENTITY_ATTRIBUTE_Claim
57 * The name of the attribute. Note "name" must never be individually
73 * Number of bytes in @e data.
78 * Binary value stored as attribute value. Note: "data" must never
79 * be individually 'malloc'ed, but instead always points into some
86 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList
91 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *list_head;
96 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *list_tail;
99 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry
104 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *prev;
109 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *next;
112 * The attribute claim
114 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim;
118 * Create a new attribute claim.
120 * @param attr_name the attribute name
121 * @param type the attribute type
122 * @param data the attribute value
123 * @param data_size the attribute value size
124 * @return the new attribute
126 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *
127 GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name,
134 * Get required size for serialization buffer
136 * @param attrs the attribute list to serialize
138 * @return the required buffer size
141 GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs);
144 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs);
147 GNUNET_IDENTITY_ATTRIBUTE_list_add (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
148 const char* attr_name,
154 * Serialize an attribute list
156 * @param attrs the attribute list to serialize
157 * @param result the serialized attribute
159 * @return length of serialized data
162 GNUNET_IDENTITY_ATTRIBUTE_list_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
166 * Deserialize an attribute list
168 * @param data the serialized attribute list
169 * @param data_size the length of the serialized data
171 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller
173 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *
174 GNUNET_IDENTITY_ATTRIBUTE_list_deserialize (const char* data,
179 * Get required size for serialization buffer
181 * @param attr the attribute to serialize
183 * @return the required buffer size
186 GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr);
191 * Serialize an attribute
193 * @param attr the attribute to serialize
194 * @param result the serialized attribute
196 * @return length of serialized data
199 GNUNET_IDENTITY_ATTRIBUTE_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr,
203 * Deserialize an attribute
205 * @param data the serialized attribute
206 * @param data_size the length of the serialized data
208 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
210 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *
211 GNUNET_IDENTITY_ATTRIBUTE_deserialize (const char* data,
214 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList*
215 GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs);
218 * Convert a type name to the corresponding number
220 * @param typename name to convert
221 * @return corresponding number, UINT32_MAX on error
224 GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (const char *typename);
227 * Convert human-readable version of a 'claim' of an attribute to the binary
230 * @param type type of the claim
231 * @param s human-readable string
232 * @param data set to value in binary encoding (will be allocated)
233 * @param data_size set to number of bytes in @a data
234 * @return #GNUNET_OK on success
237 GNUNET_IDENTITY_ATTRIBUTE_string_to_value (uint32_t type,
243 * Convert the 'claim' of an attribute to a string
245 * @param type the type of attribute
246 * @param data claim in binary encoding
247 * @param data_size number of bytes in @a data
248 * @return NULL on error, otherwise human-readable representation of the claim
251 GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type,
256 * Convert a type number to the corresponding type string
258 * @param type number of a type
259 * @return corresponding typestring, NULL on error
262 GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type);
265 #if 0 /* keep Emacsens' auto-indent happy */
273 /* ifndef GNUNET_IDENTITY_ATTRIBUTE_LIB_H */
276 /** @} */ /* end of group identity */
278 /* end of gnunet_identity_attribute_lib.h */