diff options
author | lloyd <[email protected]> | 2006-06-23 10:34:49 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-06-23 10:34:49 +0000 |
commit | 571fea5ac667b88a66604ecdba05d8324f5e9de7 (patch) | |
tree | fc7f8191e779ad3dc6fb2e4ac4e6c9f2acfed7c3 /modules | |
parent | 714fe898764407cdb9ebcea30cbc69bf1a4bada8 (diff) |
Inline a number of small objects that are only used in a local context
(ie, a single function). This will, unfortunately, break GCC 2.95.x
support. Most of the operating systems that had shipped with 2.95.x,
like OpenBSD and QNX, have since upgraded. Anyone needing 2.95.x support
will have to continue using 1.4.x
Diffstat (limited to 'modules')
-rw-r--r-- | modules/es_capi/es_capi.cpp | 84 | ||||
-rw-r--r-- | modules/mux_pthr/mux_pthr.cpp | 68 | ||||
-rw-r--r-- | modules/mux_qt/mux_qt.cpp | 26 | ||||
-rw-r--r-- | modules/mux_win32/mux_win32.cpp | 31 |
4 files changed, 86 insertions, 123 deletions
diff --git a/modules/es_capi/es_capi.cpp b/modules/es_capi/es_capi.cpp index 95bc3d969..fa067f606 100644 --- a/modules/es_capi/es_capi.cpp +++ b/modules/es_capi/es_capi.cpp @@ -11,62 +11,46 @@ namespace Botan { -namespace { - -/************************************************* -* CSP Handle * -*************************************************/ -class CSP_Handle - { - public: - CSP_Handle(u64bit); - ~CSP_Handle(); - - void gen_random(byte[], u32bit) const; - bool is_valid() const { return valid; } - - HCRYPTPROV get_handle() const { return handle; } - private: - HCRYPTPROV handle; - bool valid; - }; - /************************************************* -* Call CryptGenRandom * -*************************************************/ -void CSP_Handle::gen_random(byte out[], u32bit n) const - { - CryptGenRandom(handle, n, out); - } - -/************************************************* -* Initialize a CSP Handle * +* Gather Entropy from Win32 CAPI * *************************************************/ -CSP_Handle::CSP_Handle(u64bit capi_provider) +u32bit Win32_CAPI_EntropySource::slow_poll(byte output[], u32bit length) { - valid = false; - DWORD prov_type = (DWORD)capi_provider; - if(CryptAcquireContext(&handle, 0, 0, prov_type, CRYPT_VERIFYCONTEXT)) - valid = true; - } + class CSP_Handle + { + public: + CSP_Handle(u64bit capi_provider) + { + valid = false; + DWORD prov_type = (DWORD)capi_provider; + + if(CryptAcquireContext(&handle, 0, 0, + prov_type, CRYPT_VERIFYCONTEXT)) + valid = true; + } + + ~CSP_Handle() + { + if(is_valid()) + CryptReleaseContext(handle, 0); + } + + void gen_random(byte out[], u32bit n) const + { + if(is_valid()) + CryptGenRandom(handle, n, out); + } + + bool is_valid() const { return valid; } + + HCRYPTPROV get_handle() const { return handle; } + private: + HCRYPTPROV handle; + bool valid; + }; -/************************************************* -* Destroy a CSP Handle * -*************************************************/ -CSP_Handle::~CSP_Handle() - { - if(valid) - CryptReleaseContext(handle, 0); - } -} - -/************************************************* -* Gather Entropy from Win32 CAPI * -*************************************************/ -u32bit Win32_CAPI_EntropySource::slow_poll(byte output[], u32bit length) - { if(length > 64) length = 64; diff --git a/modules/mux_pthr/mux_pthr.cpp b/modules/mux_pthr/mux_pthr.cpp index ec2308fae..ade2005e9 100644 --- a/modules/mux_pthr/mux_pthr.cpp +++ b/modules/mux_pthr/mux_pthr.cpp @@ -14,48 +14,42 @@ namespace Botan { -namespace { - -/************************************************* -* Pthread Mutex * -*************************************************/ -class Pthread_Mutex : public Mutex - { - public: - void lock() - { - if(pthread_mutex_lock(&mutex) != 0) - throw Exception("Pthread_Mutex::lock: Error occured"); - } - - void unlock() - { - if(pthread_mutex_unlock(&mutex) != 0) - throw Exception("Pthread_Mutex::unlock: Error occured"); - } - - Pthread_Mutex() - { - if(pthread_mutex_init(&mutex, 0) != 0) - throw Exception("Pthread_Mutex: initialization failed"); - } - - ~Pthread_Mutex() - { - if(pthread_mutex_destroy(&mutex) != 0) - throw Invalid_State("~Pthread_Mutex: mutex is still locked"); - } - private: - pthread_mutex_t mutex; - }; - -} - /************************************************* * Pthread Mutex Factory * *************************************************/ Mutex* Pthread_Mutex_Factory::make() { + + class Pthread_Mutex : public Mutex + { + public: + void lock() + { + if(pthread_mutex_lock(&mutex) != 0) + throw Exception("Pthread_Mutex::lock: Error occured"); + } + + void unlock() + { + if(pthread_mutex_unlock(&mutex) != 0) + throw Exception("Pthread_Mutex::unlock: Error occured"); + } + + Pthread_Mutex() + { + if(pthread_mutex_init(&mutex, 0) != 0) + throw Exception("Pthread_Mutex: initialization failed"); + } + + ~Pthread_Mutex() + { + if(pthread_mutex_destroy(&mutex) != 0) + throw Invalid_State("~Pthread_Mutex: mutex is still locked"); + } + private: + pthread_mutex_t mutex; + }; + return new Pthread_Mutex(); } diff --git a/modules/mux_qt/mux_qt.cpp b/modules/mux_qt/mux_qt.cpp index e5c6d96ff..c0f3c93c9 100644 --- a/modules/mux_qt/mux_qt.cpp +++ b/modules/mux_qt/mux_qt.cpp @@ -12,29 +12,21 @@ namespace Botan { -namespace { - -/************************************************* -* Qt Mutex * -*************************************************/ -class Qt_Mutex : public Mutex - { - public: - void lock() { mutex.lock(); } - void unlock() { mutex.unlock(); } - private: - QMutex mutex; - }; - -} - /************************************************* * Qt Mutex Factory * *************************************************/ Mutex* Qt_Mutex_Factory::make() { + class Qt_Mutex : public Mutex + { + public: + void lock() { mutex.lock(); } + void unlock() { mutex.unlock(); } + private: + QMutex mutex; + }; + return new Qt_Mutex(); } } - diff --git a/modules/mux_win32/mux_win32.cpp b/modules/mux_win32/mux_win32.cpp index 400aea183..5ed448441 100644 --- a/modules/mux_win32/mux_win32.cpp +++ b/modules/mux_win32/mux_win32.cpp @@ -9,30 +9,23 @@ namespace Botan { -namespace { - -/************************************************* -* Win32 Mutex * -*************************************************/ -class Win32_Mutex : public Mutex - { - public: - void lock() { EnterCriticalSection(&mutex); } - void unlock() { LeaveCriticalSection(&mutex); } - - Win32_Mutex() { InitializeCriticalSection(&mutex); } - ~Win32_Mutex() { DeleteCriticalSection(&mutex); } - private: - CRITICAL_SECTION mutex; - }; - -} - /************************************************* * Win32 Mutex Factory * *************************************************/ Mutex* Win32_Mutex_Factory::make() { + class Win32_Mutex : public Mutex + { + public: + void lock() { EnterCriticalSection(&mutex); } + void unlock() { LeaveCriticalSection(&mutex); } + + Win32_Mutex() { InitializeCriticalSection(&mutex); } + ~Win32_Mutex() { DeleteCriticalSection(&mutex); } + private: + CRITICAL_SECTION mutex; + }; + return new Win32_Mutex(); } |