static int enum_pins(struct sc_pkcs15_object ***ret) { struct sc_pkcs15_object **objs; int i, n; n = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, NULL, 0); if (n < 0) { fprintf(stderr, "Error enumerating PIN codes: %s\n", sc_strerror(n)); return 1; } if (n == 0) { fprintf(stderr, "No PIN codes found!\n"); return 0; } objs = calloc(n, sizeof(*objs)); if (!objs) { fprintf(stderr, "Not enough memory!\n"); return 1; } if (0 > sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, n)) { fprintf(stderr, "Error enumerating PIN codes\n"); free(objs); return 1; } for (i = 0; i < n; i++) { sc_test_print_object(objs[i]); } *ret = objs; return n; }
static int dump_objects(const char *what, int type) { struct sc_pkcs15_object **objs; int count, i; printf("\nEnumerating %s... ", what); fflush(stdout); sc_lock(card); count = sc_pkcs15_get_objects(p15card, type, NULL, 0); if (count < 0) { printf("failed.\n"); fprintf(stderr, "Error enumerating %s: %s\n", what, sc_strerror(count)); sc_unlock(card); return 1; } if (count == 0) { printf("none found.\n"); sc_unlock(card); return 0; } printf("%u found.\n", count); objs = (struct sc_pkcs15_object **) calloc(count, sizeof(*objs)); if ((count = sc_pkcs15_get_objects(p15card, type, objs, count)) < 0) { fprintf(stderr, "Error enumerating %s: %s\n", what, sc_strerror(count)); } else { for (i = 0; i < count; i++) sc_test_print_object(objs[i]); } free(objs); sc_unlock(card); return (count < 0) ? 1 : 0; }