<commit_before>#include <assert.h>
#include <cryptoki.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>

// Slots
#define SLOT_INVALID 9999
#define SLOT_INIT_TOKEN 0
#define SLOT_NO_INIT_TOKEN 1

// PIN
#define SLOT_0_SO1_PIN "123456"
#define SLOT_0_SO2_PIN "123456"
#define SLOT_0_USER1_PIN "123456"
#define SLOT_0_USER2_PIN "123456"

int main ( int argc, const char* argv[] )
{
	printf("Hello World\n");

	//for( int i = 0; i < argc; i++ )
	//{
	//	printf( "arg %d: %s\n", i, argv[i] );
	//}

	void* sym = dlopen("/usr/lib64/libsofthsm2.so", RTLD_LAZY);
	assert(sym != 0);
	CK_C_GetFunctionList gfl = (CK_C_GetFunctionList) dlsym(sym, "C_GetFunctionList");

	CK_RV rv;
	CK_UTF8CHAR pin[] = SLOT_0_USER1_PIN;
	CK_ULONG pinLength = sizeof(pin) - 1;
	CK_UTF8CHAR sopin[] = SLOT_0_SO1_PIN;
	CK_ULONG sopinLength = sizeof(sopin) - 1;
	CK_SESSION_HANDLE hSession;

	CK_UTF8CHAR label[32];
	memset(label, ' ', 32);
	memcpy(label, "token1", strlen("token1"));

	//TODO: Carregar o C_GetFunctionList via Libdl,
	//usar funcoes carregadas a partir dele.
	CK_FUNCTION_LIST_PTR flp = 0;
	rv = gfl(&flp);

	printf("Ret value of GetListPtr (%d)\n", rv);

	CK_C_Initialize func = flp->C_Initialize;
	// (Re)initialize the token
	rv = (*func)(0);
	printf("Initializing (%d)\n", rv);
	
}<commit_msg>Using opensc instead of softhsm, no luck /<commit_after>#include <assert.h>
#include <cryptoki.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>

// Slots
#define SLOT_INVALID 9999
#define SLOT_INIT_TOKEN 0
#define SLOT_NO_INIT_TOKEN 1

// PIN
#define SLOT_0_SO1_PIN "123456"
#define SLOT_0_SO2_PIN "123456"
#define SLOT_0_USER1_PIN "123456"
#define SLOT_0_USER2_PIN "123456"

int main ( int argc, const char* argv[] )
{
	printf("Hello World\n");

	//for( int i = 0; i < argc; i++ )
	//{
	//	printf( "arg %d: %s\n", i, argv[i] );
	//}
	CK_RV rv;
	//CK_UTF8CHAR pin[] = SLOT_0_USER1_PIN;
	//CK_ULONG pinLength = sizeof(pin) - 1;
	//CK_UTF8CHAR sopin[] = SLOT_0_SO1_PIN;
	//CK_ULONG sopinLength = sizeof(sopin) - 1;
	//CK_SESSION_HANDLE hSession;

	//CK_UTF8CHAR label[32];
	//memset(label, ' ', 32);
	//memcpy(label, "token1", strlen("token1"));

	//void* sym = dlopen("/usr/lib64/libsofthsm2.so", RTLD_LAZY);
	

	void* sym = dlopen("/usr/lib64/opensc-pkcs11.so", RTLD_LAZY);
	assert(sym != 0);
	CK_C_GetFunctionList getFuncList = (CK_C_GetFunctionList) dlsym(sym, "C_GetFunctionList");


	//TODO: Carregar o C_GetFunctionList via Libdl,
	//usar funcoes carregadas a partir dele.
	CK_FUNCTION_LIST_PTR listPointer = 0;
	rv = getFuncList(&listPointer);
	assert(rv == 0);
	printf("getFuncList return: (%d)\n", rv);

	CK_C_Initialize init = listPointer->C_Initialize;
	// (Re)initialize the token
	rv = (*init)(NULL_PTR);
	printf("Initializing (%d)\n", rv);



	dlclose(sym);	
}
{'fraction_non_alphanumeric': 0.16170212765957448, 'fraction_numerical': 0.04397163120567376, 'mean_word_length': 4.597222222222222, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3893416', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1199, 'n_words': 266}