implemented and tested functionality to create sa_payload from
[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
32 /**
33 * Critical flag must not be set.
34 *
35 * @ingroup payloads
36 */
37 #define SA_PAYLOAD_CRITICAL_FLAG FALSE;
38
39 /**
40 * SA_PAYLOAD length in bytes without any proposal substructure.
41 *
42 * @ingroup payloads
43 */
44 #define SA_PAYLOAD_HEADER_LENGTH 4
45
46 typedef struct sa_payload_t sa_payload_t;
47
48 /**
49 * Class representing an IKEv2-SA Payload.
50 *
51 * The SA Payload format is described in RFC section 3.3.
52 *
53 * @ingroup payloads
54 */
55 struct sa_payload_t {
56 /**
57 * The payload_t interface.
58 */
59 payload_t payload_interface;
60
61 /**
62 * @brief Creates an iterator of stored proposal_substructure_t objects.
63 *
64 * @warning The created iterator has to get destroyed by the caller!
65 *
66 * @warning When deleting an proposal using this iterator,
67 * the length of this transform substructure has to be refreshed
68 * by calling get_length()!
69 *
70 * @param this calling sa_payload_t object
71 * @param[in] forward iterator direction (TRUE: front to end)
72 * @return created iterator_t object
73 */
74 iterator_t *(*create_proposal_substructure_iterator) (sa_payload_t *this, bool forward);
75
76 /**
77 * @brief Adds a proposal_substructure_t object to this object.
78 *
79 * @warning The added proposal_substructure_t object is
80 * getting destroyed in destroy function of sa_payload_t.
81 *
82 * @param this calling sa_payload_t object
83 * @param proposal proposal_substructure_t object to add
84 */
85 void (*add_proposal_substructure) (sa_payload_t *this,proposal_substructure_t *proposal);
86
87 /**
88 * Creates an array of ike_proposal_t's in this SA payload.
89 *
90 * An IKE proposal consist of transform of type ENCRYPTION_ALGORITHM,
91 * PSEUDO_RANDOM_FUNCTION, INTEGRITY_ALGORITHM and DIFFIE_HELLMAN_GROUP
92 *
93 * @param proposals the pointer to the first entry of ike_proposal_t's is set
94 * @param proposal_count the number of found proposals is written at this location
95 * @return
96 * - SUCCESS if an IKE proposal could be found
97 * - NOT_FOUND if no IKE proposal could be found
98 * - FAILED if a proposal does not contain all needed transforms
99 * for a IKE_PROPOSAL
100 */
101 status_t (*get_ike_proposals) (sa_payload_t *this, ike_proposal_t **proposals, size_t *proposal_count);
102
103 /**
104 * @brief Destroys an sa_payload_t object.
105 *
106 * @param this sa_payload_t object to destroy
107 */
108 void (*destroy) (sa_payload_t *this);
109 };
110
111 /**
112 * @brief Creates an empty sa_payload_t object
113 *
114 * @return created sa_payload_t object
115 *
116 * @ingroup payloads
117 */
118 sa_payload_t *sa_payload_create();
119
120 /**
121 * @brief Creates a sa_payload_t object from array of ike_proposal_t's.
122 *
123 * @return created sa_payload_t object
124 * @param proposals pointer to first proposal in array of type ike_proposal_t
125 * @param proposal_count number of ike_proposal_t's in array
126 *
127 * @ingroup payloads
128 */
129 sa_payload_t *sa_payload_create_from_ike_proposals(ike_proposal_t *proposals, size_t proposal_count);
130
131 #endif /*SA_PAYLOAD_H_*/