1 /* 2 * Copyright (c) 2018-2021 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 9 void fido_str_array_free(fido_str_array_t * sa)10fido_str_array_free(fido_str_array_t *sa) 11 { 12 for (size_t i = 0; i < sa->len; i++) 13 free(sa->ptr[i]); 14 15 free(sa->ptr); 16 sa->ptr = NULL; 17 sa->len = 0; 18 } 19 20 void fido_opt_array_free(fido_opt_array_t * oa)21fido_opt_array_free(fido_opt_array_t *oa) 22 { 23 for (size_t i = 0; i < oa->len; i++) 24 free(oa->name[i]); 25 26 free(oa->name); 27 free(oa->value); 28 oa->name = NULL; 29 oa->value = NULL; 30 } 31 32 void fido_byte_array_free(fido_byte_array_t * ba)33fido_byte_array_free(fido_byte_array_t *ba) 34 { 35 free(ba->ptr); 36 37 ba->ptr = NULL; 38 ba->len = 0; 39 } 40 41 void fido_algo_free(fido_algo_t * a)42fido_algo_free(fido_algo_t *a) 43 { 44 free(a->type); 45 a->type = NULL; 46 a->cose = 0; 47 } 48 49 void fido_algo_array_free(fido_algo_array_t * aa)50fido_algo_array_free(fido_algo_array_t *aa) 51 { 52 for (size_t i = 0; i < aa->len; i++) 53 fido_algo_free(&aa->ptr[i]); 54 55 free(aa->ptr); 56 aa->ptr = NULL; 57 aa->len = 0; 58 } 59 60 int fido_str_array_pack(fido_str_array_t * sa,const char * const * v,size_t n)61fido_str_array_pack(fido_str_array_t *sa, const char * const *v, size_t n) 62 { 63 if ((sa->ptr = calloc(n, sizeof(char *))) == NULL) { 64 fido_log_debug("%s: calloc", __func__); 65 return -1; 66 } 67 for (size_t i = 0; i < n; i++) { 68 if ((sa->ptr[i] = strdup(v[i])) == NULL) { 69 fido_log_debug("%s: strdup", __func__); 70 return -1; 71 } 72 sa->len++; 73 } 74 75 return 0; 76 } 77