79dd101d0ecbf22f408897303b1619a5b6532814
[strongswan.git] / Source / charon / encoding / payloads / transform_substructure.h
1 /**
2 * @file transform_substructure.h
3 *
4 * @brief Interface of transform_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 TRANSFORM_SUBSTRUCTURE_H_
24 #define TRANSFORM_SUBSTRUCTURE_H_
25
26 #include <types.h>
27 #include <definitions.h>
28 #include <encoding/payloads/payload.h>
29 #include <encoding/payloads/transform_attribute.h>
30 #include <utils/linked_list.h>
31 #include <transforms/diffie_hellman.h>
32 #include <transforms/signers/signer.h>
33 #include <transforms/prfs/prf.h>
34 #include <transforms/crypters/crypter.h>
35 #include <config/child_proposal.h>
36
37
38 /**
39 * IKEv1 Value for a transform payload.
40 *
41 * @ingroup payloads
42 */
43 #define TRANSFORM_TYPE_VALUE 3
44
45 /**
46 * Length of the transform substructure header in bytes.
47 *
48 * @ingroup payloads
49 */
50 #define TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH 8
51
52
53 typedef struct transform_substructure_t transform_substructure_t;
54
55 /**
56 * @brief Class representing an IKEv2- TRANSFORM SUBSTRUCTURE.
57 *
58 * The TRANSFORM SUBSTRUCTURE format is described in RFC section 3.3.2.
59 *
60 * @ingroup payloads
61 */
62 struct transform_substructure_t {
63 /**
64 * The payload_t interface.
65 */
66 payload_t payload_interface;
67
68 /**
69 * @brief Creates an iterator of stored transform_attribute_t objects.
70 *
71 * @warning The created iterator has to get destroyed by the caller!
72 *
73 * @warning When deleting an transform attribute using this iterator,
74 * the length of this transform substructure has to be refreshed
75 * by calling get_length()!
76 *
77 * @param this calling transform_substructure_t object
78 * @param[in] forward iterator direction (TRUE: front to end)
79 * @return created iterator_t object.
80 */
81 iterator_t * (*create_transform_attribute_iterator) (transform_substructure_t *this, bool forward);
82
83 /**
84 * @brief Adds a transform_attribute_t object to this object.
85 *
86 * @warning The added proposal_substructure_t object is
87 * getting destroyed in destroy function of transform_substructure_t.
88 *
89 * @param this calling transform_substructure_t object
90 * @param proposal transform_attribute_t object to add
91 */
92 void (*add_transform_attribute) (transform_substructure_t *this,transform_attribute_t *attribute);
93
94 /**
95 * @brief Sets the next_payload field of this substructure
96 *
97 * If this is the last transform, next payload field is set to 0,
98 * otherwise to 3
99 *
100 * @param this calling transform_substructure_t object
101 * @param is_last When TRUE, next payload field is set to 0, otherwise to 3
102 */
103 void (*set_is_last_transform) (transform_substructure_t *this, bool is_last);
104
105 /**
106 * @brief Checks if this is the last transform.
107 *
108 * @param this calling transform_substructure_t object
109 * @return TRUE if this is the last Transform, FALSE otherwise
110 */
111 bool (*get_is_last_transform) (transform_substructure_t *this);
112
113 /**
114 * @brief Sets transform type of the current transform substructure.
115 *
116 * @param this calling transform_substructure_t object
117 * @param type type value to set
118 */
119 void (*set_transform_type) (transform_substructure_t *this,u_int8_t type);
120
121 /**
122 * @brief get transform type of the current transform.
123 *
124 * @param this calling transform_substructure_t object
125 * @return Transform type of current transform substructure.
126 */
127 u_int8_t (*get_transform_type) (transform_substructure_t *this);
128
129 /**
130 * @brief Sets transform id of the current transform substructure.
131 *
132 * @param this calling transform_substructure_t object
133 * @param id transform id to set
134 */
135 void (*set_transform_id) (transform_substructure_t *this,u_int16_t id);
136
137 /**
138 * @brief get transform id of the current transform.
139 *
140 * @param this calling transform_substructure_t object
141 * @return Transform id of current transform substructure.
142 */
143 u_int16_t (*get_transform_id) (transform_substructure_t *this);
144
145 /**
146 * @brief get transform id of the current transform.
147 *
148 * @param this calling transform_substructure_t object
149 * @param key_length The key length is written to this location
150 * @return
151 * - SUCCESS if a key length attribute is contained
152 * - FAILED if no key length attribute is part of this
153 * transform or key length uses more then 16 bit!
154 */
155 status_t (*get_key_length) (transform_substructure_t *this,u_int16_t *key_length);
156
157 /**
158 * @brief Clones an transform_substructure_t object.
159 *
160 * @param this transform_substructure_t object to clone
161 * @return cloned transform_substructure_t object
162 */
163 transform_substructure_t* (*clone) (transform_substructure_t *this);
164
165 /**
166 * @brief Destroys an transform_substructure_t object.
167 *
168 * @param this transform_substructure_t object to destroy
169 */
170 void (*destroy) (transform_substructure_t *this);
171 };
172
173 /**
174 * @brief Creates an empty transform_substructure_t object.
175 *
176 * @return created transform_substructure_t object
177 *
178 * @ingroup payloads
179 */
180 transform_substructure_t *transform_substructure_create();
181
182 /**
183 * @brief Creates an empty transform_substructure_t object.
184 *
185 * The key length is used for the transport types ENCRYPTION_ALGORITHM,
186 * PSEUDO_RANDOM_FUNCTION, INTEGRITY_ALGORITHM. For all
187 * other transport types the key_length parameter is not used
188 *
189 * @param transform_type type of transform to create
190 * @param transform_id transform id specifying the specific algorithm of a transform type
191 * @param key_length Key length for key lenght attribute
192 * @return transform_substructure_t object
193 *
194 * @ingroup payloads
195 */
196 transform_substructure_t *transform_substructure_create_type(transform_type_t transform_type, u_int16_t transform_id, u_int16_t key_length);
197
198 #endif /*TRANSFORM_SUBSTRUCTURE_H_*/