aboutsummaryrefslogtreecommitdiffstats
path: root/include/libstate.h
blob: 0b2a2959f67142a10feda601b9c20a9e2f398520 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*************************************************
* Library Internal/Global State Header File      *
* (C) 1999-2007 The Botan Project                *
*************************************************/

#ifndef BOTAN_LIB_STATE_H__
#define BOTAN_LIB_STATE_H__

#include <botan/base.h>
#include <botan/enums.h>
#include <botan/init.h>
#include <botan/ui.h>
#include <string>
#include <vector>
#include <map>

namespace Botan {

/*************************************************
* Global State Container Base                    *
*************************************************/
class Library_State
   {
   public:
      Library_State();
      ~Library_State();

      void initialize(const InitializerOptions&, Modules&);

      void load(Modules&);

      void add_engine(class Engine*);

      class Engine_Iterator
         {
         public:
            class Engine* next();
            Engine_Iterator(const Library_State& l) : lib(l) { n = 0; }
         private:
            const Library_State& lib;
            u32bit n;
         };
      friend class Engine_Iterator;

      Allocator* get_allocator(const std::string& = "") const;
      void add_allocator(Allocator*);
      void set_default_allocator(const std::string&) const;

      bool rng_is_seeded() const { return rng->is_seeded(); }
      void randomize(byte[], u32bit);

      void set_prng(RandomNumberGenerator*);
      void add_entropy_source(EntropySource*, bool = true);
      void add_entropy(const byte[], u32bit);
      void add_entropy(EntropySource&, bool);
      u32bit seed_prng(bool, u32bit);

      class Config& config() const;

      class Mutex* get_mutex() const;
   private:
      Library_State(const Library_State&) {}
      Library_State& operator=(const Library_State&) { return (*this); }

      class Engine* get_engine_n(u32bit) const;

      class Mutex_Factory* mutex_factory;
      class Mutex* allocator_lock;
      class Mutex* engine_lock;
      class Mutex* rng_lock;

      mutable class Config* config_obj;

      std::map<std::string, Allocator*> alloc_factory;
      mutable Allocator* cached_default_allocator;

      RandomNumberGenerator* rng;
      std::vector<Allocator*> allocators;
      std::vector<EntropySource*> entropy_sources;
      std::vector<class Engine*> engines;
   };

/*************************************************
* Global State                                   *
*************************************************/
Library_State& global_state();
void set_global_state(Library_State*);
Library_State* swap_global_state(Library_State*);

}

#endif