diff options
Diffstat (limited to 'src/include/gnunet_identity_attribute_lib.h')
-rw-r--r-- | src/include/gnunet_identity_attribute_lib.h | 231 |
1 files changed, 231 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..039b50351 --- /dev/null +++ b/src/include/gnunet_identity_attribute_lib.h | |||
@@ -0,0 +1,231 @@ | |||
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 | ||
34 | extern "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 | */ | ||
59 | struct 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 | |||
91 | struct 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 | |||
104 | struct 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 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 | */ | ||
131 | struct GNUNET_IDENTITY_ATTRIBUTE_Claim * | ||
132 | GNUNET_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 | */ | ||
145 | size_t | ||
146 | GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); | ||
147 | |||
148 | void | ||
149 | GNUNET_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 | */ | ||
160 | size_t | ||
161 | GNUNET_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 | */ | ||
172 | struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList * | ||
173 | GNUNET_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 | */ | ||
184 | size_t | ||
185 | GNUNET_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 | */ | ||
197 | size_t | ||
198 | GNUNET_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 | */ | ||
209 | struct GNUNET_IDENTITY_ATTRIBUTE_Claim * | ||
210 | GNUNET_IDENTITY_ATTRIBUTE_deserialize (const char* data, | ||
211 | size_t data_size); | ||
212 | |||
213 | struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList* | ||
214 | GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); | ||
215 | |||
216 | |||
217 | |||
218 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
219 | { | ||
220 | #endif | ||
221 | #ifdef __cplusplus | ||
222 | } | ||
223 | #endif | ||
224 | |||
225 | |||
226 | /* ifndef GNUNET_IDENTITY_ATTRIBUTE_LIB_H */ | ||
227 | #endif | ||
228 | |||
229 | /** @} */ /* end of group identity */ | ||
230 | |||
231 | /* end of gnunet_identity_attribute_lib.h */ | ||