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