merged the modularization branch (credentials) back to trunk
[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/keys/private_key.h>
28 #include <credentials/keys/public_key.h>
29 #include <credentials/certificates/certificate.h>
30 #include <credentials/builder.h>
31
32 /**
33 * Kind of credential.
34 */
35 enum credential_type_t {
36 /** private key, implemented in private_key_t */
37 CRED_PRIVATE_KEY,
38 /** public key, implemented in public_key_t */
39 CRED_PUBLIC_KEY,
40 /** certificates, implemented in certificate_t */
41 CRED_CERTIFICATE,
42 };
43
44 /**
45 * Manages credential construction functions and creates instances.
46 */
47 struct credential_factory_t {
48
49 /**
50 * Create a credential using a list of builder_part_t's.
51 *
52 * The variable argument list takes builder_part_t types followed
53 * by the type specific value. The list must be terminated using BUILD_END.
54 *
55 * @param type credential type to build
56 * @param subtype subtype specific for type of the credential
57 * @param ... build_part_t arguments, BUILD_END terminated.
58 * @return type specific credential, NULL if failed
59 */
60 void* (*create)(credential_factory_t *this, credential_type_t type,
61 int subtype, ...);
62
63 /**
64 * Create a builder instance to build credentials.
65 *
66 * @param type type of credentials the builder creates
67 * @param subtype type specific subtype, such as certificate_type_t
68 * @return builder instance
69 */
70 builder_t* (*create_builder)(credential_factory_t *this,
71 credential_type_t type, int subtype);
72 /**
73 * Register a builder_t constructor function.
74 *
75 * @param type type of credential the builder creates
76 * @param constructor builder constructor function to register
77 */
78 void (*add_builder)(credential_factory_t *this,
79 credential_type_t type, int subtype,
80 builder_constructor_t constructor);
81 /**
82 * Unregister a builder_t constructor function.
83 *
84 * @param constructor constructor function to unregister.
85 */
86 void (*remove_builder)(credential_factory_t *this,
87 builder_constructor_t constructor);
88
89 /**
90 * Destroy a credential_factory instance.
91 */
92 void (*destroy)(credential_factory_t *this);
93 };
94
95 /**
96 * Create a credential_factory instance.
97 */
98 credential_factory_t *credential_factory_create();
99
100 #endif /* CREDENTIAL_FACTORY_H_ @}*/