Some documentation corrections
[strongswan.git] / src / libstrongswan / credentials / credential_factory.h
1 /*
2 * Copyright (C) 2008 Martin Willi
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 * @defgroup credential_factory credential_factory
18 * @{ @ingroup credentials
19 */
20
21 #ifndef CREDENTIAL_FACTORY_H_
22 #define CREDENTIAL_FACTORY_H_
23
24 typedef struct credential_factory_t credential_factory_t;
25 typedef enum credential_type_t credential_type_t;
26
27 #include <credentials/builder.h>
28
29 /**
30 * Kind of credential.
31 */
32 enum credential_type_t {
33 /** private key, implemented in private_key_t */
34 CRED_PRIVATE_KEY,
35 /** public key, implemented in public_key_t */
36 CRED_PUBLIC_KEY,
37 /** certificates, implemented in certificate_t */
38 CRED_CERTIFICATE,
39 };
40
41 /**
42 * enum names for credential_type_t
43 */
44 extern enum_name_t *credential_type_names;
45
46 /**
47 * Manages credential construction functions and creates instances.
48 */
49 struct credential_factory_t {
50
51 /**
52 * Create a credential using a list of builder_part_t's.
53 *
54 * The variable argument list takes builder_part_t types followed
55 * by the type specific value. The list must be terminated using BUILD_END.
56 * All passed parts get cloned/refcounted by the builder functions,
57 * so free up allocated resources after successful and unsuccessful
58 * invocations.
59 *
60 * @param type credential type to build
61 * @param subtype subtype specific for type of the credential
62 * @param ... build_part_t arguments, BUILD_END terminated.
63 * @return type specific credential, NULL if failed
64 */
65 void* (*create)(credential_factory_t *this, credential_type_t type,
66 int subtype, ...);
67
68 /**
69 * Register a credential builder function.
70 *
71 * The final flag indicates if the registered builder can build such
72 * a credential itself the most common encoding, without the need
73 * for an additional builder.
74 *
75 * @param type type of credential the builder creates
76 * @param subtype subtype of the credential, type specific
77 * @param final TRUE if this build does not invoke other builders
78 * @param constructor builder constructor function to register
79 */
80 void (*add_builder)(credential_factory_t *this,
81 credential_type_t type, int subtype, bool final,
82 builder_function_t constructor);
83 /**
84 * Unregister a credential builder function.
85 *
86 * @param constructor constructor function to unregister.
87 */
88 void (*remove_builder)(credential_factory_t *this,
89 builder_function_t constructor);
90
91 /**
92 * Create an enumerator over registered builder types.
93 *
94 * The enumerator returns only builder types registered with the final
95 * flag set.
96 *
97 * @return enumerator (credential_type_t, int subtype)
98 */
99 enumerator_t* (*create_builder_enumerator)(credential_factory_t *this);
100
101 /**
102 * Destroy a credential_factory instance.
103 */
104 void (*destroy)(credential_factory_t *this);
105 };
106
107 /**
108 * Create a credential_factory instance.
109 */
110 credential_factory_t *credential_factory_create();
111
112 #endif /** CREDENTIAL_FACTORY_H_ @}*/