Botan 1.10.17

libstate.h
Go to the documentation of this file.
1 /*
2 * Library Internal/Global State
3 * (C) 1999-2008 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_LIB_STATE_H__
9 #define BOTAN_LIB_STATE_H__
10
11 #include <botan/global_state.h>
12 #include <botan/allocate.h>
13 #include <botan/algo_factory.h>
14 #include <botan/rng.h>
15
16 #include <string>
17 #include <vector>
18 #include <map>
19
20 namespace Botan {
21
22 class Mutex;
23
24 /**
25 * Global state container aka the buritto at the center of it all
26 */
27 class BOTAN_DLL Library_State
28 {
29 public:
30 Library_State();
31 ~Library_State();
32
33 /**
34 * @param thread_safe should a mutex be used for serialization
35 */
36 void initialize(bool thread_safe);
37
38 /**
39 * @return global Algorithm_Factory
40 */
41 Algorithm_Factory& algorithm_factory() const;
42
43 /**
44 * @return global RandomNumberGenerator
45 */
46 RandomNumberGenerator& global_rng();
47
48 /**
49 * @param name the name of the allocator
50 * @return allocator matching this name, or NULL
51 */
52 Allocator* get_allocator(const std::string& name = "") const;
53
54 /**
55 * Add a new allocator to the list of available ones
56 * @param alloc the allocator to add
57 */
58 void add_allocator(Allocator* alloc);
59
60 /**
61 * Set the default allocator
62 * @param name the name of the allocator to use as the default
63 */
64 void set_default_allocator(const std::string& name);
65
66 /**
67 * Get a parameter value as std::string.
68 * @param section the section of the desired key
69 * @param key the desired keys name
70 * @result the value of the parameter
71 */
72 std::string get(const std::string& section,
73 const std::string& key) const;
74
75 /**
76 * Check whether a certain parameter is set or not.
77 * @param section the section of the desired key
78 * @param key the desired keys name
79 * @result true if the parameters value is set,
80 * false otherwise
81 */
82 bool is_set(const std::string& section,
83 const std::string& key) const;
84
85 /**
86 * Set a configuration parameter.
87 * @param section the section of the desired key
88 * @param key the desired keys name
89 * @param value the new value
90 * @param overwrite if set to true, the parameters value
91 * will be overwritten even if it is already set, otherwise
92 * no existing values will be overwritten.
93 */
94 void set(const std::string& section,
95 const std::string& key,
96 const std::string& value,
97 bool overwrite = true);
98
99 /**
100 * Add a parameter value to the "alias" section.
101 * @param key the name of the parameter which shall have a new alias
102 * @param value the new alias
103 */
104 void add_alias(const std::string& key,
105 const std::string& value);
106
107 /**
108 * Resolve an alias.
109 * @param alias the alias to resolve.
110 * @return what the alias stands for
111 */
112 std::string deref_alias(const std::string& alias) const;
113
114 /**
115 * @return newly created Mutex (free with delete)
116 */
117 Mutex* get_mutex() const;
118 private:
119 static RandomNumberGenerator* make_global_rng(Algorithm_Factory& af,
120 Mutex* mutex);
121
122 void load_default_config();
123
124 Library_State(const Library_State&) {}
125 Library_State& operator=(const Library_State&) { return (*this); }
126
127 class Mutex_Factory* mutex_factory;
128
129 Mutex* global_rng_lock;
130 RandomNumberGenerator* global_rng_ptr;
131
132 Mutex* config_lock;
133 std::map<std::string, std::string> config;
134
135 Mutex* allocator_lock;
136 std::string default_allocator_name;
137 std::map<std::string, Allocator*> alloc_factory;
138 mutable Allocator* cached_default_allocator;
139 std::vector<Allocator*> allocators;
140
141 Algorithm_Factory* m_algorithm_factory;
142 };
143
144 }
145
146 #endif
Botan::Algorithm_Factory
Definition: algo_factory.h:34
Botan::Library_State
Definition: libstate.h:27
Botan::Mutex_Factory
Definition: mutex.h:36
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::Allocator
Definition: allocate.h:19
Botan
Definition: algo_base.h:14
Botan::Mutex
Definition: mutex.h:18
alloc
Allocator * alloc
Definition: bzip2.cpp:29