aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_reclaim_attribute_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_reclaim_attribute_lib.h')
-rw-r--r--src/include/gnunet_reclaim_attribute_lib.h287
1 files changed, 287 insertions, 0 deletions
diff --git a/src/include/gnunet_reclaim_attribute_lib.h b/src/include/gnunet_reclaim_attribute_lib.h
new file mode 100644
index 000000000..9b928328e
--- /dev/null
+++ b/src/include/gnunet_reclaim_attribute_lib.h
@@ -0,0 +1,287 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2017 GNUnet e.V.
4
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.
9
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.
14
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/>.
17*/
18
19/**
20 * @author Martin Schanzenbach
21 *
22 * @file
23 * Identity attribute definitions
24 *
25 * @defgroup identity-provider Identity Provider service
26 * @{
27 */
28#ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H
29#define GNUNET_RECLAIM_ATTRIBUTE_LIB_H
30
31#ifdef __cplusplus
32extern "C"
33{
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39#include "gnunet_util_lib.h"
40
41
42/**
43 * No value attribute.
44 */
45#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE 0
46
47/**
48 * String attribute.
49 */
50#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING 1
51
52
53/**
54 * ZKlaim attribute.
55 */
56#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_ZKLAIM 2
57
58
59
60/**
61 * An attribute.
62 */
63struct GNUNET_RECLAIM_ATTRIBUTE_Claim
64{
65 /**
66 * The name of the attribute. Note "name" must never be individually
67 * free'd
68 */
69 const char* name;
70
71 /**
72 * Type of Claim
73 */
74 uint32_t type;
75
76 /**
77 * Version
78 */
79 uint32_t version;
80
81 /**
82 * Number of bytes in @e data.
83 */
84 size_t data_size;
85
86 /**
87 * Binary value stored as attribute value. Note: "data" must never
88 * be individually 'malloc'ed, but instead always points into some
89 * existing data area.
90 */
91 const void *data;
92
93};
94
95struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList
96{
97 /**
98 * List head
99 */
100 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_head;
101
102 /**
103 * List tail
104 */
105 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_tail;
106};
107
108struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry
109{
110 /**
111 * DLL
112 */
113 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *prev;
114
115 /**
116 * DLL
117 */
118 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *next;
119
120 /**
121 * The attribute claim
122 */
123 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
124};
125
126/**
127 * Create a new attribute claim.
128 *
129 * @param attr_name the attribute name
130 * @param type the attribute type
131 * @param data the attribute value
132 * @param data_size the attribute value size
133 * @return the new attribute
134 */
135struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
136GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char* attr_name,
137 uint32_t type,
138 const void* data,
139 size_t data_size);
140
141
142/**
143 * Get required size for serialization buffer
144 *
145 * @param attrs the attribute list to serialize
146 *
147 * @return the required buffer size
148 */
149size_t
150GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
151
152void
153GNUNET_RECLAIM_ATTRIBUTE_list_destroy (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
154
155void
156GNUNET_RECLAIM_ATTRIBUTE_list_add (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
157 const char* attr_name,
158 uint32_t type,
159 const void* data,
160 size_t data_size);
161
162/**
163 * Serialize an attribute list
164 *
165 * @param attrs the attribute list to serialize
166 * @param result the serialized attribute
167 *
168 * @return length of serialized data
169 */
170size_t
171GNUNET_RECLAIM_ATTRIBUTE_list_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
172 char *result);
173
174/**
175 * Deserialize an attribute list
176 *
177 * @param data the serialized attribute list
178 * @param data_size the length of the serialized data
179 *
180 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller
181 */
182struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
183GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char* data,
184 size_t data_size);
185
186
187/**
188 * Get required size for serialization buffer
189 *
190 * @param attr the attribute to serialize
191 *
192 * @return the required buffer size
193 */
194size_t
195GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr);
196
197
198
199/**
200 * Serialize an attribute
201 *
202 * @param attr the attribute to serialize
203 * @param result the serialized attribute
204 *
205 * @return length of serialized data
206 */
207size_t
208GNUNET_RECLAIM_ATTRIBUTE_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
209 char *result);
210
211/**
212 * Deserialize an attribute
213 *
214 * @param data the serialized attribute
215 * @param data_size the length of the serialized data
216 *
217 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
218 */
219struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
220GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char* data,
221 size_t data_size);
222
223struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList*
224GNUNET_RECLAIM_ATTRIBUTE_list_dup (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
225
226/**
227 * Convert a type name to the corresponding number
228 *
229 * @param typename name to convert
230 * @return corresponding number, UINT32_MAX on error
231 */
232uint32_t
233GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename);
234
235/**
236 * Convert human-readable version of a 'claim' of an attribute to the binary
237 * representation
238 *
239 * @param type type of the claim
240 * @param s human-readable string
241 * @param data set to value in binary encoding (will be allocated)
242 * @param data_size set to number of bytes in @a data
243 * @return #GNUNET_OK on success
244 */
245int
246GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type,
247 const char *s,
248 void **data,
249 size_t *data_size);
250
251/**
252 * Convert the 'claim' of an attribute to a string
253 *
254 * @param type the type of attribute
255 * @param data claim in binary encoding
256 * @param data_size number of bytes in @a data
257 * @return NULL on error, otherwise human-readable representation of the claim
258 */
259char *
260GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type,
261 const void* data,
262 size_t data_size);
263
264/**
265 * Convert a type number to the corresponding type string
266 *
267 * @param type number of a type
268 * @return corresponding typestring, NULL on error
269 */
270const char*
271GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type);
272
273
274#if 0 /* keep Emacsens' auto-indent happy */
275{
276#endif
277#ifdef __cplusplus
278}
279#endif
280
281
282/* ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H */
283#endif
284
285/** @} */ /* end of group identity */
286
287/* end of gnunet_reclaim_attribute_lib.h */