8#include <botan/assert.h>
21constexpr std::array<Utf8Char, 8> PKCS11_INTERFACE_NAME_ARR = {
"PKCS 11"};
22const std::span<const Utf8Char> PKCS11_INTERFACE_NAME(PKCS11_INTERFACE_NAME_ARR.data(),
23 PKCS11_INTERFACE_NAME_ARR.size() - 1);
27 auto version_value = [](
const Version& v) -> uint16_t {
28 return static_cast<uint16_t
>(v.major) << 8 |
static_cast<uint16_t
>(v.minor);
30 return version_value(left) <=> version_value(right);
34 return left.major == right.major && left.minor == right.minor;
41 return *
reinterpret_cast<Version*
>(interface.pFunctionList);
44std::span<const Utf8Char> name_of(
const Interface& interface) {
47 const std::string_view s(
reinterpret_cast<char*
>(interface.pInterfaceName));
48 return std::span<const Utf8Char>(
reinterpret_cast<const Utf8Char*
>(s.data()), s.size());
59 return version_of(m_interface);
63 return name_of(m_interface);
80 .pFunctionList = func_list,
84 std::vector<Interface> interface_list(count);
88 throw Invalid_Argument(
"Unexpected error while loading PKCS#11 interface list.");
93 auto is_valid_interface = [](
const Interface& i) {
100 std::vector<Interface> valid_interfaces;
101 std::copy_if(interface_list.begin(), interface_list.end(), std::back_inserter(valid_interfaces), is_valid_interface);
103 if(valid_interfaces.empty()) {
111 const Version left_version = version_of(left);
112 const Version right_version = version_of(right);
114 if(left_version == right_version) {
118 return left_version < right_version;
120 auto best_interface = std::max_element(valid_interfaces.begin(), valid_interfaces.end(), priority_comparator);
125 if(!std::ranges::equal(
name(), PKCS11_INTERFACE_NAME)) {
132 if(!std::ranges::equal(
name(), PKCS11_INTERFACE_NAME)) {
142 if(!std::ranges::equal(
name(), PKCS11_INTERFACE_NAME)) {
152 static std::array<Utf8Char, 8> STATIC_PKCS11_INTERFACE_NAME_ARR = {
"PKCS 11"};
153 return STATIC_PKCS11_INTERFACE_NAME_ARR.data();
#define BOTAN_ASSERT_NONNULL(ptr)
const FunctionList32 & func_3_2() const
Access a function list that contains all methods since PKCS #11 v.3.2.
static Utf8Char * p11_interface_name_ptr()
std::span< const Utf8Char > name() const
Access the name of the interface.
InterfaceWrapper(Interface raw_interface)
Basic constructor using an interface.
const Interface & raw_interface() const
Access the underlying interface object.
const FunctionList30 & func_3_0() const
Access a function list that contains all methods since PKCS #11 v.3.0.
const FunctionList & func_2_40() const
Access a function list that contains all methods since PKCS #11 v.2.40.
static InterfaceWrapper latest_p11_interface(Dynamically_Loaded_Library &library)
Version version() const
Access the version of the interface.
static bool C_GetFunctionList(const Dynamically_Loaded_Library &pkcs11_module, FunctionList **function_list_ptr_ptr, ReturnValue *return_value=ThrowException)
static bool C_GetInterfaceList(const Dynamically_Loaded_Library &pkcs11_module, Interface *interface_list_ptr, Ulong *count_ptr, ReturnValue *return_value=ThrowException)
CK_FUNCTION_LIST FunctionList
CK_FUNCTION_LIST_3_0 FunctionList30
CK_FUNCTION_LIST_3_2 FunctionList32
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
auto operator<=>(const Strong< T, Tags... > &lhs, const Strong< T, Tags... > &rhs)