xref: /netbsd-src/external/bsd/libfido2/dist/examples/manifest.c (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*
2  * Copyright (c) 2018 Yubico AB. All rights reserved.
3  * Use of this source code is governed by a BSD-style
4  * license that can be found in the LICENSE file.
5  */
6 
7 #include <stdbool.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 
11 #include "fido.h"
12 #include "../openbsd-compat/openbsd-compat.h"
13 
14 int
15 main(void)
16 {
17 	fido_dev_info_t	*devlist;
18 	size_t		 ndevs;
19 	int		 r;
20 
21 	fido_init(0);
22 
23 	if ((devlist = fido_dev_info_new(64)) == NULL)
24 		errx(1, "fido_dev_info_new");
25 
26 	if ((r = fido_dev_info_manifest(devlist, 64, &ndevs)) != FIDO_OK)
27 		errx(1, "fido_dev_info_manifest: %s (0x%x)", fido_strerr(r), r);
28 
29 	for (size_t i = 0; i < ndevs; i++) {
30 		const fido_dev_info_t *di = fido_dev_info_ptr(devlist, i);
31 		printf("%s: vendor=0x%04x, product=0x%04x (%s %s)\n",
32 		    fido_dev_info_path(di),
33 		    (uint16_t)fido_dev_info_vendor(di),
34 		    (uint16_t)fido_dev_info_product(di),
35 		    fido_dev_info_manufacturer_string(di),
36 		    fido_dev_info_product_string(di));
37 	}
38 
39 	fido_dev_info_free(&devlist, ndevs);
40 
41 	exit(0);
42 }
43