87ac2a8b2fa10b83676dae15a3c892fca3636dd6
[strongswan.git] / Source / lib / utils / identification.h
1 /**
2 * @file identification.h
3 *
4 * @brief Interface of identification_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 IDENTIFICATION_H_
25 #define IDENTIFICATION_H_
26
27
28 #include "types.h"
29
30 typedef enum id_type_t id_type_t;
31
32 /**
33 * @brief ID Types in a ID payload.
34 *
35 * @see
36 * - identification_t
37 * - id_payload_t
38 *
39 * @ingroup utils
40 */
41 enum id_type_t {
42
43 /**
44 * ID data is a single four (4) octet IPv4 address.
45 */
46 ID_IPV4_ADDR = 1,
47
48 /**
49 * ID data is a fully-qualified domain name string.
50 * An example of a ID_FQDN is, "example.com".
51 * The string MUST not contain any terminators (e.g., NULL, CR, etc.).
52 */
53 ID_FQDN = 2,
54
55 /**
56 * ID data is a fully-qualified RFC822 email address string, An example of
57 * a ID_RFC822_ADDR is, "jsmith@example.com". The string MUST
58 * not contain any terminators.
59 */
60 ID_RFC822_ADDR = 3,
61
62 /**
63 * ID data is a single sixteen (16) octet IPv6 address.
64 */
65 ID_IPV6_ADDR = 5,
66
67 /**
68 * ID data is the binary DER encoding of an ASN.1 X.500 Distinguished Name
69 * [X.501].
70 */
71 ID_DER_ASN1_DN = 9,
72
73 /**
74 * ID data is the binary DER encoding of an ASN.1 X.500 GeneralName
75 * [X.509].
76 */
77 ID_DER_ASN1_GN = 10,
78
79 /**
80 * ID data is an opaque octet stream which may be used to pass vendor-
81 * specific information necessary to do certain proprietary
82 * types of identification.
83 */
84 ID_KEY_ID = 11
85 };
86
87 /**
88 * String mappings for id_type_t.
89 */
90 extern mapping_t id_type_m[];
91
92 typedef struct identification_t identification_t;
93
94 /**
95 * @brief Generic identification, such as used in ID payload.
96 *
97 * The following types are possible:
98 * - ID_IPV4_ADDR
99 * - ID_FQDN*
100 * - ID_RFC822_ADDR*
101 * - ID_IPV6_ADDR*
102 * - ID_DER_ASN1_DN*
103 * - ID_DER_ASN1_GN*
104 * - ID_KEY_ID*
105 * (* = string conversion not supported)
106 *
107 * @b Constructors:
108 * - identification_create_from_string()
109 * - identification_create_from_encoding()
110 *
111 * @todo Support for other ID types then ID_IPV4_ADDR.
112 *
113 * @ingroup utils
114 */
115 struct identification_t {
116
117 /**
118 * @brief Get the encoding of this id, to send over
119 * the network.
120 *
121 * @warning Result points to internal data, do NOT free!
122 *
123 * @param this the identification_t object
124 * @return a chunk containing the encoded bytes
125 */
126 chunk_t (*get_encoding) (identification_t *this);
127
128 /**
129 * @brief Get the type of this identification.
130 *
131 * @param this the identification_t object
132 * @return id_type_t
133 */
134 id_type_t (*get_type) (identification_t *this);
135
136 /**
137 * @brief Get a string representation of this id.
138 *
139 * @warning Result points to internal data, do NOT free!
140 *
141 * @param this the identification_t object
142 * @return string
143 */
144 char *(*get_string) (identification_t *this);
145
146 /**
147 * @brief Check if two identification_t objects are equal.
148 *
149 * @param this the identification_t object
150 * @param other other identification_t object
151 * @return TRUE if the IDs are equal
152 */
153 bool (*equals) (identification_t *this,identification_t *other);
154
155 /**
156 * @brief Check if an ID belongs to a wildcard ID.
157 *
158 * An identification_t may contain wildcards, such as
159 * *@strongswan.org. This call checks if a given ID
160 * (e.g. tester@strongswan.org) belongs to a such wildcard
161 * ID. Returns TRUE if IDs are identical.
162 *
163 * @param this the ID containing a wildcard
164 * @param other the ID without wildcard
165 * @return TRUE if other belongs to this
166 */
167 bool (*belongs_to) (identification_t *this, identification_t *other);
168
169 /**
170 * @brief Clone a identification_t instance.
171 *
172 * @param this the identification_t object to clone
173 * @return clone of this
174 */
175 identification_t *(*clone) (identification_t *this);
176
177 /**
178 * @brief Destroys a identification_t object.
179 *
180 * @param this identification_t object
181 */
182 void (*destroy) (identification_t *this);
183 };
184
185 /**
186 * @brief Creates an identification_t object from a string.
187 *
188 * @param type type of this id, such as ID_IPV4_ADDR
189 * @param string input string, which will be converted
190 * @return
191 * - created identification_t object, or
192 * - NULL if type not supported.
193 *
194 * @ingroup utils
195 */
196 identification_t * identification_create_from_string(id_type_t type, char *string);
197
198 /**
199 * @brief Creates an identification_t object from an encoded chunk.
200 *
201 * @param type type of this id, such as ID_IPV4_ADDR
202 * @param encoded encoded bytes, such as from identification_t.get_encoding
203 * @return identification_t object
204 *
205 * @ingroup utils
206 */
207 identification_t * identification_create_from_encoding(id_type_t type, chunk_t encoded);
208
209
210 #endif /* IDENTIFICATION_H_ */