refactored openac and its attribute certificate factory
[strongswan.git] / src / libstrongswan / credentials / builder.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 builder builder
18 * @{ @ingroup credentials
19 */
20
21 #ifndef BUILDER_H_
22 #define BUILDER_H_
23
24 typedef struct builder_t builder_t;
25 typedef enum builder_part_t builder_part_t;
26
27 /**
28 * Constructor function which creates a new builder instance.
29 *
30 * @param subtype constructor specific subtype, e.g. certificate_type_t
31 * @return builder to construct a instance of type
32 */
33 typedef builder_t* (*builder_constructor_t)(int subtype);
34
35 #include <library.h>
36
37 /**
38 * Parts to build credentials from.
39 */
40 enum builder_part_t {
41 /** DER encoded ASN1 blob, argument is a chunk_t */
42 BUILD_BLOB_ASN1_DER,
43 /** key size in bits, as used for key generation, as u_int */
44 BUILD_KEY_SIZE,
45 /** private key to use for signing, private_key_t* */
46 BUILD_SIGNING_KEY,
47 /** certificate used for signing, certificate_t* */
48 BUILD_SIGNING_CERT,
49 /** public key to include, public_key_t* */
50 BUILD_PUBLIC_KEY,
51 /** subject for e.g. certificates, identification_t* */
52 BUILD_SUBJECT,
53 /** additional subject name, identification_t* */
54 BUILD_SUBJECT_ALTNAME,
55 /** issuer for e.g. certificates, identification_t* */
56 BUILD_ISSUER,
57 /** additional issuer name, identification_t* */
58 BUILD_ISSUER_ALTNAME,
59 /** notBefore, time_t* */
60 BUILD_NOT_BEFORE_TIME,
61 /** notAfter, time_t* */
62 BUILD_NOT_AFTER_TIME,
63 /** a CA certificate, certificate_t* */
64 BUILD_CA_CERT,
65 /** a certificate, certificate_t* */
66 BUILD_CERT,
67 /** enforce an additional X509 flag, x509_flag_t */
68 BUILD_X509_FLAG,
69 /** end of variable argument builder list */
70 BUILD_END,
71 };
72
73 /**
74 * enum names for build_part_t
75 */
76 extern enum_name_t *builder_part_names;
77
78 /**
79 * Credential construction API.
80 *
81 * The builder allows the construction of credentials in a generic and
82 * flexible way.
83 */
84 struct builder_t {
85
86 /**
87 * Add a part to the construct.
88 *
89 * Any added parts get owned by the builder/construct, so clone/refcount
90 * them if needed.
91 *
92 * @param part kind of part
93 * @param ... part specific variable argument
94 */
95 void (*add)(builder_t *this, builder_part_t part, ...);
96
97 /**
98 * Build the construct with all supplied parts.
99 *
100 * Once build() is called, the builder gets destroyed.
101 *
102 * @return specific interface, as requested with constructor.
103 */
104 void* (*build)(builder_t *this);
105 };
106
107 #endif /* BUILDER_H_ @}*/