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/es_capi | |
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/es_capi')
-rw-r--r-- | modules/es_capi/es_capi.cpp | 84 |
1 files changed, 34 insertions, 50 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; |