• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 19730695394

27 Nov 2025 08:58AM UTC coverage: 91.763% (+1.1%) from 90.661%
19730695394

push

github

web-flow
Merge pull request #4540 from Rohde-Schwarz/feature/pkcs11v32

PKCS #11 Version 3.2 Support

102511 of 111713 relevant lines covered (91.76%)

12543169.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/src/lib/utils/dyn_load/dyn_load.cpp
1
/*
2
* Dynamically Loaded Object
3
* (C) 2010 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/dyn_load.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/internal/fmt.h>
12
#include <botan/internal/target_info.h>
13
#include <sstream>
14

15
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
16
   #include <dlfcn.h>
17
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
18
   #define NOMINMAX 1
19
   #define _WINSOCKAPI_  // stop windows.h including winsock.h
20
   #include <windows.h>
21
#endif
22

23
namespace Botan {
24

25
namespace {
26

27
[[noreturn]] void raise_runtime_loader_exception(std::string_view lib_name, const char* msg) {
1✔
28
   std::ostringstream err;
1✔
29
   err << "Failed to load " << lib_name << ": ";
1✔
30
   if(msg != nullptr) {
1✔
31
      err << msg;
1✔
32
   } else {
33
      err << "Unknown error";
×
34
   }
35

36
   throw System_Error(err.str(), 0);
2✔
37
}
1✔
38

39
void* open_shared_library(const std::string& library) {
77✔
40
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
41
   void* lib = ::dlopen(library.c_str(), RTLD_LAZY);
77✔
42

43
   if(lib != nullptr) {
77✔
44
      return lib;
76✔
45
   } else {
46
      raise_runtime_loader_exception(library, ::dlerror());
1✔
47
   }
48

49
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
50
   void* lib = ::LoadLibraryA(library.c_str());
51

52
   if(lib != nullptr) {
53
      return lib;
54
   } else {
55
      raise_runtime_loader_exception(library, "LoadLibrary failed");
56
   }
57
#else
58
   raise_runtime_loader_exception(library, "Dynamic loading not supported");
59
#endif
60
}
61

62
}  // namespace
63

64
Dynamically_Loaded_Library::Dynamically_Loaded_Library(std::string_view library) :
77✔
65
      m_lib_name(library), m_lib(open_shared_library(m_lib_name)) {}
77✔
66

67
Dynamically_Loaded_Library::~Dynamically_Loaded_Library() {
76✔
68
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
69
   ::dlclose(m_lib);
76✔
70
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
71
   ::FreeLibrary(reinterpret_cast<HMODULE>(m_lib));
72
#endif
73
}
76✔
74

75
void* Dynamically_Loaded_Library::resolve_symbol(const std::string& symbol) const {
78✔
76
   if(void* addr = resolve_symbol_internal(symbol)) {
78✔
77
      return addr;
78✔
78
   }
79
   throw Invalid_Argument(fmt("Failed to resolve symbol {} in {}", symbol, m_lib_name));
×
80
}
81

82
void* Dynamically_Loaded_Library::resolve_symbol_internal(const std::string& symbol) const {
131✔
83
   void* addr = nullptr;
131✔
84
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
85
   addr = ::dlsym(m_lib, symbol.c_str());
131✔
86
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
87
   addr = reinterpret_cast<void*>(::GetProcAddress(reinterpret_cast<HMODULE>(m_lib), symbol.c_str()));
88
#endif
89

90
   return addr;
131✔
91
}
92

93
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc