]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/uuid/test/mock_random.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / uuid / test / mock_random.cpp
CommitLineData
11fdf7f2
TL
1//
2// Copyright (c) 2017 James E. King III
3//
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
92f5a8d4 6// https://www.boost.org/LICENSE_1_0.txt)
11fdf7f2
TL
7//
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.
11//
12
13#include <boost/config.hpp>
14#include <boost/core/ignore_unused.hpp>
15
16#if defined(BOOST_WINDOWS)
17
18#include <boost/winapi/basic_types.hpp>
19
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...
24namespace boost {
25namespace winapi {
26 typedef ULONG_PTR_ HCRYPTPROV_;
27}
28}
29
30// wincrypt has to be mocked through a DLL pretending to be
31// the real thing as the official APIs use __declspec(dllimport)
32
33#include <deque>
34std::deque<boost::winapi::BOOL_> wincrypt_next_result;
35
36BOOST_SYMBOL_EXPORT bool expectations_capable()
37{
38 return true;
39}
40
41BOOST_SYMBOL_EXPORT bool expectations_met()
42{
43 return wincrypt_next_result.empty();
44}
45
46BOOST_SYMBOL_EXPORT void expect_next_call_success(bool success)
47{
48 wincrypt_next_result.push_back(success ? 1 : 0);
49}
50
51BOOST_SYMBOL_EXPORT bool provider_acquires_context()
52{
53 return true;
54}
55
56extern "C" {
57
58BOOST_SYMBOL_EXPORT
92f5a8d4 59boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
11fdf7f2
TL
60CryptAcquireContextW(
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)
66{
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);
72
73 boost::winapi::BOOL_ result = wincrypt_next_result.front();
74 wincrypt_next_result.pop_front();
75 return result;
76}
77
78BOOST_SYMBOL_EXPORT
92f5a8d4 79boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
11fdf7f2
TL
80CryptGenRandom(
81 boost::winapi::HCRYPTPROV_ hProv,
82 boost::winapi::DWORD_ dwLen,
83 boost::winapi::BYTE_ *pbBuffer)
84{
85 boost::ignore_unused(hProv);
86 boost::ignore_unused(dwLen);
87 boost::ignore_unused(pbBuffer);
88
89 boost::winapi::BOOL_ result = wincrypt_next_result.front();
90 wincrypt_next_result.pop_front();
91 return result;
92}
93
94// the implementation ignores the result of close because it
95// happens in a destructor
96BOOST_SYMBOL_EXPORT
92f5a8d4 97boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
11fdf7f2
TL
98CryptReleaseContext(
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
103#else
104 boost::winapi::DWORD_ dwFlags
105#endif
106)
107{
108 boost::ignore_unused(hProv);
109 boost::ignore_unused(dwFlags);
110 return true;
111}
112
113} // end extern "C"
114
115#endif