xref: /freebsd/contrib/libfido2/examples/manifest.c (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
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 <fido.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 
11 #include "../openbsd-compat/openbsd-compat.h"
12 
13 int
14 main(void)
15 {
16 	fido_dev_info_t	*devlist;
17 	size_t		 ndevs;
18 	int		 r;
19 
20 	fido_init(0);
21 
22 	if ((devlist = fido_dev_info_new(64)) == NULL)
23 		errx(1, "fido_dev_info_new");
24 
25 	if ((r = fido_dev_info_manifest(devlist, 64, &ndevs)) != FIDO_OK)
26 		errx(1, "fido_dev_info_manifest: %s (0x%x)", fido_strerr(r), r);
27 
28 	for (size_t i = 0; i < ndevs; i++) {
29 		const fido_dev_info_t *di = fido_dev_info_ptr(devlist, i);
30 		printf("%s: vendor=0x%04x, product=0x%04x (%s %s)\n",
31 		    fido_dev_info_path(di),
32 		    (uint16_t)fido_dev_info_vendor(di),
33 		    (uint16_t)fido_dev_info_product(di),
34 		    fido_dev_info_manufacturer_string(di),
35 		    fido_dev_info_product_string(di));
36 	}
37 
38 	fido_dev_info_free(&devlist, ndevs);
39 
40 	exit(0);
41 }
42