proposal: Add possibility to register custom proposal keyword parser
[strongswan.git] / src / libstrongswan / crypto / proposal / proposal_keywords.h
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /*
17 * Copyright (c) 2012 Nanoteq Pty Ltd
18 *
19 * Permission is hereby granted, free of charge, to any person obtaining a copy
20 * of this software and associated documentation files (the "Software"), to deal
21 * in the Software without restriction, including without limitation the rights
22 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 * copies of the Software, and to permit persons to whom the Software is
24 * furnished to do so, subject to the following conditions:
25 *
26 * The above copyright notice and this permission notice shall be included in
27 * all copies or substantial portions of the Software.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
35 * THE SOFTWARE.
36 */
37
38 /**
39 * @defgroup proposal_keywords proposal_keywords
40 * @{ @ingroup crypto
41 */
42
43 #ifndef PROPOSAL_KEYWORDS_H_
44 #define PROPOSAL_KEYWORDS_H_
45
46 typedef struct proposal_token_t proposal_token_t;
47 typedef struct proposal_keywords_t proposal_keywords_t;
48
49 typedef proposal_token_t*(*proposal_algname_parser_t)(const char *algname);
50
51 #include <library.h>
52 #include <crypto/transform.h>
53
54 /**
55 * Class representing a proposal token.
56 */
57 struct proposal_token_t {
58
59 /**
60 * The name of the token.
61 */
62 char *name;
63
64 /**
65 * The type of transform in the token.
66 */
67 transform_type_t type;
68
69 /**
70 * The IKE id of the algorithm.
71 */
72 u_int16_t algorithm;
73
74 /**
75 * The key size associated with the specific algorithm.
76 */
77 u_int16_t keysize;
78 };
79
80 /**
81 * Class to manage proposal keywords
82 */
83 struct proposal_keywords_t {
84
85 /**
86 * Returns the proposal token for the specified string if a token exists.
87 *
88 * @param str the string containing the name of the token
89 * @return proposal_token if found, NULL otherwise
90 */
91 const proposal_token_t *(*get_token)(proposal_keywords_t *this,
92 const char *str);
93
94 /**
95 * Register a new proposal token for an algorithm.
96 *
97 * @param name the string containing the name of the token
98 * @param type the transform_type_t for the token
99 * @param algorithm the IKE id of the algorithm
100 * @param keysize the key size associated with the specific algorithm
101 */
102 void (*register_token)(proposal_keywords_t *this, const char *name,
103 transform_type_t type, u_int16_t algorithm,
104 u_int16_t keysize);
105
106 /**
107 * Register an algorithm name parser.
108 *
109 * It is meant to parse an algorithm name into a proposal token in a
110 * generic, user defined way.
111 *
112 * @param parser a pointer to the parser function
113 */
114 void (*register_algname_parser)(proposal_keywords_t *this,
115 proposal_algname_parser_t parser);
116
117 /**
118 * Destroy a proposal_keywords_t instance.
119 */
120 void (*destroy)(proposal_keywords_t *this);
121 };
122
123 /**
124 * Create a proposal_keywords_t instance.
125 */
126 proposal_keywords_t *proposal_keywords_create();
127
128 #endif /** PROPOSAL_KEYWORDS_H_ @}*/