(no commit message)
[strongswan.git] / Source / charon / encoding / payloads / id_payload.h
1 /**
2 * @file id_payload.h
3 *
4 * @brief Interface of id_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
24 #ifndef _ID_PAYLOAD_H_
25 #define _ID_PAYLOAD_H_
26
27 #include <types.h>
28 #include <encoding/payloads/payload.h>
29
30 /**
31 * Length of a nonce payload without a nonce in bytes.
32 *
33 * @ingroup payloads
34 */
35 #define ID_PAYLOAD_HEADER_LENGTH 8
36
37
38 typedef enum id_type_t id_type_t;
39
40 /**
41 * ID Types of a ID payload.
42 *
43 * @ingroup payloads
44 */
45 enum id_type_t {
46 /**
47 * ID data is a single four (4) octet IPv4 address.
48 */
49 ID_IPV4_ADDR = 1,
50
51 /**
52 * ID data is a fully-qualified domain name string.
53 * An example of a ID_FQDN is, "example.com".
54 * The string MUST not contain any terminators (e.g., NULL, CR, etc.).
55 */
56 ID_FQDN = 2,
57
58 /**
59 * ID data is a fully-qualified RFC822 email address string, An example of
60 * a ID_RFC822_ADDR is, "jsmith@example.com". The string MUST
61 * not contain any terminators.
62 */
63 ID_RFC822_ADDR = 3,
64
65 /**
66 * ID data is a single sixteen (16) octet IPv6 address.
67 */
68 ID_IPV6_ADDR = 5,
69
70 /**
71 * ID data is the binary DER encoding of an ASN.1 X.500 Distinguished Name
72 * [X.501].
73 */
74 ID_DER_ASN1_DN = 9,
75
76 /**
77 * ID data is the binary DER encoding of an ASN.1 X.500 GeneralName
78 * [X.509].
79 */
80 ID_DER_ASN1_GN = 10,
81
82 /**
83 * ID data is an opaque octet stream which may be used to pass vendor-
84 * specific information necessary to do certain proprietary
85 * types of identification.
86 */
87 ID_KEY_ID = 11
88 };
89
90 extern mapping_t id_type_m[];
91
92
93 typedef struct id_payload_t id_payload_t;
94
95 /**
96 * Object representing an IKEv2 ID payload.
97 *
98 * The ID payload format is described in draft section 3.5.
99 *
100 * @ingroup payloads
101 *
102 */
103 struct id_payload_t {
104 /**
105 * The payload_t interface.
106 */
107 payload_t payload_interface;
108
109 /**
110 * @brief Set the ID type.
111 *
112 *
113 * @param this calling id_payload_t object
114 * @param type Type of ID
115 */
116 void (*set_id_type) (id_payload_t *this, id_type_t type);
117
118 /**
119 * @brief Get the ID type.
120 *
121 * @param this calling id_payload_t object
122 * @return type of the ID
123 */
124 id_type_t (*get_id_type) (id_payload_t *this);
125
126 /**
127 * @brief Set the ID data.
128 *
129 * Data are getting cloned.
130 *
131 * @param this calling id_payload_t object
132 * @param data ID data as chunk_t
133 */
134 void (*set_data) (id_payload_t *this, chunk_t data);
135
136 /**
137 * @brief Get the ID data.
138 *
139 * Returned data are a copy of the internal one
140 *
141 * @param this calling id_payload_t object
142 * @return ID data as chunk_t
143 */
144 chunk_t (*get_data) (id_payload_t *this);
145
146 /**
147 * @brief Get the type of ID payload (IDi or IDr).
148 *
149 * @param this calling id_payload_t object
150 * @return
151 * - TRUE if this payload is of type IDi
152 * - FALSE if this payload is of type IDr
153 *
154 */
155 bool (*get_initiator) (id_payload_t *this);
156
157 /**
158 * @brief Set the type of ID payload (IDi or IDr).
159 *
160 * @param this calling id_payload_t object
161 * @param is_initiator
162 * - TRUE if this payload is of type IDi
163 * - FALSE if this payload is of type IDr
164 *
165 */
166 void (*set_initiator) (id_payload_t *this,bool is_initiator);
167
168 /**
169 * @brief Destroys an id_payload_t object.
170 *
171 * @param this id_payload_t object to destroy
172 */
173 void (*destroy) (id_payload_t *this);
174 };
175
176 /**
177 * @brief Creates an empty id_payload_t object.
178 *
179 * As default a ID payload of type IDi is created.
180 *
181 * @param is_initiator
182 * - TRUE if this payload is of type IDi
183 * - FALSE if this payload is of type IDr
184 *
185 * @return created id_payload_t object
186 *
187 * @ingroup payloads
188 */
189 id_payload_t *id_payload_create(bool is_initiator);
190
191
192 #endif //_ID_PAYLOAD_H_