hide credentials headers in credential_factory.h
[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 implementations,
57 * so free up allocated ressources 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 * Create an enumerator for a builder type.
70 *
71 * The build() method has to be called on each enumerated builder to
72 * cleanup associated ressources.
73 *
74 * @param type type of credentials the builder creates
75 * @param subtype type specific subtype, such as certificate_type_t
76 * @return enumerator over builder_t
77 */
78 enumerator_t* (*create_builder_enumerator)(credential_factory_t *this,
79 credential_type_t type, int subtype);
80
81 /**
82 * Register a builder_t constructor function.
83 *
84 * @param type type of credential the builder creates
85 * @param constructor builder constructor function to register
86 */
87 void (*add_builder)(credential_factory_t *this,
88 credential_type_t type, int subtype,
89 builder_constructor_t constructor);
90 /**
91 * Unregister a builder_t constructor function.
92 *
93 * @param constructor constructor function to unregister.
94 */
95 void (*remove_builder)(credential_factory_t *this,
96 builder_constructor_t constructor);
97
98 /**
99 * Destroy a credential_factory instance.
100 */
101 void (*destroy)(credential_factory_t *this);
102 };
103
104 /**
105 * Create a credential_factory instance.
106 */
107 credential_factory_t *credential_factory_create();
108
109 #endif /** CREDENTIAL_FACTORY_H_ @}*/