diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/cert/x509/certstor.cpp | 4 | ||||
-rw-r--r-- | src/lib/utils/exceptn.h | 8 | ||||
-rw-r--r-- | src/lib/utils/filesystem.cpp (renamed from src/lib/utils/fs.cpp) | 60 | ||||
-rw-r--r-- | src/lib/utils/filesystem.h (renamed from src/lib/utils/fs.h) | 7 | ||||
-rw-r--r-- | src/lib/utils/info.txt | 24 |
5 files changed, 63 insertions, 40 deletions
diff --git a/src/lib/cert/x509/certstor.cpp b/src/lib/cert/x509/certstor.cpp index d075fe706..e3498f602 100644 --- a/src/lib/cert/x509/certstor.cpp +++ b/src/lib/cert/x509/certstor.cpp @@ -6,7 +6,7 @@ */ #include <botan/certstor.h> -#include <botan/fs.h> +#include <botan/internal/filesystem.h> namespace Botan { @@ -118,7 +118,7 @@ Certificate_Store_In_Memory::Certificate_Store_In_Memory(const std::string& dir) if(dir == "") return; - std::vector<std::string> maybe_certs = list_all_readable_files_in_or_under(dir); + std::vector<std::string> maybe_certs = get_files_recursive(dir); for(auto&& cert_file : maybe_certs) { try diff --git a/src/lib/utils/exceptn.h b/src/lib/utils/exceptn.h index 7a10319c5..06db697bf 100644 --- a/src/lib/utils/exceptn.h +++ b/src/lib/utils/exceptn.h @@ -158,6 +158,14 @@ struct BOTAN_DLL Stream_IO_Error : public Exception }; /** +* No_Filesystem_Access Exception +*/ +struct BOTAN_DLL No_Filesystem_Access : public Exception + { + No_Filesystem_Access() : Exception("No filesystem access enabled.") {} + }; + +/** * Self Test Failure Exception */ struct BOTAN_DLL Self_Test_Failure : public Internal_Error diff --git a/src/lib/utils/fs.cpp b/src/lib/utils/filesystem.cpp index b1ada17db..0a31dec7a 100644 --- a/src/lib/utils/fs.cpp +++ b/src/lib/utils/filesystem.cpp @@ -4,40 +4,46 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/fs.h> +#include <botan/exceptn.h> +#include <botan/internal/filesystem.h> #include <algorithm> -#include <deque> -#include <functional> -#include <memory> #if defined(BOTAN_HAS_BOOST_FILESYSTEM) #include <boost/filesystem.hpp> - #elif defined(BOTAN_TARGET_OS_HAS_READDIR) #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> + #include <deque> + #include <memory> + #include <functional> #endif namespace Botan { -std::vector<std::string> -list_all_readable_files_in_or_under(const std::string& dir_path) - { - std::vector<std::string> paths; +namespace { #if defined(BOTAN_HAS_BOOST_FILESYSTEM) +std::vector<std::string> impl_boost_filesystem(const std::string& dir_path) +{ namespace fs = boost::filesystem; - fs::recursive_directory_iterator end; - for(fs::recursive_directory_iterator dir(dir_path); dir != end; ++dir) + std::vector<std::string> out; + + for(fs::recursive_directory_iterator dir(dir_path), end; dir != end; ++dir) { if(fs::is_regular_file(dir->path())) - paths.push_back(dir->path().string()); + { + out.push_back(dir->path().string()); + } } + return out; +} #elif defined(BOTAN_TARGET_OS_HAS_READDIR) - +std::vector<std::string> impl_readdir(const std::string& dir_path) + { + std::vector<std::string> out; std::deque<std::string> dir_list; dir_list.push_back(dir_path); @@ -65,22 +71,32 @@ list_all_readable_files_in_or_under(const std::string& dir_path) if(S_ISDIR(stat_buf.st_mode)) dir_list.push_back(full_path); else if(S_ISREG(stat_buf.st_mode)) - paths.push_back(full_path); + out.push_back(full_path); } } } -#else -#if defined(_MSC_VER) - #pragma message ( "No filesystem access enabled" ) -#else - #warning "No filesystem access enabled" + + return out; + } #endif + +} + +std::vector<std::string> get_files_recursive(const std::string& dir) + { + std::vector<std::string> files; + +#if defined(BOTAN_HAS_BOOST_FILESYSTEM) + files = impl_boost_filesystem(dir); +#elif defined(BOTAN_TARGET_OS_HAS_READDIR) + files = impl_readdir(dir); +#else + throw No_Filesystem_Access(); #endif - std::sort(paths.begin(), paths.end()); + std::sort(files.begin(), files.end()); - return paths; + return files; } } - diff --git a/src/lib/utils/fs.h b/src/lib/utils/filesystem.h index 25ec5ecd1..6f9b5196e 100644 --- a/src/lib/utils/fs.h +++ b/src/lib/utils/filesystem.h @@ -4,8 +4,8 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#ifndef BOTAN_UTIL_FS_H__ -#define BOTAN_UTIL_FS_H__ +#ifndef BOTAN_UTIL_FILESYSTEM_H__ +#define BOTAN_UTIL_FILESYSTEM_H__ #include <botan/types.h> #include <vector> @@ -13,8 +13,7 @@ namespace Botan { -BOTAN_DLL std::vector<std::string> -list_all_readable_files_in_or_under(const std::string& dir); +BOTAN_DLL std::vector<std::string> get_files_recursive(const std::string& dir); } diff --git a/src/lib/utils/info.txt b/src/lib/utils/info.txt index 90f45aa3f..b8c7b85d2 100644 --- a/src/lib/utils/info.txt +++ b/src/lib/utils/info.txt @@ -2,17 +2,6 @@ define UTIL_FUNCTIONS 20140123 load_on always -<header:internal> -bit_ops.h -donna128.h -prefetch.h -rounding.h -semaphore.h -stl_util.h -ta_utils.h -xor_buf.h -</header:internal> - <header:public> assert.h bswap.h @@ -21,7 +10,6 @@ charset.h cpuid.h database.h exceptn.h -fs.h get_byte.h loadstor.h mem_ops.h @@ -31,3 +19,15 @@ rotate.h types.h version.h </header:public> + +<header:internal> +bit_ops.h +donna128.h +filesystem.h +prefetch.h +rounding.h +semaphore.h +stl_util.h +ta_utils.h +xor_buf.h +</header:internal> |