1 /*
2 Copyright (C) 1999-2007 The Botan Project. All rights reserved.
3 
4 Redistribution and use in source and binary forms, for any use, with or without
5 modification, is permitted provided that the following conditions are met:
6 
7 1. Redistributions of source code must retain the above copyright notice, this
8 list of conditions, and the following disclaimer.
9 
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions, and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED
15 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
17 
18 IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT,
19 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 // LICENSEHEADER_END
27 namespace QCA { // WRAPNS_LINE
28 /*************************************************
29  * Library Internal/Global State Header File      *
30  * (C) 1999-2007 The Botan Project                *
31  *************************************************/
32 
33 #ifndef BOTAN_LIB_STATE_H__
34 #define BOTAN_LIB_STATE_H__
35 
36 #ifdef BOTAN_TOOLS_ONLY
37 } // WRAPNS_LINE
38 #include <botan/allocate.h>
39 namespace QCA { // WRAPNS_LINE
40 #else
41 } // WRAPNS_LINE
42 #include <botan/base.h>
43 namespace QCA { // WRAPNS_LINE
44 } // WRAPNS_LINE
45 #include <botan/enums.h>
46 namespace QCA { // WRAPNS_LINE
47 } // WRAPNS_LINE
48 #include <botan/ui.h>
49 namespace QCA { // WRAPNS_LINE
50 #endif
51 } // WRAPNS_LINE
52 #include <string>
53 namespace QCA { // WRAPNS_LINE
54 } // WRAPNS_LINE
55 #include <vector>
56 namespace QCA { // WRAPNS_LINE
57 } // WRAPNS_LINE
58 #include <map>
59 namespace QCA { // WRAPNS_LINE
60 
61 namespace Botan {
62 
63 /*************************************************
64  * Global State Container Base                    *
65  *************************************************/
66 class Library_State
67 {
68 public:
69 #ifndef BOTAN_TOOLS_ONLY
70     class Engine_Iterator
71     {
72     public:
73         class Engine *next();
Engine_Iterator(const Library_State & l)74         Engine_Iterator(const Library_State &l)
75             : lib(l)
76         {
77             n = 0;
78         }
79 
80     private:
81         const Library_State &lib;
82         u32bit               n;
83     };
84     friend class Engine_Iterator;
85 
86     class UI
87     {
88     public:
pulse(Pulse_Type)89         virtual void pulse(Pulse_Type)
90         {
91         }
~UI()92         virtual ~UI()
93         {
94         }
95     };
96 #endif
97 
98     int        prealloc_size;
99     Allocator *get_allocator(const std::string & = "") const;
100     void       add_allocator(Allocator *);
101 #ifdef BOTAN_TOOLS_ONLY
102     void set_default_allocator(const std::string &);
103 #else
104     void set_default_allocator(const std::string &) const;
105 #endif
106 
107 #ifndef BOTAN_TOOLS_ONLY
rng_is_seeded()108     bool rng_is_seeded() const
109     {
110         return rng->is_seeded();
111     }
112     void randomize(byte[], u32bit);
113 
114     void   set_prng(RandomNumberGenerator *);
115     void   add_entropy_source(EntropySource *, bool = true);
116     void   add_entropy(const byte[], u32bit);
117     void   add_entropy(EntropySource &, bool);
118     u32bit seed_prng(bool, u32bit);
119 #endif
120 
121     void load(class Modules &);
122 
123 #ifndef BOTAN_TOOLS_ONLY
124     void   set_timer(class Timer *);
125     u64bit system_clock() const;
126 
127     class Config &config() const;
128 
129     void add_engine(class Engine *);
130 #endif
131 
132     class Mutex *get_mutex() const;
133     class Mutex *get_named_mutex(const std::string &);
134 
135 #ifndef BOTAN_TOOLS_ONLY
136     void                    set_x509_state(class X509_GlobalState *);
137     class X509_GlobalState &x509_state();
138 
139     void pulse(Pulse_Type) const;
140     void set_ui(UI *);
141 
142     void        set_transcoder(class Charset_Transcoder *);
143     std::string transcode(const std::string, Character_Set, Character_Set) const;
144 #endif
145 
146     Library_State(class Mutex_Factory *);
147     ~Library_State();
148 
149 private:
Library_State(const Library_State &)150     Library_State(const Library_State &)
151     {
152     }
153     Library_State &operator=(const Library_State &)
154     {
155         return (*this);
156     }
157 
158 #ifndef BOTAN_TOOLS_ONLY
159     class Engine *get_engine_n(u32bit) const;
160 #endif
161 
162     class Mutex_Factory *mutex_factory;
163 #ifndef BOTAN_TOOLS_ONLY
164     class Timer *           timer;
165     class Config *          config_obj;
166     class X509_GlobalState *x509_state_obj;
167 #endif
168 
169     std::map<std::string, class Mutex *> locks;
170     std::map<std::string, Allocator *>   alloc_factory;
171     mutable Allocator *                  cached_default_allocator;
172 #ifdef BOTAN_TOOLS_ONLY
173     std::string default_allocator_type;
174 #endif
175 
176 #ifndef BOTAN_TOOLS_ONLY
177     UI *                      ui;
178     class Charset_Transcoder *transcoder;
179     RandomNumberGenerator *   rng;
180 #endif
181     std::vector<Allocator *> allocators;
182 #ifndef BOTAN_TOOLS_ONLY
183     std::vector<EntropySource *> entropy_sources;
184     std::vector<class Engine *>  engines;
185 #endif
186 };
187 
188 /*************************************************
189  * Global State                                   *
190  *************************************************/
191 Library_State &global_state();
192 void           set_global_state(Library_State *);
193 Library_State *swap_global_state(Library_State *);
194 
195 }
196 
197 #endif
198 } // WRAPNS_LINE
199