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