diff options
author | lloyd <[email protected]> | 2006-12-14 11:12:32 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-12-14 11:12:32 +0000 |
commit | 2b32d88fabd0cf45cb42981dd03258b39d1828c4 (patch) | |
tree | db8549290d367b6eef4ff62ff4bc62357135afe4 /src | |
parent | 780243495bda65e52f8f1797a3db0a25e420998b (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
Diffstat (limited to 'src')
-rw-r--r-- | src/filter.cpp | 4 | ||||
-rw-r--r-- | src/libstate.cpp | 20 | ||||
-rw-r--r-- | src/make_prm.cpp | 22 | ||||
-rw-r--r-- | src/numthry.cpp | 6 | ||||
-rw-r--r-- | src/ui.cpp | 29 |
5 files changed, 37 insertions, 44 deletions
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); - } - -} - } |