2 // Copyright (c) 2017 James E. King III
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // https://www.boost.org/LICENSE_1_0.txt)
8 // The contents of this file are compiled into a loadable
9 // library that is used for mocking purposes so that the error
10 // paths in the random_provider implementations are exercised.
13 #include <boost/config.hpp>
14 #include <boost/core/ignore_unused.hpp>
16 #if defined(BOOST_WINDOWS)
18 #include <boost/winapi/basic_types.hpp>
20 // WinAPI is not currently set up well for building mocks, as
21 // the definitions of wincrypt APIs all use BOOST_SYMBOL_IMPORT
22 // therefore we cannot include it, but we need some of the types
23 // so they are defined here...
26 typedef ULONG_PTR_ HCRYPTPROV_
;
30 // wincrypt has to be mocked through a DLL pretending to be
31 // the real thing as the official APIs use __declspec(dllimport)
34 std::deque
<boost::winapi::BOOL_
> wincrypt_next_result
;
36 BOOST_SYMBOL_EXPORT
bool expectations_capable()
41 BOOST_SYMBOL_EXPORT
bool expectations_met()
43 return wincrypt_next_result
.empty();
46 BOOST_SYMBOL_EXPORT
void expect_next_call_success(bool success
)
48 wincrypt_next_result
.push_back(success
? 1 : 0);
51 BOOST_SYMBOL_EXPORT
bool provider_acquires_context()
59 boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
61 boost::winapi::HCRYPTPROV_
*phProv
,
62 boost::winapi::LPCWSTR_ szContainer
,
63 boost::winapi::LPCWSTR_ szProvider
,
64 boost::winapi::DWORD_ dwProvType
,
65 boost::winapi::DWORD_ dwFlags
)
67 boost::ignore_unused(phProv
);
68 boost::ignore_unused(szContainer
);
69 boost::ignore_unused(szProvider
);
70 boost::ignore_unused(dwProvType
);
71 boost::ignore_unused(dwFlags
);
73 boost::winapi::BOOL_ result
= wincrypt_next_result
.front();
74 wincrypt_next_result
.pop_front();
79 boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
81 boost::winapi::HCRYPTPROV_ hProv
,
82 boost::winapi::DWORD_ dwLen
,
83 boost::winapi::BYTE_
*pbBuffer
)
85 boost::ignore_unused(hProv
);
86 boost::ignore_unused(dwLen
);
87 boost::ignore_unused(pbBuffer
);
89 boost::winapi::BOOL_ result
= wincrypt_next_result
.front();
90 wincrypt_next_result
.pop_front();
94 // the implementation ignores the result of close because it
95 // happens in a destructor
97 boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
99 boost::winapi::HCRYPTPROV_ hProv
,
100 #if defined(_MSC_VER) && (_MSC_VER+0) >= 1500 && (_MSC_VER+0) < 1900 && BOOST_USE_NTDDI_VERSION < BOOST_WINAPI_NTDDI_WINXP
101 // see winapi crypt.hpp for more details on why these differ...
102 boost::winapi::ULONG_PTR_ dwFlags
104 boost::winapi::DWORD_ dwFlags
108 boost::ignore_unused(hProv
);
109 boost::ignore_unused(dwFlags
);