monotone

monotone Mtn Source Tree

Root/botan/modules.cpp

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

Archive Download this file

Branches

Tags

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