diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-04-16 19:21:57 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-04-16 19:35:27 +0200 |
commit | 75fe4f60c3f59af30cb1d8f2b5902d866c05550a (patch) | |
tree | 81106c6129626417cb9f71ab31393b31f9c27078 /libqpdf/SecureRandomDataProvider.cc | |
parent | 38edca820eac0a79fd860895b46dd03005e3c96b (diff) | |
download | qpdf-75fe4f60c3f59af30cb1d8f2b5902d866c05550a.tar.zst |
Use anonymous namespaces for file-private classes
Diffstat (limited to 'libqpdf/SecureRandomDataProvider.cc')
-rw-r--r-- | libqpdf/SecureRandomDataProvider.cc | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/libqpdf/SecureRandomDataProvider.cc b/libqpdf/SecureRandomDataProvider.cc index f8a342bd..c96d31f7 100644 --- a/libqpdf/SecureRandomDataProvider.cc +++ b/libqpdf/SecureRandomDataProvider.cc @@ -31,47 +31,54 @@ SecureRandomDataProvider::getInstance() # ifdef _WIN32 -class WindowsCryptProvider +namespace { - public: - WindowsCryptProvider() + class WindowsCryptProvider { - if (!CryptAcquireContextW( - &crypt_prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { - throw std::runtime_error( - "unable to acquire crypt context: " + getErrorMessage()); + public: + WindowsCryptProvider() + { + if (!CryptAcquireContextW( + &crypt_prov, + NULL, + NULL, + PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT)) { + throw std::runtime_error( + "unable to acquire crypt context: " + getErrorMessage()); + } + } + ~WindowsCryptProvider() + { + // Ignore error + CryptReleaseContext(crypt_prov, 0); } - } - ~WindowsCryptProvider() - { - // Ignore error - CryptReleaseContext(crypt_prov, 0); - } - - HCRYPTPROV crypt_prov; - private: - std::string - getErrorMessage() - { - DWORD errorMessageID = ::GetLastError(); - LPSTR messageBuffer = nullptr; - size_t size = FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - errorMessageID, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - reinterpret_cast<LPSTR>(&messageBuffer), - 0, - NULL); - std::string message(messageBuffer, size); - LocalFree(messageBuffer); - return ( - "error number " + QUtil::int_to_string_base(errorMessageID, 16) + - ": " + message); - } -}; + HCRYPTPROV crypt_prov; + + private: + std::string + getErrorMessage() + { + DWORD errorMessageID = ::GetLastError(); + LPSTR messageBuffer = nullptr; + size_t size = FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + errorMessageID, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + reinterpret_cast<LPSTR>(&messageBuffer), + 0, + NULL); + std::string message(messageBuffer, size); + LocalFree(messageBuffer); + return ( + "error number " + + QUtil::int_to_string_base(errorMessageID, 16) + ": " + message); + } + }; +} // namespace # endif void |