forked from jbteam/libemv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.c
70 lines (57 loc) · 1.62 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "include/libemv.h"
#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
static void init_functions(void);
static void get_transaction_date_YYMMDD(char* strdate);
static void get_transaction_time_HHmmss(char* strtime);
// This function can cause problems in custom platforms
static void init_functions(void)
{
libemv_ext_apdu = 0;
libemv_malloc = malloc;
libemv_realloc = realloc;
libemv_free = free;
libemv_get_date = get_transaction_date_YYMMDD;
libemv_get_time = get_transaction_time_HHmmss;
libemv_rand = rand;
libemv_printf = printf;
}
// This function can cause problems in custom platforms
static void get_transaction_date_YYMMDD(char* strdate)
{
time_t rawtime;
time(&rawtime);
strftime(strdate, 6, "%y%m%d", localtime(&rawtime));
}
// This function can cause problems in custom platforms
static void get_transaction_time_HHmmss(char* strtime)
{
time_t rawtime;
time(&rawtime);
strftime(strtime, 6, "%H%M%S", localtime(&rawtime));
}
LIBEMV_API void libemv_init(void)
{
init_functions();
libemv_debug_enabled = 0;
libemv_init_tlv_buffer();
// Settings
memset(&libemv_settings, 0, sizeof(libemv_settings));
memset(&libemv_global, 0, sizeof(libemv_global));
libemv_applications_count = 0;
libemv_applications = 0;
libemv_settings.appSelectionUsePSE = 1;
libemv_settings.appSelectionSupportConfirm = 1;
libemv_settings.appSelectionPartial = 1;
libemv_settings.appSelectionSupport = 1;
}
LIBEMV_API void libemv_destroy(void)
{
if (libemv_debug_enabled)
libemv_printf("Destroy allocated data...\n");
libemv_destroy_tlv_buffer();
libemv_destroy_settings();
}