aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-05-14 10:39:44 -0400
committerJack Lloyd <[email protected]>2018-05-14 10:39:44 -0400
commit1773c9a43315bf27b44b89e28396abf8e0f05409 (patch)
treef7b1f84aaa9a28be11a4a5519cd8ac9f7fce5a25
parent8f3f7743472ba625a0bb249cd06651ed13325b87 (diff)
parent05abe208647f6ae112bed0a1a8cee794a55fcfa5 (diff)
Merge GH #1567 Fixes for C++17 mode compilation under MSVC
-rw-r--r--src/lib/utils/compiler.h11
-rw-r--r--src/lib/utils/filesystem.cpp10
-rw-r--r--src/tests/test_x509_path.cpp35
3 files changed, 37 insertions, 19 deletions
diff --git a/src/lib/utils/compiler.h b/src/lib/utils/compiler.h
index 68fc51e6d..202b5cb75 100644
--- a/src/lib/utils/compiler.h
+++ b/src/lib/utils/compiler.h
@@ -137,7 +137,7 @@
/*
* Define BOTAN_CURRENT_FUNCTION
*/
-#if defined(_MSC_VER)
+#if defined(BOTAN_BUILD_COMPILER_IS_MSVC_2013)
#define BOTAN_CURRENT_FUNCTION __FUNCTION__
#else
#define BOTAN_CURRENT_FUNCTION __func__
@@ -155,6 +155,15 @@
#endif
/*
+* Define BOTAN_CONSTEXPR (for MSVC 2013)
+*/
+#if defined(BOTAN_BUILD_COMPILER_IS_MSVC_2013)
+ #define BOTAN_CONSTEXPR /**/
+#else
+ #define BOTAN_CONSTEXPR constexpr
+#endif
+
+/*
* Define BOTAN_ALIGNAS (for MSVC 2013)
*/
#if defined(BOTAN_BUILD_COMPILER_IS_MSVC_2013)
diff --git a/src/lib/utils/filesystem.cpp b/src/lib/utils/filesystem.cpp
index 9ce23d0c6..fbfafdf5b 100644
--- a/src/lib/utils/filesystem.cpp
+++ b/src/lib/utils/filesystem.cpp
@@ -35,17 +35,21 @@ namespace {
#if defined(BOTAN_TARGET_OS_HAS_STL_FILESYSTEM_MSVC) && defined(BOTAN_BUILD_COMPILER_IS_MSVC)
std::vector<std::string> impl_stl_filesystem(const std::string& dir)
{
+#if (_MSVC_LANG >= 201703L)
+ using namespace std::filesystem;
+#else
using namespace std::tr2::sys;
+#endif
std::vector<std::string> out;
path p(dir);
- if (is_directory(p))
+ if(is_directory(p))
{
- for (recursive_directory_iterator itr(p), end; itr != end; ++itr)
+ for(recursive_directory_iterator itr(p), end; itr != end; ++itr)
{
- if (is_regular_file(itr->path()))
+ if(is_regular_file(itr->path()))
{
out.push_back(itr->path().string());
}
diff --git a/src/tests/test_x509_path.cpp b/src/tests/test_x509_path.cpp
index 43ecb81e0..22d6f1407 100644
--- a/src/tests/test_x509_path.cpp
+++ b/src/tests/test_x509_path.cpp
@@ -14,16 +14,16 @@
#include <botan/data_src.h>
#include <botan/x509_crl.h>
#include <botan/pkcs10.h>
+ #include <botan/exceptn.h>
+
+ #include <fstream>
+ #include <string>
+ #include <vector>
+ #include <map>
+ #include <algorithm>
+ #include <limits>
#endif
-#include <botan/exceptn.h>
-
-#include <fstream>
-#include <string>
-#include <vector>
-#include <map>
-#include <algorithm>
-
namespace Botan_Tests {
namespace {
@@ -578,16 +578,21 @@ std::vector<Test::Result> BSI_Path_Validation_Tests::run()
* the validation function may be relevant, i.e. if issuer DNs are
* ambiguous.
*/
- auto uniform_shuffle = [](size_t m) -> size_t
- {
- size_t s;
- Test::rng().randomize(reinterpret_cast<uint8_t*>(&s), sizeof(s));
- return s % m;
- };
+ struct random_bit_generator {
+ using result_type = size_t;
+ static BOTAN_CONSTEXPR result_type min() { return 0; }
+ static BOTAN_CONSTEXPR result_type max() { return std::numeric_limits<size_t>::max(); }
+ result_type operator()()
+ {
+ size_t s;
+ Test::rng().randomize(reinterpret_cast<uint8_t*>(&s), sizeof(s));
+ return s;
+ }
+ } rbg;
for(size_t r = 0; r < 16; r++)
{
- std::random_shuffle(++(certs.begin()), certs.end(), uniform_shuffle);
+ std::shuffle(++(certs.begin()), certs.end(), rbg);
Botan::Path_Validation_Result validation_result =
Botan::x509_path_validate(certs, restrictions, trusted, "",