20constexpr std::array<Utf8Char, 8> PKCS11_INTERFACE_NAME_ARR = {
"PKCS 11"};
21const std::span<const Utf8Char> PKCS11_INTERFACE_NAME(PKCS11_INTERFACE_NAME_ARR.data(),
22 PKCS11_INTERFACE_NAME_ARR.size() - 1);
26 auto version_value = [](
const Version& v) -> uint16_t {
27 return static_cast<uint16_t
>(v.major) << 8 |
static_cast<uint16_t
>(v.minor);
29 return version_value(left) <=> version_value(right);
33 return left.major == right.major && left.minor == right.minor;
40 return *
reinterpret_cast<Version*
>(p11_interface.pFunctionList);
43std::span<const Utf8Char> name_of(
const Interface& p11_interface) {
46 const std::string_view s(
reinterpret_cast<char*
>(p11_interface.pInterfaceName));
47 return std::span<const Utf8Char>(
reinterpret_cast<const Utf8Char*
>(s.data()), s.size());
54 throw PKCS11_Error(
"PKCS #11 interface has null pInterfaceName or pFunctionList");
59 return version_of(m_p11_interface);
63 return name_of(m_p11_interface);
74 if(!rv || func_list ==
nullptr) {
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) {
94 if(i.pFunctionList ==
nullptr || i.pInterfaceName ==
nullptr) {
97 if(!std::ranges::equal(name_of(i), PKCS11_INTERFACE_NAME)) {
103 std::vector<Interface> valid_interfaces;
104 std::copy_if(interface_list.begin(), interface_list.end(), std::back_inserter(valid_interfaces), is_valid_interface);
106 if(valid_interfaces.empty()) {
114 const Version left_version = version_of(left);
115 const Version right_version = version_of(right);
117 if(left_version == right_version) {
121 return left_version < right_version;
123 auto best_interface = std::max_element(valid_interfaces.begin(), valid_interfaces.end(), priority_comparator);
128 if(!std::ranges::equal(
name(), PKCS11_INTERFACE_NAME)) {
135 if(!std::ranges::equal(
name(), PKCS11_INTERFACE_NAME)) {
145 if(!std::ranges::equal(
name(), PKCS11_INTERFACE_NAME)) {
155 static std::array<Utf8Char, 8> STATIC_PKCS11_INTERFACE_NAME_ARR = {
"PKCS 11"};
156 return STATIC_PKCS11_INTERFACE_NAME_ARR.data();
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()
InterfaceWrapper(Interface p11_interface)
Basic constructor using an interface.
std::span< const Utf8Char > name() const
Access the name of the 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
auto operator<=>(const Strong< T, Tags... > &lhs, const Strong< T, Tags... > &rhs)
bool operator==(const AlgorithmIdentifier &x, const AlgorithmIdentifier &y)
CK_UTF8CHAR * pInterfaceName