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