- added and tested auth_payload_t class
[strongswan.git] / Source / charon / encoding / payloads / encodings.h
1 /**
2 * @file encodings.h
3 *
4 * @brief Encoding types of fields in a IKEv2 payload.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef ENCODINGS_H_
24 #define ENCODINGS_H_
25
26 #include <types.h>
27 #include <definitions.h>
28
29
30 typedef enum encoding_type_t encoding_type_t;
31
32 /**
33 * @brief All different kinds of encoding types.
34 *
35 * Each field of an IKEv2-Message (in header or payload)
36 * which has to be parsed or generated differently has its own
37 * type defined here.
38 *
39 * Header is parsed like a payload and gets its one payload_id
40 * from PRIVATE USE space. Also the substructures
41 * of specific payload types get their own payload_id
42 * from PRIVATE_USE space. See IKEv2-Draft for more informations.
43 *
44 * @ingroup payloads
45 */
46 enum encoding_type_t{
47 /**
48 * Representing a 4 Bit unsigned int value.
49 *
50 *
51 * When generating it must be changed from host to network order.
52 * The value is read from the associated data struct.
53 * The current write position is moved 4 bit forward afterwards.
54 *
55 * When parsing it must be changed from network to host order.
56 * The value is written to the associated data struct.
57 * The current read pointer is moved 4 bit forward afterwards.
58 */
59 U_INT_4,
60 /**
61 * Representing a 8 Bit unsigned int value.
62 *
63 *
64 * When generating it must be changed from host to network order.
65 * The value is read from the associated data struct.
66 * The current write position is moved 8 bit forward afterwards.
67 *
68 * When parsing it must be changed from network to host order.
69 * The value is written to the associated data struct.
70 * The current read pointer is moved 8 bit forward afterwards.
71 */
72 U_INT_8,
73 /**
74 * Representing a 16 Bit unsigned int value.
75 *
76 *
77 * When generating it must be changed from host to network order.
78 * The value is read from the associated data struct.
79 * The current write position is moved 16 bit forward afterwards.
80 *
81 * When parsing it must be changed from network to host order.
82 * The value is written to the associated data struct.
83 * The current read pointer is moved 16 bit forward afterwards.
84 */
85 U_INT_16,
86 /**
87 * Representing a 32 Bit unsigned int value.
88 *
89 * When generating it must be changed from host to network order.
90 * The value is read from the associated data struct.
91 * The current write position is moved 32 bit forward afterwards.
92 *
93 * When parsing it must be changed from network to host order.
94 * The value is written to the associated data struct.
95 * The current read pointer is moved 32 bit forward afterwards.
96 */
97
98 U_INT_32,
99 /**
100 * Representing a 64 Bit unsigned int value.
101 *
102 * When generating it must be changed from host to network order.
103 * The value is read from the associated data struct.
104 * The current write position is moved 64 bit forward afterwards.
105 *
106 * When parsing it must be changed from network to host order.
107 * The value is written to the associated data struct.
108 * The current read pointer is moved 64 bit forward afterwards.
109 */
110 U_INT_64,
111 /**
112 * @brief represents a RESERVED_BIT used in FLAG-Bytes.
113 *
114 * When generating, the next bit is set to zero and the current write
115 * position is moved one bit forward.
116 * No value is read from the associated data struct.
117 * The current write position is moved 1 bit forward afterwards.
118 *
119 * When parsing, the current read pointer is moved one bit forward.
120 * No value is written to the associated data struct.
121 * The current read pointer is moved 1 bit forward afterwards.
122 */
123 RESERVED_BIT,
124 /**
125 * @brief represents a RESERVED_BYTE.
126 *
127 * When generating, the next byte is set to zero and the current write
128 * position is moved one byte forward.
129 * No value is read from the associated data struct.
130 * The current write position is moved 1 byte forward afterwards.
131 *
132 * When parsing, the current read pointer is moved one byte forward.
133 * No value is written to the associated data struct.
134 * The current read pointer is moved 1 byte forward afterwards.
135 */
136 RESERVED_BYTE,
137 /**
138 * Representing a 1 Bit flag.
139 *
140 * When generation, the next bit is set to 1 if the associated value
141 * in the data struct is TRUE, 0 otherwise. The current write position
142 * is moved 1 bit forward afterwards.
143 *
144 * When parsing, the next bit is read and stored in the associated data
145 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
146 * is moved 1 bit forward afterwards
147 */
148 FLAG,
149 /**
150 * Representating a length field of a payload.
151 *
152 * When generating it must be changed from host to network order.
153 * The value is read from the associated data struct.
154 * The current write position is moved 16 bit forward afterwards.
155 *
156 * When parsing it must be changed from network to host order.
157 * The value is written to the associated data struct.
158 * The current read pointer is moved 16 bit forward afterwards.
159 */
160 PAYLOAD_LENGTH,
161 /**
162 * Representating a length field of a header.
163 *
164 * When generating it must be changed from host to network order.
165 * The value is read from the associated data struct.
166 * The current write position is moved 32 bit forward afterwards.
167 *
168 * When parsing it must be changed from network to host order.
169 * The value is written to the associated data struct.
170 * The current read pointer is moved 32 bit forward afterwards.
171 */
172 HEADER_LENGTH,
173 /**
174 * Representating a spi size field.
175 *
176 * When generating it must be changed from host to network order.
177 * The value is read from the associated data struct.
178 * The current write position is moved 8 bit forward afterwards.
179 *
180 * When parsing it must be changed from network to host order.
181 * The value is written to the associated data struct.
182 * The current read pointer is moved 8 bit forward afterwards.
183 */
184 SPI_SIZE,
185 /**
186 * Representating a spi field.
187 *
188 * When generating the content of the chunkt pointing to
189 * is written.
190 *
191 * When parsing SPI_SIZE bytes are read and written into the chunk pointing to.
192 */
193 SPI,
194 /**
195 * Representating a Key Exchange Data field.
196 *
197 * When generating the content of the chunkt pointing to
198 * is written.
199 *
200 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
201 */
202 KEY_EXCHANGE_DATA,
203 /**
204 * Representating a Notification field.
205 *
206 * When generating the content of the chunkt pointing to
207 * is written.
208 *
209 * When parsing (Payload Length - spi size - 8) bytes are read and written into the chunk pointing to.
210 */
211 NOTIFICATION_DATA,
212 /**
213 * Representating one or more proposal substructures.
214 *
215 * The offset points to a linked_list_t pointer.
216 *
217 * When generating the proposal_substructure_t objects are stored
218 * in the pointed linked_list.
219 *
220 * When parsing the parsed proposal_substructure_t objects have
221 * to be stored in the pointed linked_list.
222 */
223 PROPOSALS,
224 /**
225 * Representating one or more transform substructures.
226 *
227 * The offset points to a linked_list_t pointer.
228 *
229 * When generating the transform_substructure_t objects are stored
230 * in the pointed linked_list.
231 *
232 * When parsing the parsed transform_substructure_t objects have
233 * to be stored in the pointed linked_list.
234 */
235 TRANSFORMS,
236 /**
237 * Representating one or more Attributes of a transform substructure.
238 *
239 * The offset points to a linked_list_t pointer.
240 *
241 * When generating the transform_attribute_t objects are stored
242 * in the pointed linked_list.
243 *
244 * When parsing the parsed transform_attribute_t objects have
245 * to be stored in the pointed linked_list.
246 */
247 TRANSFORM_ATTRIBUTES,
248 /**
249 * Representing a 1 Bit flag specifying the format of a transform attribute.
250 *
251 * When generation, the next bit is set to 1 if the associated value
252 * in the data struct is TRUE, 0 otherwise. The current write position
253 * is moved 1 bit forward afterwards.
254 *
255 * When parsing, the next bit is read and stored in the associated data
256 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
257 * is moved 1 bit forward afterwards.
258 */
259 ATTRIBUTE_FORMAT,
260 /**
261 * Representing a 15 Bit unsigned int value used as attribute type
262 * in an attribute transform.
263 *
264 *
265 * When generating it must be changed from host to network order.
266 * The value is read from the associated data struct.
267 * The current write position is moved 15 bit forward afterwards.
268 *
269 * When parsing it must be changed from network to host order.
270 * The value is written to the associated data struct.
271 * The current read pointer is moved 15 bit forward afterwards.
272 */
273 ATTRIBUTE_TYPE,
274
275 /**
276 * Depending on the field of type ATTRIBUTE_FORMAT
277 * this field contains the length or the value of an transform attribute.
278 * Its stored in a 16 unsigned integer field.
279 *
280 * When generating it must be changed from host to network order.
281 * The value is read from the associated data struct.
282 * The current write position is moved 16 bit forward afterwards.
283 *
284 * When parsing it must be changed from network to host order.
285 * The value is written to the associated data struct.
286 * The current read pointer is moved 16 bit forward afterwards.
287 */
288 ATTRIBUTE_LENGTH_OR_VALUE,
289
290 /**
291 * Depending on the field of type ATTRIBUTE_FORMAT
292 * this field is available or missing and so parsed/generated
293 * or not parsed/not generated.
294 *
295 * When generating the content of the chunkt pointing to
296 * is written.
297 *
298 * When parsing SPI_SIZE bytes are read and written into the chunk pointing to.
299 */
300 ATTRIBUTE_VALUE,
301
302 /**
303 * Representating a Nonce Data field.
304 *
305 * When generating the content of the chunkt pointing to
306 * is written.
307 *
308 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
309 */
310 NONCE_DATA,
311
312 /**
313 * Representating a ID Data field.
314 *
315 * When generating the content of the chunkt pointing to
316 * is written.
317 *
318 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
319 */
320 ID_DATA,
321
322 /**
323 * Representating a AUTH Data field.
324 *
325 * When generating the content of the chunkt pointing to
326 * is written.
327 *
328 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
329 */
330 AUTH_DATA,
331
332 /**
333 * Representating an IKE_SPI field in an IKEv2 Header.
334 *
335 * When generating the value of the u_int64_t pointing to
336 * is written (host and networ order is not changed).
337 *
338 * When parsing 8 bytes are read and written into the u_int64_t pointing to.
339 */
340 IKE_SPI,
341
342 /**
343 * Representing the encrypted data body of a encryption payload.
344 */
345 ENCRYPTED_DATA,
346
347 };
348
349 /**
350 * mappings to map encoding_type_t's to strings
351 */
352 extern mapping_t encoding_type_m[];
353
354 typedef struct encoding_rule_t encoding_rule_t;
355
356 /**
357 * An encoding rule is a mapping of a specific encoding type to
358 * a location in the data struct where the current field is stored to
359 * or read from.
360 *
361 * For examples see files in this directory.
362 *
363 * This rules are used by parser and generator.
364 *
365 * @ingroup payloads
366 */
367 struct encoding_rule_t {
368 /**
369 * Encoding type.
370 */
371 encoding_type_t type;
372
373 /**
374 * Offset in the data struct.
375 *
376 * When parsing, data are written to this offset of the
377 * data struct.
378 *
379 * When generating, data are read from this offset in the
380 * data struct.
381 */
382 u_int32_t offset;
383 };
384
385 #endif /*ENCODINGS_H_*/