implemented and tested functionality to create sa_payload from
[strongswan.git] / Source / charon / encoding / payloads / proposal_substructure.h
1 /**
2 * @file proposal_substructure.h
3 *
4 * @brief Interface of proposal_substructure_t.
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 PROPOSAL_SUBSTRUCTURE_H_
24 #define PROPOSAL_SUBSTRUCTURE_H_
25
26 #include <types.h>
27 #include <encoding/payloads/payload.h>
28 #include <encoding/payloads/transform_substructure.h>
29 #include <utils/linked_list.h>
30
31 /**
32 * IKEv1 Value for a proposal payload.
33 *
34 * @ingroup payloads
35 */
36 #define PROPOSAL_TYPE_VALUE 2
37
38 /**
39 * Length of the proposal substructure header
40 * (without spi).
41 *
42 * @ingroup payloads
43 */
44 #define PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH 8
45
46
47 typedef enum protocol_id_t protocol_id_t;
48
49 /**
50 * Protocol ID of a proposal.
51 *
52 * @ingroup payloads
53 */
54 enum protocol_id_t {
55 UNDEFINED_PROTOCOL_ID = 201,
56 IKE = 1,
57 AH = 2,
58 ESP = 3,
59 };
60
61 typedef struct proposal_substructure_t proposal_substructure_t;
62
63 /**
64 * Object representing an IKEv2-PROPOSAL SUBSTRUCTURE.
65 *
66 * The PROPOSAL SUBSTRUCTURE format is described in RFC section 3.3.1.
67 *
68 * @ingroup payloads
69 */
70 struct proposal_substructure_t {
71 /**
72 * The payload_t interface.
73 */
74 payload_t payload_interface;
75
76 /**
77 * @brief Creates an iterator of stored transform_substructure_t objects.
78 *
79 * @warning The created iterator has to get destroyed by the caller!
80 * When deleting any transform over this iterator, call
81 * get_size to make sure the length and number values are ok.
82 *
83 * @param this calling proposal_substructure_t object
84 * @param[in] forward iterator direction (TRUE: front to end)
85 * @return created iterator_t object
86 */
87 iterator_t * (*create_transform_substructure_iterator) (proposal_substructure_t *this, bool forward);
88
89 /**
90 * @brief Adds a transform_substructure_t object to this object.
91 *
92 * @warning The added transform_substructure_t object is
93 * getting destroyed in destroy function of proposal_substructure_t.
94 *
95 * @param this calling proposal_substructure_t object
96 * @param transform transform_substructure_t object to add
97 */
98 void (*add_transform_substructure) (proposal_substructure_t *this,transform_substructure_t *transform);
99
100 /**
101 * @brief Sets the proposal number of current proposal.
102 *
103 * @param this calling proposal_substructure_t object
104 * @param id proposal number to set
105 */
106 void (*set_proposal_number) (proposal_substructure_t *this,u_int8_t proposal_number);
107
108 /**
109 * @brief get proposal number of current proposal.
110 *
111 * @param this calling proposal_substructure_t object
112 * @return proposal number of current proposal substructure.
113 */
114 u_int8_t (*get_proposal_number) (proposal_substructure_t *this);
115
116 /**
117 * @brief get the number of transforms in current proposal.
118 *
119 * @param this calling proposal_substructure_t object
120 * @return transform count in current proposal
121 */
122 size_t (*get_transform_count) (proposal_substructure_t *this);
123
124 /**
125 * @brief get size of the set spi in bytes.
126 *
127 * @param this calling proposal_substructure_t object
128 * @return size of the spi in bytes
129 */
130 size_t (*get_spi_size) (proposal_substructure_t *this);
131
132 /**
133 * @brief Sets the protocol id of current proposal.
134 *
135 * @param this calling proposal_substructure_t object
136 * @param id protocol id to set
137 */
138 void (*set_protocol_id) (proposal_substructure_t *this,u_int8_t protocol_id);
139
140 /**
141 * @brief get protocol id of current proposal.
142 *
143 * @param this calling proposal_substructure_t object
144 * @return protocol id of current proposal substructure.
145 */
146 u_int8_t (*get_protocol_id) (proposal_substructure_t *this);
147
148 /**
149 * @brief Get informations for a specific transform type.
150 *
151 * @param this calling proposal_substructure_t object
152 * @param type type to get informations for
153 * @param transform_id transform id of the specific type
154 * @param key_length key length of the specific key length transform attribute
155 * @return
156 * - SUCCESS if transform type is part of this proposal and
157 * all data (incl. key length) could be fetched
158 * - NOT_FOUND if transform type is not part of this proposal
159 */
160 status_t (*get_info_for_transform_type) (proposal_substructure_t *this,transform_type_t type, u_int16_t *transform_id, u_int16_t *key_length);
161
162 /**
163 * @brief Sets the next_payload field of this substructure
164 *
165 * If this is the last proposal, next payload field is set to 0,
166 * otherwise to 2
167 *
168 * @param this calling proposal_substructure_t object
169 * @param is_last When TRUE, next payload field is set to 0, otherwise to 2
170 */
171 void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last);
172
173 /**
174 * @brief Returns the currently set SPI of this proposal.
175 *
176 * @warning Returned data are not copied
177 *
178 * @param this calling proposal_substructure_t object
179 * @return chunk_t pointing to the value
180 */
181 chunk_t (*get_spi) (proposal_substructure_t *this);
182
183 /**
184 * @brief Sets the SPI of the current proposal.
185 *
186 * @warning SPI is getting copied
187 *
188 * @param this calling proposal_substructure_t object
189 * @param spi chunk_t pointing to the value to set
190 */
191 void (*set_spi) (proposal_substructure_t *this, chunk_t spi);
192
193 /**
194 * @brief Clones an proposal_substructure_t object.
195 *
196 * @param this proposal_substructure_t object to clone
197 * @return cloned object
198 */
199 proposal_substructure_t* (*clone) (proposal_substructure_t *this);
200
201 /**
202 * @brief Destroys an proposal_substructure_t object.
203 *
204 * @param this proposal_substructure_t object to destroy
205 */
206 void (*destroy) (proposal_substructure_t *this);
207 };
208
209 /**
210 * @brief Creates an empty proposal_substructure_t object
211 *
212 * @return created proposal_substructure_t object
213 *
214 * @ingroup payloads
215 */
216 proposal_substructure_t *proposal_substructure_create();
217
218
219
220 #endif /*PROPOSAL_SUBSTRUCTURE_H_*/