12#include <botan/assert.h>
13#include <botan/p11_types.h>
14#include <botan/internal/dyn_load.h>
33 }
else if(return_value !=
nullptr) {
35 *return_value =
static_cast<ReturnValue>(function_result);
49 session.
set_pin(old_pin, new_pin);
55 session.
set_pin(old_so_pin, new_so_pin);
65 m_interface_wrapper([&] {
66 BOTAN_ARG_CHECK(ptr !=
nullptr,
"Function list pointer must not be nullptr");
79 return handle_return_value(m_interface_wrapper.func_2_40().C_Initialize(
const_cast<void*
>(init_args)), return_value);
83 return handle_return_value(m_interface_wrapper.func_2_40().C_Finalize(reserved), return_value);
87 return handle_return_value(m_interface_wrapper.func_2_40().C_GetInfo(info_ptr), return_value);
95 get_function_list get_function_list_ptr = pkcs11_module.
resolve<get_function_list>(
"C_GetFunctionList");
105 if(
auto get_interface_list_ptr = pkcs11_module.
try_resolve_symbol<get_interface_list>(
"C_GetInterfaceList");
106 get_interface_list_ptr.has_value()) {
107 return handle_return_value(get_interface_list_ptr.value()(interface_list_ptr, count_ptr), return_value);
122 get_interface_ptr.has_value()) {
124 get_interface_ptr.value()(
125 const_cast<Utf8Char*
>(interface_name_ptr),
const_cast<Version*
>(version_ptr), interface_ptr_ptr,
flags),
138 return handle_return_value(m_interface_wrapper.func_2_40().C_GetSlotList(token_present, slot_list_ptr, count_ptr),
146 Ulong number_slots = 0;
148 const bool success =
C_GetSlotList(
static_cast<Bbool>(token_present),
nullptr, &number_slots, return_value);
150 if(!success || number_slots == 0) {
155 slot_ids.resize(number_slots);
156 return C_GetSlotList(
static_cast<Bbool>(token_present), slot_ids.data(), &number_slots, return_value);
160 return handle_return_value(m_interface_wrapper.func_2_40().C_GetSlotInfo(slot_id, info_ptr), return_value);
164 return handle_return_value(m_interface_wrapper.func_2_40().C_GetTokenInfo(slot_id, info_ptr), return_value);
182 std::vector<MechanismType>& mechanisms,
187 Ulong number_mechanisms = 0;
189 const bool success =
C_GetMechanismList(slot_id,
nullptr, &number_mechanisms, return_value);
191 if(!success || number_mechanisms == 0) {
196 mechanisms.resize(number_mechanisms);
198 slot_id,
reinterpret_cast<MechanismType*
>(mechanisms.data()), &number_mechanisms, return_value);
206 m_interface_wrapper.func_2_40().C_GetMechanismInfo(slot_id,
static_cast<CK_MECHANISM_TYPE>(type), info_ptr),
216 m_interface_wrapper.func_2_40().C_InitToken(
217 slot_id,
const_cast<Utf8Char*
>(so_pin_ptr), so_pin_len,
const_cast<Utf8Char*
>(label_ptr)),
226 m_interface_wrapper.func_2_40().C_InitPIN(session,
const_cast<Utf8Char*
>(pin_ptr), pin_len), return_value);
236 m_interface_wrapper.func_2_40().C_SetPIN(
237 session,
const_cast<Utf8Char*
>(old_pin_ptr), old_len,
const_cast<Utf8Char*
>(new_pin_ptr), new_len),
250 m_interface_wrapper.func_2_40().C_OpenSession(slot_id,
flags, application, notify, session_ptr), return_value);
254 return handle_return_value(m_interface_wrapper.func_2_40().C_CloseSession(session), return_value);
258 return handle_return_value(m_interface_wrapper.func_2_40().C_CloseAllSessions(slot_id), return_value);
262 return handle_return_value(m_interface_wrapper.func_2_40().C_GetSessionInfo(session, info_ptr), return_value);
270 Byte* operation_state_ptr,
271 Ulong* operation_state_len_ptr,
274 m_interface_wrapper.func_2_40().C_GetOperationState(session, operation_state_ptr, operation_state_len_ptr),
279 const Byte* operation_state_ptr,
280 Ulong operation_state_len,
285 m_interface_wrapper.func_2_40().C_SetOperationState(
286 session,
const_cast<Byte*
>(operation_state_ptr), operation_state_len, encryption_key, authentication_key),
293 m_interface_wrapper.func_2_40().C_Login(
309 const_cast<Utf8Char*
>(username_ptr),
315 return handle_return_value(m_interface_wrapper.func_2_40().C_Logout(session), return_value);
322 return handle_return_value(m_interface_wrapper.func_3_2().C_GetSessionValidationFlags(session, type, flags_ptr),
334 m_interface_wrapper.func_2_40().C_CreateObject(session, attribute_template_ptr, count, object_ptr), return_value);
344 m_interface_wrapper.func_2_40().C_CopyObject(session,
object, attribute_template_ptr, count, new_object_ptr),
349 return handle_return_value(m_interface_wrapper.func_2_40().C_DestroyObject(session,
object), return_value);
356 return handle_return_value(m_interface_wrapper.func_2_40().C_GetObjectSize(session,
object, size_ptr), return_value);
365 m_interface_wrapper.func_2_40().C_GetAttributeValue(session,
object, attribute_template_ptr, count),
375 m_interface_wrapper.func_2_40().C_SetAttributeValue(session,
object, attribute_template_ptr, count),
383 return handle_return_value(m_interface_wrapper.func_2_40().C_FindObjectsInit(session, attribute_template_ptr, count),
389 Ulong max_object_count,
390 Ulong* object_count_ptr,
393 m_interface_wrapper.func_2_40().C_FindObjects(session, object_ptr, max_object_count, object_count_ptr),
398 return handle_return_value(m_interface_wrapper.func_2_40().C_FindObjectsFinal(session), return_value);
408 m_interface_wrapper.func_2_40().C_EncryptInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key), return_value);
412 const Byte* data_ptr,
414 Byte* encrypted_data_ptr,
415 Ulong* encrypted_data_len_ptr,
418 m_interface_wrapper.func_2_40().C_Encrypt(
419 session,
const_cast<Byte*
>(data_ptr), data_len, encrypted_data_ptr, encrypted_data_len_ptr),
424 const Byte* part_ptr,
426 Byte* encrypted_part_ptr,
427 Ulong* encrypted_part_len_ptr,
430 m_interface_wrapper.func_2_40().C_EncryptUpdate(
431 session,
const_cast<Byte*
>(part_ptr), part_len, encrypted_part_ptr, encrypted_part_len_ptr),
436 Byte* last_encrypted_part_ptr,
437 Ulong* last_encrypted_part_len_ptr,
440 m_interface_wrapper.func_2_40().C_EncryptFinal(session, last_encrypted_part_ptr, last_encrypted_part_len_ptr),
451 m_interface_wrapper.func_3_0().C_MessageEncryptInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
456 const void* parameter_ptr,
458 const Byte* associated_data_ptr,
459 Ulong associated_data_len,
460 const Byte* plaintext_ptr,
462 Byte* ciphertext_ptr,
463 Ulong* ciphertext_len_ptr,
466 const_cast<void*
>(parameter_ptr),
468 const_cast<Byte*
>(associated_data_ptr),
470 const_cast<Byte*
>(plaintext_ptr),
478 const void* parameter_ptr,
480 const Byte* associated_data_ptr,
481 Ulong associated_data_len,
484 m_interface_wrapper.func_3_0().C_EncryptMessageBegin(session,
485 const_cast<void*
>(parameter_ptr),
487 const_cast<Byte*
>(associated_data_ptr),
488 associated_data_len),
493 const void* parameter_ptr,
495 const Byte* plaintext_part_ptr,
496 Ulong plaintext_part_len,
497 Byte* ciphertext_ptr,
498 Ulong* ciphertext_part_len_ptr,
502 const_cast<void*
>(parameter_ptr),
504 const_cast<Byte*
>(plaintext_part_ptr),
507 ciphertext_part_len_ptr,
513 return handle_return_value(m_interface_wrapper.func_3_0().C_MessageEncryptFinal(session), return_value);
523 m_interface_wrapper.func_2_40().C_DecryptInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key), return_value);
527 const Byte* encrypted_data_ptr,
528 Ulong encrypted_data_len,
533 m_interface_wrapper.func_2_40().C_Decrypt(
534 session,
const_cast<Byte*
>(encrypted_data_ptr), encrypted_data_len, data_ptr, data_len_ptr),
539 const Byte* encrypted_part_ptr,
540 Ulong encrypted_part_len,
545 m_interface_wrapper.func_2_40().C_DecryptUpdate(
546 session,
const_cast<Byte*
>(encrypted_part_ptr), encrypted_part_len, part_ptr, part_len_ptr),
552 Ulong* last_part_len_ptr,
554 return handle_return_value(m_interface_wrapper.func_2_40().C_DecryptFinal(session, last_part_ptr, last_part_len_ptr),
565 m_interface_wrapper.func_3_0().C_MessageDecryptInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
570 const void* parameter_ptr,
572 const Byte* associated_data_ptr,
573 Ulong associated_data_len,
574 const Byte* ciphertext_ptr,
575 Ulong ciphertext_len,
577 Ulong* plaintext_len_ptr,
580 const_cast<void*
>(parameter_ptr),
582 const_cast<Byte*
>(associated_data_ptr),
584 const_cast<Byte*
>(ciphertext_ptr),
592 const void* parameter_ptr,
594 const Byte* associated_data_ptr,
595 Ulong associated_data_len,
598 m_interface_wrapper.func_3_0().C_DecryptMessageBegin(session,
599 const_cast<void*
>(parameter_ptr),
601 const_cast<Byte*
>(associated_data_ptr),
602 associated_data_len),
607 const void* parameter_ptr,
609 const Byte* ciphertext_part_ptr,
610 Ulong ciphertext_part_len,
612 Ulong* plaintext_part_len_ptr,
616 m_interface_wrapper.func_3_0().C_DecryptMessageNext(session,
617 const_cast<void*
>(parameter_ptr),
619 const_cast<Byte*
>(ciphertext_part_ptr),
622 plaintext_part_len_ptr,
628 return handle_return_value(m_interface_wrapper.func_3_0().C_MessageDecryptFinal(session), return_value);
639 const Byte* data_ptr,
642 Ulong* digest_len_ptr,
645 session,
const_cast<Byte*
>(data_ptr), data_len, digest_ptr, digest_len_ptr),
650 const Byte* part_ptr,
654 m_interface_wrapper.func_2_40().C_DigestUpdate(session,
const_cast<Byte*
>(part_ptr), part_len), return_value);
658 return handle_return_value(m_interface_wrapper.func_2_40().C_DigestKey(session, key), return_value);
663 Ulong* digest_len_ptr,
665 return handle_return_value(m_interface_wrapper.func_2_40().C_DigestFinal(session, digest_ptr, digest_len_ptr),
676 m_interface_wrapper.func_2_40().C_SignInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key), return_value);
680 const Byte* data_ptr,
683 Ulong* signature_len_ptr,
686 session,
const_cast<Byte*
>(data_ptr), data_len, signature_ptr, signature_len_ptr),
691 const Byte* part_ptr,
695 m_interface_wrapper.func_2_40().C_SignUpdate(session,
const_cast<Byte*
>(part_ptr), part_len), return_value);
700 Ulong* signature_len_ptr,
702 return handle_return_value(m_interface_wrapper.func_2_40().C_SignFinal(session, signature_ptr, signature_len_ptr),
711 m_interface_wrapper.func_2_40().C_SignRecoverInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
719 Ulong* signature_len,
722 session,
const_cast<Byte*
>(data), data_len, signature, signature_len),
733 m_interface_wrapper.func_3_0().C_MessageSignInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
738 const void* parameter_ptr,
740 const Byte* data_ptr,
743 Ulong* signature_len_ptr,
746 const_cast<void*
>(parameter_ptr),
748 const_cast<Byte*
>(data_ptr),
756 const void* parameter_ptr,
760 m_interface_wrapper.func_3_0().C_SignMessageBegin(session,
const_cast<void*
>(parameter_ptr), parameter_len),
765 const void* parameter_ptr,
767 const Byte* data_ptr,
770 Ulong* signature_len_ptr,
773 const_cast<void*
>(parameter_ptr),
775 const_cast<Byte*
>(data_ptr),
783 return handle_return_value(m_interface_wrapper.func_3_0().C_MessageSignFinal(session), return_value);
793 m_interface_wrapper.func_2_40().C_VerifyInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key), return_value);
797 const Byte* data_ptr,
799 const Byte* signature_ptr,
803 m_interface_wrapper.func_2_40().C_Verify(
804 session,
const_cast<Byte*
>(data_ptr), data_len,
const_cast<Byte*
>(signature_ptr), signature_len),
809 const Byte* part_ptr,
813 m_interface_wrapper.func_2_40().C_VerifyUpdate(session,
const_cast<Byte*
>(part_ptr), part_len), return_value);
817 const Byte* signature_ptr,
821 m_interface_wrapper.func_2_40().C_VerifyFinal(session,
const_cast<Byte*
>(signature_ptr), signature_len),
830 m_interface_wrapper.func_2_40().C_VerifyRecoverInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
835 const Byte* signature_ptr,
841 session,
const_cast<Byte*
>(signature_ptr), signature_len, data_ptr, data_len_ptr),
848 const Byte* signature_ptr,
852 m_interface_wrapper.func_3_2().C_VerifySignatureInit(
853 session,
const_cast<Mechanism*
>(mechanism_ptr), key,
const_cast<Byte*
>(signature_ptr), signature_len),
858 const Byte* data_ptr,
862 m_interface_wrapper.func_3_2().C_VerifySignature(session,
const_cast<Byte*
>(data_ptr), data_len), return_value);
866 const Byte* part_ptr,
870 m_interface_wrapper.func_3_2().C_VerifySignatureUpdate(session,
const_cast<Byte*
>(part_ptr), part_len),
875 return handle_return_value(m_interface_wrapper.func_3_2().C_VerifySignatureFinal(session), return_value);
885 m_interface_wrapper.func_3_0().C_MessageVerifyInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
890 const void* parameter_ptr,
892 const Byte* data_ptr,
894 const Byte* signature_ptr,
898 const_cast<void*
>(parameter_ptr),
900 const_cast<Byte*
>(data_ptr),
902 const_cast<Byte*
>(signature_ptr),
908 const void* parameter_ptr,
912 m_interface_wrapper.func_3_0().C_VerifyMessageBegin(session,
const_cast<void*
>(parameter_ptr), parameter_len),
917 const void* parameter_ptr,
919 const Byte* data_ptr,
921 const Byte* signature_ptr,
925 const_cast<void*
>(parameter_ptr),
927 const_cast<Byte*
>(data_ptr),
929 const_cast<Byte*
>(signature_ptr),
935 return handle_return_value(m_interface_wrapper.func_3_0().C_MessageVerifyFinal(session), return_value);
941 const Byte* part_ptr,
943 Byte* encrypted_part_ptr,
944 Ulong* encrypted_part_len_ptr,
947 m_interface_wrapper.func_2_40().C_DigestEncryptUpdate(
948 session,
const_cast<Byte*
>(part_ptr), part_len, encrypted_part_ptr, encrypted_part_len_ptr),
953 const Byte* encrypted_part_ptr,
954 Ulong encrypted_part_len,
959 m_interface_wrapper.func_2_40().C_DecryptDigestUpdate(
960 session,
const_cast<Byte*
>(encrypted_part_ptr), encrypted_part_len, part_ptr, part_len_ptr),
965 const Byte* part_ptr,
967 Byte* encrypted_part_ptr,
968 Ulong* encrypted_part_len_ptr,
971 m_interface_wrapper.func_2_40().C_SignEncryptUpdate(
972 session,
const_cast<Byte*
>(part_ptr), part_len, encrypted_part_ptr, encrypted_part_len_ptr),
977 const Byte* encrypted_part_ptr,
978 Ulong encrypted_part_len,
983 m_interface_wrapper.func_2_40().C_DecryptVerifyUpdate(
984 session,
const_cast<Byte*
>(encrypted_part_ptr), encrypted_part_len, part_ptr, part_len_ptr),
997 m_interface_wrapper.func_2_40().C_GenerateKey(
998 session,
const_cast<Mechanism*
>(mechanism_ptr), attribute_template_ptr, count, key_ptr),
1005 Ulong public_key_attribute_count,
1007 Ulong private_key_attribute_count,
1013 public_key_template_ptr,
1014 public_key_attribute_count,
1015 private_key_template_ptr,
1016 private_key_attribute_count,
1026 Byte* wrapped_key_ptr,
1027 Ulong* wrapped_key_len_ptr,
1030 m_interface_wrapper.func_2_40().C_WrapKey(
1031 session,
const_cast<Mechanism*
>(mechanism_ptr), wrapping_key, key, wrapped_key_ptr, wrapped_key_len_ptr),
1038 const Byte* wrapped_key_ptr,
1039 Ulong wrapped_key_len,
1041 Ulong attribute_count,
1047 const_cast<Byte*
>(wrapped_key_ptr),
1049 attribute_template_ptr,
1059 Ulong attribute_count,
1063 m_interface_wrapper.func_2_40().C_DeriveKey(
1064 session,
const_cast<Mechanism*
>(mechanism_ptr), base_key, attribute_template_ptr, attribute_count, key_ptr),
1072 const Byte* associated_data_ptr,
1073 Ulong associated_data_len,
1074 Byte* wrapped_key_ptr,
1075 Ulong* wrapped_key_len_ptr,
1078 m_interface_wrapper.func_3_2().C_WrapKeyAuthenticated(session,
1082 const_cast<Byte*
>(associated_data_ptr),
1083 associated_data_len,
1085 wrapped_key_len_ptr),
1092 const Byte* wrapped_key_ptr,
1093 Ulong wrapped_key_len,
1095 Ulong attribute_count,
1096 const Byte* associated_data_ptr,
1097 Ulong associated_data_len,
1101 m_interface_wrapper.func_3_2().C_UnwrapKeyAuthenticated(session,
1104 const_cast<Byte*
>(wrapped_key_ptr),
1106 attribute_template_ptr,
1108 const_cast<Byte*
>(associated_data_ptr),
1109 associated_data_len,
1118 Ulong attribute_count,
1119 Byte* ciphertext_ptr,
1120 Ulong* ciphertext_len_ptr,
1138 Ulong attribute_count,
1139 const Byte* ciphertext_ptr,
1140 Ulong ciphertext_len,
1148 const_cast<Byte*
>(ciphertext_ptr),
1157 const Byte* seed_ptr,
1161 m_interface_wrapper.func_2_40().C_SeedRandom(session,
const_cast<Byte*
>(seed_ptr), seed_len), return_value);
1165 Byte* random_data_ptr,
1168 return handle_return_value(m_interface_wrapper.func_2_40().C_GenerateRandom(session, random_data_ptr, random_len),
1175 return handle_return_value(m_interface_wrapper.func_2_40().C_GetFunctionStatus(session), return_value);
1179 return handle_return_value(m_interface_wrapper.func_2_40().C_CancelFunction(session), return_value);
1189 m_interface_wrapper.func_3_2().C_AsyncComplete(session,
const_cast<Utf8Char*
>(function_name_ptr), result_ptr),
1198 m_interface_wrapper.func_3_2().C_AsyncGetID(session,
const_cast<Utf8Char*
>(function_name_ptr), id_ptr),
1209 session,
const_cast<Utf8Char*
>(function_name_ptr),
id, data_ptr, data_len),
1214 return reinterpret_cast<FunctionList*
>(m_interface_wrapper.raw_interface().pFunctionList);
#define BOTAN_ARG_CHECK(expr, msg)
std::optional< PtrT > try_resolve_symbol(const std::string &symbol) const
PtrT resolve(const std::string &symbol) const
Wraps a PKCS #11 Interface object.
static Utf8Char * p11_interface_name_ptr()
bool C_VerifyMessage(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *data_ptr, Ulong data_len, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException)
bool C_CancelFunction(SessionHandle session, ReturnValue *return_value=ThrowException) const
bool C_MessageSignFinal(SessionHandle session, ReturnValue *return_value=ThrowException)
bool C_EncryptMessageBegin(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *associated_data_ptr, Ulong associated_data_len, ReturnValue *return_value=ThrowException)
bool C_SignEncryptUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, Byte *encrypted_part_ptr, Ulong *encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_GetSessionInfo(SessionHandle session, SessionInfo *info_ptr, ReturnValue *return_value=ThrowException) const
bool C_VerifySignatureInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException)
bool C_Logout(SessionHandle session, ReturnValue *return_value=ThrowException) const
bool C_MessageEncryptFinal(SessionHandle session, ReturnValue *return_value=ThrowException)
bool C_WrapKey(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle wrapping_key, ObjectHandle key, Byte *wrapped_key_ptr, Ulong *wrapped_key_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_InitPIN(SessionHandle session, const Utf8Char *pin_ptr, Ulong pin_len, ReturnValue *return_value=ThrowException) const
bool C_GetOperationState(SessionHandle session, Byte *operation_state_ptr, Ulong *operation_state_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DigestKey(SessionHandle session, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_DecryptUpdate(SessionHandle session, const Byte *encrypted_part_ptr, Ulong encrypted_part_len, Byte *part_ptr, Ulong *part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_MessageDecryptFinal(SessionHandle session, ReturnValue *return_value=ThrowException)
bool C_GetTokenInfo(SlotId slot_id, TokenInfo *info_ptr, ReturnValue *return_value=ThrowException) const
bool C_SetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
bool C_VerifyMessageNext(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *data_ptr, Ulong data_len, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException)
bool C_SignRecover(SessionHandle session, const Byte *data_ptr, Ulong data_len, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_MessageDecryptInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException)
bool C_DecryptFinal(SessionHandle session, Byte *last_part_ptr, Ulong *last_part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_VerifyRecover(SessionHandle session, const Byte *signature_ptr, Ulong signature_len, Byte *data_ptr, Ulong *data_len_ptr, ReturnValue *return_value=ThrowException) const
static bool C_GetFunctionList(const Dynamically_Loaded_Library &pkcs11_module, FunctionList **function_list_ptr_ptr, ReturnValue *return_value=ThrowException)
bool C_EncapsulateKey(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle public_key, Attribute *template_ptr, Ulong attribute_count, Byte *ciphertext_ptr, Ulong *ciphertext_len_ptr, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException)
bool C_InitToken(SlotId slot_id, const Utf8Char *so_pin_ptr, Ulong so_pin_len, const Utf8Char *label_ptr, ReturnValue *return_value=ThrowException) const
bool C_GetSlotInfo(SlotId slot_id, SlotInfo *info_ptr, ReturnValue *return_value=ThrowException) const
bool C_EncryptFinal(SessionHandle session, Byte *last_encrypted_part_ptr, Ulong *last_encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_FindObjectsInit(SessionHandle session, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
bool C_VerifyUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException) const
bool C_GetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
bool C_DestroyObject(SessionHandle session, ObjectHandle object, ReturnValue *return_value=ThrowException) const
bool C_VerifyMessageBegin(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, ReturnValue *return_value=ThrowException)
bool C_Login(SessionHandle session, UserType user_type, const Utf8Char *pin_ptr, Ulong pin_len, ReturnValue *return_value=ThrowException) const
bool C_CopyObject(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *new_object_ptr, ReturnValue *return_value=ThrowException) const
bool C_EncryptMessage(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *associated_data_ptr, Ulong associated_data_len, const Byte *plaintext_ptr, Ulong plaintext_len, Byte *ciphertext_ptr, Ulong *ciphertext_len_ptr, ReturnValue *return_value=ThrowException)
bool C_GenerateRandom(SessionHandle session, Byte *random_data_ptr, Ulong random_len, ReturnValue *return_value=ThrowException) const
LowLevel(FunctionList *ptr)
bool C_VerifySignature(SessionHandle session, const Byte *data_ptr, Ulong data_len, ReturnValue *return_value=ThrowException)
bool C_EncryptMessageNext(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *plaintext_part_ptr, Ulong plaintext_part_len, Byte *ciphertext_ptr, Ulong *ciphertext_part_len_ptr, Flags flags, ReturnValue *return_value=ThrowException)
bool C_Sign(SessionHandle session, const Byte *data_ptr, Ulong data_len, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DecryptMessage(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *associated_data_ptr, Ulong associated_data_len, const Byte *ciphertext_ptr, Ulong ciphertext_len, Byte *plaintext_ptr, Ulong *plaintext_len_ptr, ReturnValue *return_value=ThrowException)
bool C_GetFunctionStatus(SessionHandle session, ReturnValue *return_value=ThrowException) const
bool C_AsyncGetID(SessionHandle session, const Utf8Char *function_name_ptr, Ulong *id_ptr, ReturnValue *return_value=ThrowException)
bool C_CloseSession(SessionHandle session, ReturnValue *return_value=ThrowException) const
const InterfaceWrapper & get_interface()
bool C_Initialize(const void *init_args, ReturnValue *return_value=ThrowException) const
bool C_Encrypt(SessionHandle session, const Byte *data_ptr, Ulong data_len, Byte *encrypted_data, Ulong *encrypted_data_len_ptr, ReturnValue *return_value=ThrowException) const
static bool C_GetInterfaceList(const Dynamically_Loaded_Library &pkcs11_module, Interface *interface_list_ptr, Ulong *count_ptr, ReturnValue *return_value=ThrowException)
bool C_LoginUser(SessionHandle session, UserType user_type, const Utf8Char *pin_ptr, Ulong pin_len, const Utf8Char *username_ptr, Ulong username_len, ReturnValue *return_value=ThrowException)
bool C_SignUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException) const
bool C_DecapsulateKey(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle private_key, Attribute *template_ptr, Ulong attribute_count, const Byte *ciphertext_ptr, Ulong ciphertext_len, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException)
bool C_GetInfo(Info *info_ptr, ReturnValue *return_value=ThrowException) const
bool C_GetMechanismList(SlotId slot_id, MechanismType *mechanism_list_ptr, Ulong *count_ptr, ReturnValue *return_value=ThrowException) const
bool C_WaitForSlotEvent(Flags flags, SlotId *slot_ptr, void *reserved, ReturnValue *return_value=ThrowException) const
bool C_MessageVerifyInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException)
bool C_GetSessionValidationFlags(SessionHandle session, Ulong type, Flags *flags_ptr, ReturnValue *return_value=ThrowException)
bool C_OpenSession(SlotId slot_id, Flags flags, void *application, Notify notify, SessionHandle *session_ptr, ReturnValue *return_value=ThrowException) const
bool C_FindObjectsFinal(SessionHandle session, ReturnValue *return_value=ThrowException) const
static bool handle_return_value(CK_RV function_result, ReturnValue *return_value)
bool C_Decrypt(SessionHandle session, const Byte *encrypted_data_ptr, Ulong encrypted_data_len, Byte *data_ptr, Ulong *data_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DigestInit(SessionHandle session, const Mechanism *mechanism_ptr, ReturnValue *return_value=ThrowException) const
bool C_VerifySignatureFinal(SessionHandle session, ReturnValue *return_value=ThrowException)
bool C_AsyncComplete(SessionHandle session, const Utf8Char *function_name_ptr, AsyncData *result_ptr, ReturnValue *return_value=ThrowException)
bool C_DecryptInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_MessageSignInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException)
bool C_SessionCancel(SessionHandle session, Flags flags, ReturnValue *return_value=ThrowException)
bool C_CloseAllSessions(SlotId slot_id, ReturnValue *return_value=ThrowException) const
bool C_AsyncJoin(SessionHandle session, const Utf8Char *function_name_ptr, Ulong id, Byte *data_ptr, Ulong data_len, ReturnValue *return_value=ThrowException)
bool C_SeedRandom(SessionHandle session, const Byte *seed_ptr, Ulong seed_len, ReturnValue *return_value=ThrowException) const
bool C_CreateObject(SessionHandle session, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *object_ptr, ReturnValue *return_value=ThrowException) const
static bool C_GetInterface(const Dynamically_Loaded_Library &pkcs11_module, const Utf8Char *interface_name_ptr, const Version *version_ptr, Interface *interface_ptr_ptr, Flags flags, ReturnValue *return_value=ThrowException)
bool C_Finalize(void *reserved, ReturnValue *return_value=ThrowException) const
bool C_SignMessageNext(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *data_ptr, Ulong data_len, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException)
bool C_FindObjects(SessionHandle session, ObjectHandle *object_ptr, Ulong max_object_count, Ulong *object_count_ptr, ReturnValue *return_value=ThrowException) const
bool C_GenerateKeyPair(SessionHandle session, const Mechanism *mechanism_ptr, Attribute *public_key_template_ptr, Ulong public_key_attribute_count, Attribute *private_key_template_ptr, Ulong private_key_attribute_count, ObjectHandle *public_key_ptr, ObjectHandle *private_key_ptr, ReturnValue *return_value=ThrowException) const
bool C_UnwrapKeyAuthenticated(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle unwrapping_key, const Byte *wrapped_key_ptr, Ulong wrapped_key_len, Attribute *attribute_template_ptr, Ulong attribute_count, const Byte *associated_data_ptr, Ulong associated_data_len, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
bool C_VerifyInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_GetSlotList(Bbool token_present, SlotId *slot_list_ptr, Ulong *count_ptr, ReturnValue *return_value=ThrowException) const
bool C_GetMechanismInfo(SlotId slot_id, MechanismType type, MechanismInfo *info_ptr, ReturnValue *return_value=ThrowException) const
bool C_DigestEncryptUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, Byte *encrypted_part_ptr, Ulong *encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DecryptMessageNext(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *ciphertext_part_ptr, Ulong ciphertext_part_len, Byte *plaintext_ptr, Ulong *plaintext_part_len_ptr, Flags flags, ReturnValue *return_value=ThrowException)
bool C_SignMessage(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *data_ptr, Ulong data_len, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException)
bool C_SetPIN(SessionHandle session, const Utf8Char *old_pin_ptr, Ulong old_len, const Utf8Char *new_pin_ptr, Ulong new_len, ReturnValue *return_value=ThrowException) const
bool C_VerifyFinal(SessionHandle session, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException) const
bool C_Digest(SessionHandle session, const Byte *data_ptr, Ulong data_len, Byte *digest_ptr, Ulong *digest_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_MessageVerifyFinal(SessionHandle session, ReturnValue *return_value=ThrowException)
FunctionList * get_functions() const
bool C_UnwrapKey(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle unwrapping_key, const Byte *wrapped_key_ptr, Ulong wrapped_key_len, Attribute *attribute_template_ptr, Ulong attribute_count, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
bool C_VerifySignatureUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException)
bool C_EncryptInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_WrapKeyAuthenticated(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle wrapping_key, ObjectHandle key, const Byte *associated_data_ptr, Ulong associated_data_len, Byte *wrapped_key_ptr, Ulong *wrapped_key_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_SignFinal(SessionHandle session, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_SignMessageBegin(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, ReturnValue *return_value=ThrowException)
bool C_MessageEncryptInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException)
bool C_VerifyRecoverInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_DigestUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException) const
bool C_SignInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_DigestFinal(SessionHandle session, Byte *digest_ptr, Ulong *digest_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_Verify(SessionHandle session, const Byte *data_ptr, Ulong data_len, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException) const
bool C_GetObjectSize(SessionHandle session, ObjectHandle object, Ulong *size_ptr, ReturnValue *return_value=ThrowException) const
bool C_SetOperationState(SessionHandle session, const Byte *operation_state_ptr, Ulong operation_state_len, ObjectHandle encryption_key, ObjectHandle authentication_key, ReturnValue *return_value=ThrowException) const
bool C_GenerateKey(SessionHandle session, const Mechanism *mechanism_ptr, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
bool C_EncryptUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, Byte *encrypted_part_ptr, Ulong *encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DecryptMessageBegin(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *associated_data_ptr, Ulong associated_data_len, ReturnValue *return_value=ThrowException)
bool C_DecryptDigestUpdate(SessionHandle session, const Byte *encrypted_part_ptr, Ulong encrypted_part_len, Byte *part_ptr, Ulong *part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_SignRecoverInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_DecryptVerifyUpdate(SessionHandle session, const Byte *encrypted_part_ptr, Ulong encrypted_part_len, Byte *part_ptr, Ulong *part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DeriveKey(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle base_key, Attribute *attribute_template_ptr, Ulong attribute_count, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
Represents a PKCS#11 session.
void set_pin(const secure_string &old_pin, const secure_string &new_pin)
Calls C_SetPIN to change the PIN using the old PIN (requires a logged in session).
void init_pin(const secure_string &new_pin)
Calls C_InitPIN to change or initialize the PIN using the SO_PIN (requires a logged in session).
void login(UserType userType, const secure_string &pin)
Represents a PKCS#11 Slot, i.e., a card reader.
void initialize(std::string_view label, const secure_string &so_pin) const
ReturnValue * ThrowException
secure_vector< uint8_t > secure_string
CK_FUNCTION_LIST FunctionList
void change_pin(Slot &slot, const secure_string &old_pin, const secure_string &new_pin)
CK_OBJECT_HANDLE ObjectHandle
void change_so_pin(Slot &slot, const secure_string &old_so_pin, const secure_string &new_so_pin)
CK_SESSION_INFO SessionInfo
void set_pin(Slot &slot, const secure_string &so_pin, const secure_string &pin)
CK_MECHANISM_INFO MechanismInfo
void initialize_token(Slot &slot, std::string_view label, const secure_string &so_pin, const secure_string &pin)
CK_SESSION_HANDLE SessionHandle
#define CKR_GENERAL_ERROR
CK_MECHANISM_TYPE * CK_MECHANISM_TYPE_PTR
CK_ULONG CK_MECHANISM_TYPE