1 /* ****************************************************************************
2
3 * eID Middleware Project.
4 * Copyright (C) 2014 FedICT.
5 *
6 * This is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version
8 * 3.0 as published by the Free Software Foundation.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this software; if not, see
17 * http://www.gnu.org/licenses/.
18
19 **************************************************************************** */
20 #ifdef WIN32
21 #include <win32.h>
22 #pragma pack(push, cryptoki, 1)
23 #include "pkcs11.h"
24 #pragma pack(pop, cryptoki)
25 #else
26 #include <unix.h>
27 #include <pkcs11.h>
28 #endif
29 #include <stdio.h>
30
31 #include "testlib.h"
32
TEST_FUNC(slotinfo)33 TEST_FUNC(slotinfo) {
34 CK_SLOT_ID slot = 0;
35 CK_SLOT_INFO info;
36 int ret;
37
38 check_rv_long(C_GetSlotInfo(slot, &info), m_p11_noinit);
39
40 check_rv(C_Initialize(NULL_PTR));
41
42 check_rv_long(C_GetSlotInfo(slot, NULL_PTR), m_p11_badarg);
43
44 if((ret = find_slot(CK_TRUE, &slot)) != TEST_RV_OK) {
45 check_rv(C_Finalize(NULL_PTR));
46 return ret;
47 }
48
49 check_rv_long(C_GetSlotInfo(slot+30, &info), m_p11_badslot);
50 check_rv(C_GetSlotInfo(slot, &info));
51
52 verify_null(info.slotDescription, 64, 0, "Slot description:\t'%s'\n");
53 verify_null(info.manufacturerID, 32, 0, "Manufacturer ID:\t'%s'\n");
54
55 printf("Hardware version: %d.%d\n", info.hardwareVersion.major, info.hardwareVersion.minor);
56 printf("Firmware version: %d.%d\n", info.hardwareVersion.major, info.hardwareVersion.minor);
57 printf("Token present: %c; Removable: %c; Hardware slot: %c\n", info.flags & CKF_TOKEN_PRESENT ? 'y' : 'n', info.flags & CKF_REMOVABLE_DEVICE ? 'y' : 'n', info.flags & CKF_HW_SLOT ? 'y' : 'n');
58
59 check_rv(C_Finalize(NULL_PTR));
60
61 return TEST_RV_OK;
62 }
63