1 /*
2  * Copyright (c) 2011 Collabora Ltd.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  *     * Redistributions of source code must retain the above
9  *       copyright notice, this list of conditions and the
10  *       following disclaimer.
11  *     * Redistributions in binary form must reproduce the
12  *       above copyright notice, this list of conditions and
13  *       the following disclaimer in the documentation and/or
14  *       other materials provided with the distribution.
15  *     * The names of contributors to this software may not be
16  *       used to endorse or promote products derived from this
17  *       software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
29  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30  * DAMAGE.
31  *
32  * Author: Stef Walter <stefw@collabora.co.uk>
33  */
34 
35 #ifndef __P11_KIT_H__
36 #define __P11_KIT_H__
37 
38 #include "p11-kit/pkcs11.h"
39 
40 /*
41  * If the caller is using the PKCS#11 GNU calling convention, then we cater
42  * to that here.
43  */
44 #ifdef CRYPTOKI_GNU
45 typedef ck_rv_t CK_RV;
46 typedef struct ck_function_list* CK_FUNCTION_LIST_PTR;
47 typedef struct ck_function_list CK_FUNCTION_LIST;
48 #endif
49 
50 #include "p11-kit/deprecated.h"
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 enum {
57 	P11_KIT_MODULE_UNMANAGED = 1 << 0,
58 	P11_KIT_MODULE_CRITICAL = 1 << 1,
59 	P11_KIT_MODULE_TRUSTED = 1 << 2,
60 	P11_KIT_MODULE_VERBOSE = 1 << 3,
61 	P11_KIT_MODULE_MASK = (1 << 4) - 1
62 };
63 
64 typedef void        (* p11_kit_destroyer)                   (void *data);
65 
66 CK_FUNCTION_LIST **    p11_kit_modules_load                 (const char *reserved,
67                                                              int flags);
68 
69 CK_RV                  p11_kit_modules_initialize           (CK_FUNCTION_LIST **modules,
70                                                              p11_kit_destroyer failure_callback);
71 
72 CK_FUNCTION_LIST **    p11_kit_modules_load_and_initialize  (int flags);
73 
74 CK_RV                  p11_kit_modules_finalize             (CK_FUNCTION_LIST **modules);
75 
76 void                   p11_kit_modules_release              (CK_FUNCTION_LIST **modules);
77 
78 void                   p11_kit_modules_finalize_and_release (CK_FUNCTION_LIST **modules);
79 
80 CK_FUNCTION_LIST *     p11_kit_module_for_name              (CK_FUNCTION_LIST **modules,
81                                                              const char *name);
82 
83 char *                 p11_kit_module_get_filename          (CK_FUNCTION_LIST *module);
84 char *                 p11_kit_module_get_name              (CK_FUNCTION_LIST *module);
85 
86 int                    p11_kit_module_get_flags             (CK_FUNCTION_LIST *module);
87 
88 CK_FUNCTION_LIST *     p11_kit_module_load                  (const char *module_path,
89                                                              int flags);
90 
91 CK_RV                  p11_kit_module_initialize            (CK_FUNCTION_LIST *module);
92 
93 CK_RV                  p11_kit_module_finalize              (CK_FUNCTION_LIST *module);
94 
95 void                   p11_kit_module_release               (CK_FUNCTION_LIST *module);
96 
97 char *                 p11_kit_config_option                (CK_FUNCTION_LIST *module,
98                                                              const char *option);
99 
100 const char*            p11_kit_strerror                     (CK_RV rv);
101 
102 size_t                 p11_kit_space_strlen                 (const unsigned char *string,
103                                                              size_t max_length);
104 
105 char*                  p11_kit_space_strdup                 (const unsigned char *string,
106                                                              size_t max_length);
107 
108 void                   p11_kit_be_quiet                     (void);
109 
110 void                   p11_kit_be_loud                      (void);
111 
112 #ifdef P11_KIT_FUTURE_UNSTABLE_API
113 
114 void                   p11_kit_set_progname                 (const char *progname);
115 
116 void                   p11_kit_override_system_files        (const char *system_conf,
117                                                              const char *user_conf,
118                                                              const char *package_modules,
119                                                              const char *system_modules,
120 						             const char *user_modules);
121 #endif
122 
123 const char *           p11_kit_message                      (void);
124 
125 #ifdef __cplusplus
126 } /* extern "C" */
127 #endif
128 
129 #endif /* __P11_KIT_H__ */
130