BVB Source Codes

mars Show crypt.hpp Source code

Return Download mars: download crypt.hpp Source code - Download mars Source code - Type:.hpp
  1. //  crypt.hpp  --------------------------------------------------------------//
  2.  
  3. //  Copyright 2014 Antony Polukhin
  4. //  Copyright 2015 Andrey Semashev
  5.  
  6. //  Distributed under the Boost Software License, Version 1.0.
  7. //  See http://www.boost.org/LICENSE_1_0.txt
  8.  
  9.  
  10. #ifndef BOOST_DETAIL_WINAPI_CRYPT_HPP
  11. #define BOOST_DETAIL_WINAPI_CRYPT_HPP
  12.  
  13. #include <boost/detail/winapi/basic_types.hpp>
  14. #include <boost/detail/winapi/detail/cast_ptr.hpp>
  15. #if defined( BOOST_USE_WINDOWS_H ) && defined( BOOST_WINAPI_IS_MINGW )
  16. // MinGW does not include this header as part of windows.h
  17. #include <wincrypt.h>
  18. #endif
  19.  
  20. #ifdef BOOST_HAS_PRAGMA_ONCE
  21. #pragma once
  22. #endif
  23.  
  24. #if !defined( BOOST_USE_WINDOWS_H )
  25. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace detail { namespace winapi {
  26. typedef ULONG_PTR_ HCRYPTPROV_;
  27. }}}
  28.  
  29. // Some versions of MinGW (including the latest ones) contain buggy declarations of CryptEnumProvidersA and CryptEnumProvidersW.
  30. // We cannot detect those broken versions, and we can't include the system header because it's incomplete.
  31. // So below we duplicate the broken declarations here and work around the problem with cast_ptr. These declarations
  32. // will have to be removed when MinGW is fixed.
  33.  
  34. extern "C" {
  35. #if !defined( BOOST_NO_ANSI_APIS )
  36. #if !defined( BOOST_WINAPI_IS_MINGW ) || !defined( UNICODE )
  37. BOOST_SYMBOL_IMPORT mars_boost::detail::winapi::BOOL_ WINAPI
  38. CryptEnumProvidersA(
  39.     mars_boost::detail::winapi::DWORD_ dwIndex,
  40.     mars_boost::detail::winapi::DWORD_ *pdwReserved,
  41.     mars_boost::detail::winapi::DWORD_ dwFlags,
  42.     mars_boost::detail::winapi::DWORD_ *pdwProvType,
  43.     mars_boost::detail::winapi::LPSTR_ szProvName,
  44.     mars_boost::detail::winapi::DWORD_ *pcbProvName);
  45. #else
  46. // Broken declaration in MinGW
  47. BOOST_SYMBOL_IMPORT mars_boost::detail::winapi::BOOL_ WINAPI
  48. CryptEnumProvidersA(
  49.     mars_boost::detail::winapi::DWORD_ dwIndex,
  50.     mars_boost::detail::winapi::DWORD_ *pdwReserved,
  51.     mars_boost::detail::winapi::DWORD_ dwFlags,
  52.     mars_boost::detail::winapi::DWORD_ *pdwProvType,
  53.     mars_boost::detail::winapi::LPWSTR_ szProvName,
  54.     mars_boost::detail::winapi::DWORD_ *pcbProvName);
  55. #endif
  56.  
  57. BOOST_SYMBOL_IMPORT mars_boost::detail::winapi::BOOL_ WINAPI
  58. CryptAcquireContextA(
  59.     mars_boost::detail::winapi::HCRYPTPROV_ *phProv,
  60.     mars_boost::detail::winapi::LPCSTR_ pszContainer,
  61.     mars_boost::detail::winapi::LPCSTR_ pszProvider,
  62.     mars_boost::detail::winapi::DWORD_ dwProvType,
  63.     mars_boost::detail::winapi::DWORD_ dwFlags);
  64. #endif // !defined( BOOST_NO_ANSI_APIS )
  65.  
  66. #if !defined( BOOST_WINAPI_IS_MINGW ) || defined( UNICODE )
  67. BOOST_SYMBOL_IMPORT mars_boost::detail::winapi::BOOL_ WINAPI
  68. CryptEnumProvidersW(
  69.     mars_boost::detail::winapi::DWORD_ dwIndex,
  70.     mars_boost::detail::winapi::DWORD_ *pdwReserved,
  71.     mars_boost::detail::winapi::DWORD_ dwFlags,
  72.     mars_boost::detail::winapi::DWORD_ *pdwProvType,
  73.     mars_boost::detail::winapi::LPWSTR_ szProvName,
  74.     mars_boost::detail::winapi::DWORD_ *pcbProvName);
  75. #else
  76. // Broken declaration in MinGW
  77. BOOST_SYMBOL_IMPORT mars_boost::detail::winapi::BOOL_ WINAPI
  78. CryptEnumProvidersW(
  79.     mars_boost::detail::winapi::DWORD_ dwIndex,
  80.     mars_boost::detail::winapi::DWORD_ *pdwReserved,
  81.     mars_boost::detail::winapi::DWORD_ dwFlags,
  82.     mars_boost::detail::winapi::DWORD_ *pdwProvType,
  83.     mars_boost::detail::winapi::LPSTR_ szProvName,
  84.     mars_boost::detail::winapi::DWORD_ *pcbProvName);
  85. #endif
  86.  
  87. BOOST_SYMBOL_IMPORT mars_boost::detail::winapi::BOOL_ WINAPI
  88. CryptAcquireContextW(
  89.     mars_boost::detail::winapi::HCRYPTPROV_ *phProv,
  90.     mars_boost::detail::winapi::LPCWSTR_ szContainer,
  91.     mars_boost::detail::winapi::LPCWSTR_ szProvider,
  92.     mars_boost::detail::winapi::DWORD_ dwProvType,
  93.     mars_boost::detail::winapi::DWORD_ dwFlags);
  94.  
  95. BOOST_SYMBOL_IMPORT mars_boost::detail::winapi::BOOL_ WINAPI
  96. CryptGenRandom(
  97.     mars_boost::detail::winapi::HCRYPTPROV_ hProv,
  98.     mars_boost::detail::winapi::DWORD_ dwLen,
  99.     mars_boost::detail::winapi::BYTE_ *pbBuffer);
  100.  
  101. BOOST_SYMBOL_IMPORT mars_boost::detail::winapi::BOOL_ WINAPI
  102. CryptReleaseContext(
  103.     mars_boost::detail::winapi::HCRYPTPROV_ hProv,
  104.     mars_boost::detail::winapi::DWORD_ dwFlags);
  105. }
  106. #endif // !defined( BOOST_USE_WINDOWS_H )
  107.  
  108. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  109. namespace detail {
  110. namespace winapi {
  111.  
  112. #if defined( BOOST_USE_WINDOWS_H )
  113.  
  114. typedef ::HCRYPTPROV HCRYPTPROV_;
  115.  
  116. const DWORD_ PROV_RSA_FULL_         = PROV_RSA_FULL;
  117.  
  118. const DWORD_ CRYPT_VERIFYCONTEXT_   = CRYPT_VERIFYCONTEXT;
  119. const DWORD_ CRYPT_NEWKEYSET_       = CRYPT_NEWKEYSET;
  120. const DWORD_ CRYPT_DELETEKEYSET_    = CRYPT_DELETEKEYSET;
  121. const DWORD_ CRYPT_MACHINE_KEYSET_  = CRYPT_MACHINE_KEYSET;
  122. const DWORD_ CRYPT_SILENT_          = CRYPT_SILENT;
  123.  
  124. #else
  125.  
  126. const DWORD_ PROV_RSA_FULL_         = 1;
  127.  
  128. const DWORD_ CRYPT_VERIFYCONTEXT_   = 0xF0000000;
  129. const DWORD_ CRYPT_NEWKEYSET_       = 8;
  130. const DWORD_ CRYPT_DELETEKEYSET_    = 16;
  131. const DWORD_ CRYPT_MACHINE_KEYSET_  = 32;
  132. const DWORD_ CRYPT_SILENT_          = 64;
  133.  
  134. #endif
  135.  
  136. #if !defined( BOOST_NO_ANSI_APIS )
  137. using ::CryptEnumProvidersA;
  138. using ::CryptAcquireContextA;
  139. #endif
  140. using ::CryptEnumProvidersW;
  141. using ::CryptAcquireContextW;
  142. using ::CryptGenRandom;
  143. using ::CryptReleaseContext;
  144.  
  145. #if !defined( BOOST_NO_ANSI_APIS )
  146. BOOST_FORCEINLINE BOOL_ crypt_enum_providers(
  147.     DWORD_ dwIndex,
  148.     DWORD_ *pdwReserved,
  149.     DWORD_ dwFlags,
  150.     DWORD_ *pdwProvType,
  151.     LPSTR_ szProvName,
  152.     DWORD_ *pcbProvName)
  153. {
  154.     return ::CryptEnumProvidersA(dwIndex, pdwReserved, dwFlags, pdwProvType, winapi::detail::cast_ptr(szProvName), pcbProvName);
  155. }
  156.  
  157. BOOST_FORCEINLINE BOOL_ crypt_acquire_context(
  158.     HCRYPTPROV_ *phProv,
  159.     LPCSTR_ pszContainer,
  160.     LPCSTR_ pszProvider,
  161.     DWORD_ dwProvType,
  162.     DWORD_ dwFlags)
  163. {
  164.     return ::CryptAcquireContextA(phProv, pszContainer, pszProvider, dwProvType, dwFlags);
  165. }
  166. #endif
  167.  
  168. BOOST_FORCEINLINE BOOL_ crypt_enum_providers(
  169.     DWORD_ dwIndex,
  170.     DWORD_ *pdwReserved,
  171.     DWORD_ dwFlags,
  172.     DWORD_ *pdwProvType,
  173.     LPWSTR_ szProvName,
  174.     DWORD_ *pcbProvName)
  175. {
  176.     return ::CryptEnumProvidersW(dwIndex, pdwReserved, dwFlags, pdwProvType, winapi::detail::cast_ptr(szProvName), pcbProvName);
  177. }
  178.  
  179. BOOST_FORCEINLINE BOOL_ crypt_acquire_context(
  180.     HCRYPTPROV_ *phProv,
  181.     LPCWSTR_ szContainer,
  182.     LPCWSTR_ szProvider,
  183.     DWORD_ dwProvType,
  184.     DWORD_ dwFlags)
  185. {
  186.     return ::CryptAcquireContextW(phProv, szContainer, szProvider, dwProvType, dwFlags);
  187. }
  188.  
  189. }
  190. }
  191. }
  192.  
  193. #endif // BOOST_DETAIL_WINAPI_CRYPT_HPP
  194.  
downloadcrypt.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top