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 <string.h> 8 #include "fido.h" 9 10 fido_dev_info_t * 11 fido_dev_info_new(size_t n) 12 { 13 return (calloc(n, sizeof(fido_dev_info_t))); 14 } 15 16 void 17 fido_dev_info_free(fido_dev_info_t **devlist_p, size_t n) 18 { 19 fido_dev_info_t *devlist; 20 21 if (devlist_p == NULL || (devlist = *devlist_p) == NULL) 22 return; 23 24 for (size_t i = 0; i < n; i++) { 25 const fido_dev_info_t *di = &devlist[i]; 26 free(di->path); 27 free(di->manufacturer); 28 free(di->product); 29 } 30 31 free(devlist); 32 33 *devlist_p = NULL; 34 } 35 36 const fido_dev_info_t * 37 fido_dev_info_ptr(const fido_dev_info_t *devlist, size_t i) 38 { 39 return (&devlist[i]); 40 } 41 42 const char * 43 fido_dev_info_path(const fido_dev_info_t *di) 44 { 45 return (di->path); 46 } 47 48 int16_t 49 fido_dev_info_vendor(const fido_dev_info_t *di) 50 { 51 return (di->vendor_id); 52 } 53 54 int16_t 55 fido_dev_info_product(const fido_dev_info_t *di) 56 { 57 return (di->product_id); 58 } 59 60 const char * 61 fido_dev_info_manufacturer_string(const fido_dev_info_t *di) 62 { 63 return (di->manufacturer); 64 } 65 66 const char * 67 fido_dev_info_product_string(const fido_dev_info_t *di) 68 { 69 return (di->product); 70 } 71