monotone

monotone Mtn Source Tree

Root/botan/modules.cpp

1/*************************************************
2* Module Factory Source File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#include <botan/modules.h>
7#include <botan/defalloc.h>
8#include <botan/def_char.h>
9#include <botan/eng_def.h>
10#include <botan/timers.h>
11
12#if defined(BOTAN_EXT_MUTEX_PTHREAD)
13 #include <botan/mux_pthr.h>
14#elif defined(BOTAN_EXT_MUTEX_WIN32)
15 #include <botan/mux_win32.h>
16#elif defined(BOTAN_EXT_MUTEX_QT)
17 #include <botan/mux_qt.h>
18#endif
19
20#if defined(BOTAN_EXT_ALLOC_MMAP)
21 #include <botan/mmap_mem.h>
22#endif
23
24#if defined(BOTAN_EXT_TIMER_HARDWARE)
25 #include <botan/tm_hard.h>
26#elif defined(BOTAN_EXT_TIMER_POSIX)
27 #include <botan/tm_posix.h>
28#elif defined(BOTAN_EXT_TIMER_UNIX)
29 #include <botan/tm_unix.h>
30#elif defined(BOTAN_EXT_TIMER_WIN32)
31 #include <botan/tm_win32.h>
32#endif
33
34#if defined(BOTAN_EXT_ENGINE_AEP)
35 #include <botan/eng_aep.h>
36#endif
37
38#if defined(BOTAN_EXT_ENGINE_GNU_MP)
39 #include <botan/eng_gmp.h>
40#endif
41
42#if defined(BOTAN_EXT_ENGINE_OPENSSL)
43 #include <botan/eng_ossl.h>
44#endif
45
46#if defined(BOTAN_EXT_ENTROPY_SRC_AEP)
47 #include <botan/es_aep.h>
48#endif
49
50#if defined(BOTAN_EXT_ENTROPY_SRC_DEVICE)
51 #include <botan/es_dev.h>
52#endif
53
54#if defined(BOTAN_EXT_ENTROPY_SRC_EGD)
55 #include <botan/es_egd.h>
56#endif
57
58#if defined(BOTAN_EXT_ENTROPY_SRC_UNIX)
59 #include <botan/es_unix.h>
60#endif
61
62#if defined(BOTAN_EXT_ENTROPY_SRC_BEOS)
63 #include <botan/es_beos.h>
64#endif
65
66#if defined(BOTAN_EXT_ENTROPY_SRC_CAPI)
67 #include <botan/es_capi.h>
68#endif
69
70#if defined(BOTAN_EXT_ENTROPY_SRC_WIN32)
71 #include <botan/es_win32.h>
72#endif
73
74#if defined(BOTAN_EXT_ENTROPY_SRC_FTW)
75 #include <botan/es_ftw.h>
76#endif
77
78namespace Botan {
79
80/*************************************************
81* Return a mutex factory, if available *
82*************************************************/
83Mutex_Factory* Builtin_Modules::mutex_factory() const
84 {
85#if defined(BOTAN_EXT_MUTEX_PTHREAD)
86 return new Pthread_Mutex_Factory;
87#elif defined(BOTAN_EXT_MUTEX_WIN32)
88 return new Win32_Mutex_Factory;
89#elif defined(BOTAN_EXT_MUTEX_QT)
90 return new Qt_Mutex_Factory;
91#else
92 return 0;
93#endif
94 }
95
96/*************************************************
97* Find a high resolution timer, if possible *
98*************************************************/
99Timer* Builtin_Modules::timer() const
100 {
101#if defined(BOTAN_EXT_TIMER_HARDWARE)
102 return new Hardware_Timer;
103#elif defined(BOTAN_EXT_TIMER_POSIX)
104 return new POSIX_Timer;
105#elif defined(BOTAN_EXT_TIMER_UNIX)
106 return new Unix_Timer;
107#elif defined(BOTAN_EXT_TIMER_WIN32)
108 return new Win32_Timer;
109#else
110 return new Timer;
111#endif
112 }
113
114/*************************************************
115* Find any usable allocators *
116*************************************************/
117std::vector<Allocator*> Builtin_Modules::allocators() const
118 {
119 std::vector<Allocator*> allocators;
120
121#if defined(BOTAN_EXT_ALLOC_MMAP)
122 allocators.push_back(new MemoryMapping_Allocator);
123#endif
124
125 allocators.push_back(new Locking_Allocator);
126 allocators.push_back(new Malloc_Allocator);
127
128 return allocators;
129 }
130
131/*************************************************
132* Return the default allocator *
133*************************************************/
134std::string Builtin_Modules::default_allocator() const
135 {
136 if(should_lock)
137 {
138#if defined(BOTAN_EXT_ALLOC_MMAP)
139 return "mmap";
140#else
141 return "locking";
142#endif
143 }
144 else
145 return "malloc";
146 }
147
148/*************************************************
149* Register any usable entropy sources *
150*************************************************/
151std::vector<EntropySource*> Builtin_Modules::entropy_sources() const
152 {
153 std::vector<EntropySource*> sources;
154
155#if defined(BOTAN_EXT_ENTROPY_SRC_AEP)
156 sources.push_back(new AEP_EntropySource);
157#endif
158
159#if defined(BOTAN_EXT_ENTROPY_SRC_EGD)
160 sources.push_back(new EGD_EntropySource);
161#endif
162
163#if defined(BOTAN_EXT_ENTROPY_SRC_DEVICE)
164 sources.push_back(new Device_EntropySource);
165#endif
166
167#if defined(BOTAN_EXT_ENTROPY_SRC_CAPI)
168 sources.push_back(new Win32_CAPI_EntropySource);
169#endif
170
171#if defined(BOTAN_EXT_ENTROPY_SRC_WIN32)
172 sources.push_back(new Win32_EntropySource);
173#endif
174
175#if defined(BOTAN_EXT_ENTROPY_SRC_UNIX)
176 sources.push_back(new Unix_EntropySource);
177#endif
178
179#if defined(BOTAN_EXT_ENTROPY_SRC_BEOS)
180 sources.push_back(new BeOS_EntropySource);
181#endif
182
183#if defined(BOTAN_EXT_ENTROPY_SRC_FTW)
184 sources.push_back(new FTW_EntropySource);
185#endif
186
187 return sources;
188 }
189
190/*************************************************
191* Find any usable engines *
192*************************************************/
193std::vector<Engine*> Builtin_Modules::engines() const
194 {
195 std::vector<Engine*> engines;
196
197 if(use_engines)
198 {
199#if defined(BOTAN_EXT_ENGINE_AEP)
200 engines.push_back(new AEP_Engine);
201#endif
202
203#if defined(BOTAN_EXT_ENGINE_GNU_MP)
204 engines.push_back(new GMP_Engine);
205#endif
206
207#if defined(BOTAN_EXT_ENGINE_OPENSSL)
208 engines.push_back(new OpenSSL_Engine);
209#endif
210 }
211
212 engines.push_back(new Default_Engine);
213
214 return engines;
215 }
216
217/*************************************************
218* Find the best transcoder option *
219*************************************************/
220Charset_Transcoder* Builtin_Modules::transcoder() const
221 {
222 return new Default_Charset_Transcoder;
223 }
224
225/*************************************************
226* Builtin_Modules Constructor *
227*************************************************/
228Builtin_Modules::Builtin_Modules(const InitializerOptions& args) :
229 should_lock(args.secure_memory()),
230 use_engines(args.use_engines())
231 {
232 }
233
234}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status