xref: /freebsd/crypto/openssl/apps/lib/names.c (revision e7be843b4a162e68651d3911f0357ed464915629)
1 /*
2  * Copyright 2019-2025 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #include <string.h>
11 #include <openssl/bio.h>
12 #include <openssl/safestack.h>
13 #include "names.h"
14 #include "internal/e_os.h"
15 
name_cmp(const char * const * a,const char * const * b)16 int name_cmp(const char * const *a, const char * const *b)
17 {
18     return OPENSSL_strcasecmp(*a, *b);
19 }
20 
collect_names(const char * name,void * vdata)21 void collect_names(const char *name, void *vdata)
22 {
23     STACK_OF(OPENSSL_CSTRING) *names = vdata;
24 
25     /* A failure to push cannot be handled so we ignore the result. */
26     (void)sk_OPENSSL_CSTRING_push(names, name);
27 }
28 
print_names(BIO * out,STACK_OF (OPENSSL_CSTRING)* names)29 void print_names(BIO *out, STACK_OF(OPENSSL_CSTRING) *names)
30 {
31     int i = sk_OPENSSL_CSTRING_num(names);
32     int j;
33 
34     sk_OPENSSL_CSTRING_sort(names);
35     if (i > 1)
36         BIO_printf(out, "{ ");
37     for (j = 0; j < i; j++) {
38         const char *name = sk_OPENSSL_CSTRING_value(names, j);
39 
40         if (j > 0)
41             BIO_printf(out, ", ");
42         BIO_printf(out, "%s", name);
43     }
44     if (i > 1)
45         BIO_printf(out, " }");
46 }
47