aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-12-14 11:12:32 +0000
committerlloyd <[email protected]>2006-12-14 11:12:32 +0000
commit2b32d88fabd0cf45cb42981dd03258b39d1828c4 (patch)
treedb8549290d367b6eef4ff62ff4bc62357135afe4
parent780243495bda65e52f8f1797a3db0a25e420998b (diff)
Move the UI pulse functions into the global library state. That is (as best
as I can tell) the last of the global data, with the exception of the single global_lib_state pointer in libstate.cpp
-rw-r--r--include/enums.h15
-rw-r--r--include/libstate.h12
-rw-r--r--include/ui.h30
-rw-r--r--src/filter.cpp4
-rw-r--r--src/libstate.cpp20
-rw-r--r--src/make_prm.cpp22
-rw-r--r--src/numthry.cpp6
-rw-r--r--src/ui.cpp29
8 files changed, 64 insertions, 74 deletions
diff --git a/include/enums.h b/include/enums.h
index bc939aba1..c5ffeff24 100644
--- a/include/enums.h
+++ b/include/enums.h
@@ -99,6 +99,21 @@ enum Character_Set {
LATIN1_CHARSET
};
+/*************************************************
+* Pulse Function *
+*************************************************/
+enum Pulse_Type {
+ GENERAL_PULSE,
+
+ PIPE_WRITE,
+
+ PRIME_SEARCHING,
+ PRIME_SIEVING,
+ PRIME_PASSED_SIEVE,
+ PRIME_TESTING,
+ PRIME_FOUND
+};
+
static const u32bit NO_CERT_PATH_LIMIT = 0xFFFFFFF0;
}
diff --git a/include/libstate.h b/include/libstate.h
index c2e217df7..8cf700220 100644
--- a/include/libstate.h
+++ b/include/libstate.h
@@ -8,6 +8,7 @@
#include <botan/base.h>
#include <botan/enums.h>
+#include <botan/ui.h>
#include <string>
#include <vector>
#include <map>
@@ -31,6 +32,13 @@ class Library_State
};
friend class Engine_Iterator;
+ class UI
+ {
+ public:
+ virtual void pulse(Pulse_Type) {}
+ virtual ~UI() {}
+ };
+
Allocator* get_allocator(const std::string& = "") const;
void add_allocator(Allocator*);
void set_default_allocator(const std::string&) const;
@@ -59,6 +67,9 @@ class Library_State
void set_x509_state(class X509_GlobalState*);
class X509_GlobalState& x509_state();
+ void pulse(Pulse_Type) const;
+ void set_ui(UI*);
+
void set_transcoder(class Charset_Transcoder*);
std::string transcode(const std::string,
Character_Set, Character_Set) const;
@@ -80,6 +91,7 @@ class Library_State
std::map<std::string, Allocator*> alloc_factory;
mutable Allocator* cached_default_allocator;
+ UI* ui;
class Charset_Transcoder* transcoder;
RandomNumberGenerator* rng;
std::vector<Allocator*> allocators;
diff --git a/include/ui.h b/include/ui.h
index a956518d6..888d92c48 100644
--- a/include/ui.h
+++ b/include/ui.h
@@ -28,36 +28,6 @@ class User_Interface
mutable bool first_try;
};
-namespace UI {
-
-/*************************************************
-* Pulse Function *
-*************************************************/
-enum Pulse_Type {
- GENERAL_PULSE,
-
- PIPE_WRITE,
-
- PRIME_SEARCHING,
- PRIME_SIEVING,
- PRIME_PASSED_SIEVE,
- PRIME_TESTING,
- PRIME_FOUND
-};
-typedef void (*pulse_func)(Pulse_Type, void*);
-
-/*************************************************
-* Set the UI pulse function *
-*************************************************/
-void set_pulse(pulse_func, void* = 0);
-
-/*************************************************
-* Call the UI pulse function *
-*************************************************/
-void pulse(Pulse_Type = GENERAL_PULSE);
-
-}
-
}
#endif
diff --git a/src/filter.cpp b/src/filter.cpp
index 4ed9d0041..9c7fe3c28 100644
--- a/src/filter.cpp
+++ b/src/filter.cpp
@@ -5,7 +5,7 @@
#include <botan/filter.h>
#include <botan/secqueue.h>
-#include <botan/ui.h>
+#include <botan/libstate.h>
namespace Botan {
@@ -25,7 +25,7 @@ Filter::Filter()
*************************************************/
void Filter::send(const byte input[], u32bit length)
{
- UI::pulse(UI::PIPE_WRITE);
+ global_state().pulse(PIPE_WRITE);
bool nothing_attached = true;
for(u32bit j = 0; j != total_ports(); ++j)
diff --git a/src/libstate.cpp b/src/libstate.cpp
index c9db23be8..e8d47be24 100644
--- a/src/libstate.cpp
+++ b/src/libstate.cpp
@@ -292,6 +292,24 @@ X509_GlobalState& Library_State::x509_state()
}
/*************************************************
+* Set the UI object state *
+*************************************************/
+void Library_State::set_ui(UI* new_ui)
+ {
+ delete ui;
+ ui = new_ui;
+ }
+
+/*************************************************
+* Send a pulse to the UI object *
+*************************************************/
+void Library_State::pulse(Pulse_Type pulse_type) const
+ {
+ if(ui)
+ ui->pulse(pulse_type);
+ }
+
+/*************************************************
* Set the configuration object *
*************************************************/
Config& Library_State::config() const
@@ -348,6 +366,7 @@ Library_State::Library_State(Mutex_Factory* mutex_factory)
rng = 0;
cached_default_allocator = 0;
x509_state_obj = 0;
+ ui = 0;
}
/*************************************************
@@ -360,6 +379,7 @@ Library_State::~Library_State()
delete rng;
delete timer;
delete config_obj;
+ delete ui;
std::for_each(entropy_sources.begin(), entropy_sources.end(),
del_fun<EntropySource>());
diff --git a/src/make_prm.cpp b/src/make_prm.cpp
index c7461c411..7642ab435 100644
--- a/src/make_prm.cpp
+++ b/src/make_prm.cpp
@@ -4,11 +4,11 @@
*************************************************/
#include <botan/numthry.h>
+#include <botan/libstate.h>
#include <botan/lookup.h>
#include <botan/bit_ops.h>
#include <botan/parsing.h>
#include <botan/rng.h>
-#include <botan/ui.h>
#include <algorithm>
#include <memory>
@@ -55,7 +55,7 @@ bool generate_dsa_primes(BigInt& p, BigInt& q, const byte const_seed[],
q.binary_decode(qhash, qhash.size());
if(!is_prime(q))
return false;
- UI::pulse(UI::PRIME_FOUND);
+ global_state().pulse(PRIME_FOUND);
u32bit n = (pbits-1) / 160, b = (pbits-1) % 160;
SecureVector<byte> W(20 * (n+1));
@@ -67,7 +67,7 @@ bool generate_dsa_primes(BigInt& p, BigInt& q, const byte const_seed[],
for(u32bit j = 0; j != 4096 - counter_start; ++j)
{
- UI::pulse(UI::PRIME_SEARCHING);
+ global_state().pulse(PRIME_SEARCHING);
for(u32bit k = 0; k != n + 1; ++k)
{
@@ -82,7 +82,7 @@ bool generate_dsa_primes(BigInt& p, BigInt& q, const byte const_seed[],
if(p.bits() == pbits && is_prime(p))
{
- UI::pulse(UI::PRIME_FOUND);
+ global_state().pulse(PRIME_FOUND);
return true;
}
}
@@ -99,7 +99,7 @@ SecureVector<byte> generate_dsa_primes(BigInt& p, BigInt& q, u32bit pbits)
while(true)
{
Global_RNG::randomize(seed, seed.size());
- UI::pulse(UI::PRIME_SEARCHING);
+ global_state().pulse(PRIME_SEARCHING);
if(generate_dsa_primes(p, q, seed, seed.size(), pbits))
return seed;
}
@@ -124,7 +124,7 @@ BigInt random_prime(u32bit bits, const BigInt& coprime,
while(true)
{
- UI::pulse(UI::PRIME_SEARCHING);
+ global_state().pulse(PRIME_SEARCHING);
BigInt p = random_integer(bits);
p.set_bit(bits - 2);
@@ -139,7 +139,7 @@ BigInt random_prime(u32bit bits, const BigInt& coprime,
for(u32bit j = 0; j != sieve.size(); ++j)
{
sieve[j] = p % PRIMES[j];
- UI::pulse(UI::PRIME_SIEVING);
+ global_state().pulse(PRIME_SIEVING);
}
u32bit counter = 0;
@@ -148,7 +148,7 @@ BigInt random_prime(u32bit bits, const BigInt& coprime,
if(counter == 4096 || p.bits() > bits)
break;
- UI::pulse(UI::PRIME_SEARCHING);
+ global_state().pulse(PRIME_SEARCHING);
bool passes_sieve = true;
++counter;
@@ -157,17 +157,17 @@ BigInt random_prime(u32bit bits, const BigInt& coprime,
for(u32bit j = 0; j != sieve.size(); ++j)
{
sieve[j] = (sieve[j] + modulo) % PRIMES[j];
- UI::pulse(UI::PRIME_SIEVING);
+ global_state().pulse(PRIME_SIEVING);
if(sieve[j] == 0)
passes_sieve = false;
}
if(!passes_sieve || gcd(p - 1, coprime) != 1)
continue;
- UI::pulse(UI::PRIME_PASSED_SIEVE);
+ global_state().pulse(PRIME_PASSED_SIEVE);
if(passes_mr_tests(p))
{
- UI::pulse(UI::PRIME_FOUND);
+ global_state().pulse(PRIME_FOUND);
return p;
}
}
diff --git a/src/numthry.cpp b/src/numthry.cpp
index 382150906..8e21e6fa0 100644
--- a/src/numthry.cpp
+++ b/src/numthry.cpp
@@ -4,7 +4,7 @@
*************************************************/
#include <botan/numthry.h>
-#include <botan/ui.h>
+#include <botan/libstate.h>
#include <algorithm>
namespace Botan {
@@ -284,7 +284,7 @@ bool MillerRabin_Test::passes_test(const BigInt& a)
if(a < 2 || a >= n_minus_1)
throw Invalid_Argument("Bad size for nonce in Miller-Rabin test");
- UI::pulse(UI::PRIME_TESTING);
+ global_state().pulse(PRIME_TESTING);
BigInt y = pow_mod(a);
if(y == 1 || y == n_minus_1)
@@ -292,7 +292,7 @@ bool MillerRabin_Test::passes_test(const BigInt& a)
for(u32bit j = 1; j != s; ++j)
{
- UI::pulse(UI::PRIME_TESTING);
+ global_state().pulse(PRIME_TESTING);
y = reducer.square(y);
if(y == 1)
diff --git a/src/ui.cpp b/src/ui.cpp
index f8ce0c544..5bd51fb30 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -4,6 +4,7 @@
*************************************************/
#include <botan/ui.h>
+#include <botan/libstate.h>
namespace Botan {
@@ -31,32 +32,4 @@ User_Interface::User_Interface(const std::string& preset) :
first_try = true;
}
-namespace UI {
-
-/*************************************************
-* The current pulse function *
-*************************************************/
-pulse_func pulse_f = 0;
-void* pulse_f_data = 0;
-
-/*************************************************
-* Set the UI pulse function *
-*************************************************/
-void set_pulse(pulse_func p, void* p_data)
- {
- pulse_f = p;
- pulse_f_data = p_data;
- }
-
-/*************************************************
-* Call the UI pulse function *
-*************************************************/
-void pulse(Pulse_Type type)
- {
- if(pulse_f)
- pulse_f(type, pulse_f_data);
- }
-
-}
-
}