// testinit.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "initToken.h"
//#include "Import.h"
#include <windows.h>
#include <string>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
//	unsigned long dwPublicSize = 0;
//	unsigned long dwPrivateSize = 0;
//	string strPublic;
//	string strPrivate;
	string strTokenName;
	string strSoPIN;
	string strUserPIN;

//	cout << endl << "Input the size of public data area (in byte, normally 4000) : ";
//	cin >> strPublic;
//	cout << endl << "Input the size of private data area (in byte, normally 2700) : ";
//	cin >> strPrivate;
	cout << endl << "Input the token friendly name : ";
	cin >> strTokenName;
	cout << endl << "Input the user PIN you want to set : ";
	cin >> strUserPIN;
	cout << endl << "Input your SO PIN : ";
	cin >> strSoPIN;

//	sscanf(strPublic.c_str(), "%d", &dwPublicSize);
//	sscanf(strPrivate.c_str(), "%d", &dwPrivateSize);

//	if(0 == dwPublicSize || 0 == dwPrivateSize)
//	{
//		cout << endl << "Can't initialize, check your input please." << endl;
//		return -1;
//	}

//	cout << "Result :" << endl;
//	cout << "Public : " << dwPublicSize << endl;
//	cout << "Private : " << dwPrivateSize << endl;

	unsigned long dwRet = 0;
	dwRet = eps1k_Initialize(
		(char*)strSoPIN.c_str(),
		NULL,	// I do not want change the SO PIN.
		(char*)strUserPIN.c_str(),
//		dwPublicSize,
//		dwPrivateSize,
		(char*)strTokenName.c_str()
		);

	if(0 == dwRet)
	{
		cout << endl << "ePass1000 initialized !" << endl;
//		return 0;
	}
	else
	{
		cout << endl << "ePass1000 initialize failed. Error code is " << dwRet << endl;
		return -2;
	}

//	char *path = "cert.p12";
//	char* password = "Qz7B8ntbiemK"; 
//	int rv;
//	char* userpin = "1234";
//	rv = ImportCerts(path, password, userpin);
//	printf("\nrv = %d\n", rv);
//	
//	char* path2 = "yubozeng.pfx";
//	char* password2 = "b1cee174"; 
//	rv = ImportCerts(path2, password2, userpin);
//	printf("\nrv = %d\n", rv);

	return 0;
}
