- dead end implementation
[strongswan.git] / Source / charon / encoding / payloads / sa_payload.h
1 /**
2 * @file sa_payload.h
3 *
4 * @brief Interface of sa_payload_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 SA_PAYLOAD_H_
24 #define SA_PAYLOAD_H_
25
26 #include <types.h>
27 #include <encoding/payloads/payload.h>
28 #include <encoding/payloads/proposal_substructure.h>
29 #include <utils/linked_list.h>
30 #include <config/init_config.h>
31 #include <config/sa_config.h>
32
33 /**
34 * Critical flag must not be set.
35 *
36 * @ingroup payloads
37 */
38 #define SA_PAYLOAD_CRITICAL_FLAG FALSE;
39
40 /**
41 * SA_PAYLOAD length in bytes without any proposal substructure.
42 *
43 * @ingroup payloads
44 */
45 #define SA_PAYLOAD_HEADER_LENGTH 4
46
47 typedef struct sa_payload_t sa_payload_t;
48
49 /**
50 * @brief Class representing an IKEv2-SA Payload.
51 *
52 * The SA Payload format is described in RFC section 3.3.
53 *
54 * @b Constructors:
55 * - sa_payload_create()
56 * - sa_payload_create_from_ike_proposals()
57 * - sa_payload_create_from_child_proposal()
58 *
59 * @todo Add support of algorithms without specified keylength in get_child_proposals and get_ike_proposals.
60 *
61 * @ingroup payloads
62 */
63 struct sa_payload_t {
64 /**
65 * The payload_t interface.
66 */
67 payload_t payload_interface;
68
69 /**
70 * @brief Creates an iterator of stored proposal_substructure_t objects.
71 *
72 * @warning The created iterator has to get destroyed by the caller!
73 *
74 * @warning When deleting an proposal using this iterator,
75 * the length of this transform substructure has to be refreshed
76 * by calling get_length()!
77 *
78 * @param this calling sa_payload_t object
79 * @param[in] forward iterator direction (TRUE: front to end)
80 * @return created iterator_t object
81 */
82 iterator_t *(*create_proposal_substructure_iterator) (sa_payload_t *this, bool forward);
83
84 /**
85 * @brief Adds a proposal_substructure_t object to this object.
86 *
87 * @warning The added proposal_substructure_t object is
88 * getting destroyed in destroy function of sa_payload_t.
89 *
90 * @param this calling sa_payload_t object
91 * @param proposal proposal_substructure_t object to add
92 */
93 void (*add_proposal_substructure) (sa_payload_t *this,proposal_substructure_t *proposal);
94
95 /**
96 * @brief Creates an array of ike_proposal_t's in this SA payload.
97 *
98 * An IKE proposal consist of transform of type ENCRYPTION_ALGORITHM,
99 * PSEUDO_RANDOM_FUNCTION, INTEGRITY_ALGORITHM and DIFFIE_HELLMAN_GROUP
100 *
101 * @param proposals the pointer to the first entry of ike_proposal_t's is set
102 * @param proposal_count the number of found proposals is written at this location
103 * @return
104 * - SUCCESS if an IKE proposal could be found
105 * - NOT_FOUND if no IKE proposal could be found
106 * - FAILED if a proposal does not contain all needed transforms
107 * for a IKE_PROPOSAL
108 */
109 status_t (*get_ike_proposals) (sa_payload_t *this, ike_proposal_t **proposals, size_t *proposal_count);
110
111 /**
112 * @brief Creates an array of child_proposal_t's in this SA payload.
113 *
114 * @param proposals the pointer to the first entry of child_proposal_t's is set
115 * @param proposal_count the number of found proposals is written at this location
116 * @return
117 * - SUCCESS if child proposals could be found
118 * - NOT_FOUND if no child proposal could be found
119 * - FAILED if a proposal does not contain all needed transforms
120 */
121 status_t (*get_child_proposals) (sa_payload_t *this, child_proposal_t **proposals, size_t *proposal_count);
122
123 /**
124 * @brief Add a child proposal (AH/ESP) to the payload.
125 *
126 * @param proposal child proposal to add to the payload
127 */
128 void (*add_child_proposal) (sa_payload_t *this, child_proposal_t *proposal);
129
130 /**
131 * @brief Destroys an sa_payload_t object.
132 *
133 * @param this sa_payload_t object to destroy
134 */
135 void (*destroy) (sa_payload_t *this);
136 };
137
138 /**
139 * @brief Creates an empty sa_payload_t object
140 *
141 * @return created sa_payload_t object
142 *
143 * @ingroup payloads
144 */
145 sa_payload_t *sa_payload_create();
146
147 /**
148 * @brief Creates a sa_payload_t object from array of ike_proposal_t's.
149 *
150 * @return created sa_payload_t object
151 * @param proposals pointer to first proposal in array of type ike_proposal_t
152 * @param proposal_count number of ike_proposal_t's in array
153 * @return sa_payload_t object
154 *
155 * @ingroup payloads
156 */
157 sa_payload_t *sa_payload_create_from_ike_proposals(ike_proposal_t *proposals, size_t proposal_count);
158
159
160 #endif /*SA_PAYLOAD_H_*/