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 71 72 73 74 75 76 77 78 79 80 81 82 83
|
/* t-getmechanismlist.c - Regression test.
* Copyright (C) 2006 g10 Code GmbH
*
* This file is part of Scute.
*
* Scute is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* Scute is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <https://gnu.org/licenses/>.
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <stdio.h>
#include <stdbool.h>
#include "t-support.h"
int
main (int argc, char *argv[])
{
CK_RV err;
CK_SLOT_ID_PTR slots;
CK_ULONG slots_count;
unsigned int i;
(void) argc;
(void) argv;
init_cryptoki ();
err = C_GetSlotList (true, NULL, &slots_count);
fail_if_err (err);
if (slots_count == 0)
{
printf ("Skipping test because no token is present.\n");
return 77;
}
printf ("Number of slots with tokens: %lu\n", slots_count);
slots = malloc (sizeof (CK_SLOT_ID) * slots_count);
if (!slots)
fail_if_err (CKR_HOST_MEMORY);
err = C_GetSlotList (true, slots, &slots_count);
fail_if_err (err);
for (i = 0; i < slots_count; i++)
{
CK_MECHANISM_TYPE_PTR mechanisms;
CK_ULONG mechanisms_count;
unsigned int j;
printf ("%2i. Slot ID %lu\n", i, slots[i]);
err = C_GetMechanismList (slots[i], NULL, &mechanisms_count);
fail_if_err (err);
printf (" Mechanisms: %lu\n", mechanisms_count);
mechanisms = malloc (sizeof (CK_MECHANISM_TYPE) * mechanisms_count);
if (!mechanisms)
fail_if_err (CKR_HOST_MEMORY);
err = C_GetMechanismList (slots[i], mechanisms, &mechanisms_count);
fail_if_err (err);
for (j = 0; j < mechanisms_count; j++)
printf (" %2i. %s\n", j, mechanism_type_str (mechanisms[j]));
free (mechanisms);
}
return 0;
}
|