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