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
57 struct GNUNET_RECLAIM_ATTRIBUTE_Claim
74 * The name of the attribute. Note "name" must never be individually
80 * Number of bytes in @e data.
85 * Binary value stored as attribute value. Note: "data" must never
86 * be individually 'malloc'ed, but instead always points into some
94 * A list of GNUNET_RECLAIM_ATTRIBUTE_Claim structures.
96 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList
101 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_head;
106 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_tail;
110 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry
115 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *prev;
120 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *next;
123 * The attribute claim
125 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
130 * Create a new attribute claim.
132 * @param attr_name the attribute name
133 * @param type the attribute type
134 * @param data the attribute value
135 * @param data_size the attribute value size
136 * @return the new attribute
138 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
139 GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name,
146 * Get required size for serialization buffer
148 * @param attrs the attribute list to serialize
149 * @return the required buffer size
152 GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (
153 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
159 * @param attrs list to destroy
162 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (
163 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
167 * Add a new attribute to a claim list
169 * @param attr_name the name of the new attribute claim
170 * @param type the type of the claim
171 * @param data claim payload
172 * @param data_size claim payload size
175 GNUNET_RECLAIM_ATTRIBUTE_list_add (
176 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
177 const char *attr_name,
184 * Serialize an attribute list
186 * @param attrs the attribute list to serialize
187 * @param result the serialized attribute
188 * @return length of serialized data
191 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (
192 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
197 * Deserialize an attribute list
199 * @param data the serialized attribute list
200 * @param data_size the length of the serialized data
201 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller
203 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
204 GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size);
208 * Get required size for serialization buffer
210 * @param attr the attribute to serialize
211 * @return the required buffer size
214 GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (
215 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr);
219 * Serialize an attribute
221 * @param attr the attribute to serialize
222 * @param result the serialized attribute
223 * @return length of serialized data
226 GNUNET_RECLAIM_ATTRIBUTE_serialize (
227 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
232 * Deserialize an attribute
234 * @param data the serialized attribute
235 * @param data_size the length of the serialized data
237 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
239 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
240 GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size);
244 * Make a (deep) copy of a claim list
245 * @param attrs claim list to copy
246 * @return copied claim list
248 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
249 GNUNET_RECLAIM_ATTRIBUTE_list_dup (
250 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
254 * Convert a type name to the corresponding number
256 * @param typename name to convert
257 * @return corresponding number, UINT32_MAX on error
260 GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename);
263 * Convert human-readable version of a 'claim' of an attribute to the binary
266 * @param type type of the claim
267 * @param s human-readable string
268 * @param data set to value in binary encoding (will be allocated)
269 * @param data_size set to number of bytes in @a data
270 * @return #GNUNET_OK on success
273 GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type,
280 * Convert the 'claim' of an attribute to a string
282 * @param type the type of attribute
283 * @param data claim in binary encoding
284 * @param data_size number of bytes in @a data
285 * @return NULL on error, otherwise human-readable representation of the claim
288 GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type,
294 * Convert a type number to the corresponding type string
296 * @param type number of a type
297 * @return corresponding typestring, NULL on error
300 GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type);
303 #if 0 /* keep Emacsens' auto-indent happy */
311 /* ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H */
314 /** @} */ /* end of group reclaim-attribute */
316 /* end of gnunet_reclaim_attribute_lib.h */