xref: /freebsd/contrib/libfido2/examples/manifest.c (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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  * SPDX-License-Identifier: BSD-2-Clause
6  */
7 
8 #include <fido.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 
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