2 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "app_params.h"
13 static int describe_param_type(char *buf
, size_t bufsz
, const OSSL_PARAM
*param
)
15 const char *type_mod
= "";
16 const char *type
= NULL
;
17 int show_type_number
= 0;
20 switch (param
->data_type
) {
21 case OSSL_PARAM_UNSIGNED_INTEGER
:
22 type_mod
= "unsigned ";
24 case OSSL_PARAM_INTEGER
:
27 case OSSL_PARAM_UTF8_PTR
:
28 type_mod
= "pointer to a ";
30 case OSSL_PARAM_UTF8_STRING
:
31 type
= "UTF8 encoded string";
33 case OSSL_PARAM_OCTET_PTR
:
34 type_mod
= "pointer to an ";
36 case OSSL_PARAM_OCTET_STRING
:
37 type
= "octet string";
40 type
= "unknown type";
45 printed_len
= BIO_snprintf(buf
, bufsz
, "%s: ", param
->key
);
46 if (printed_len
> 0) {
50 printed_len
= BIO_snprintf(buf
, bufsz
, "%s%s", type_mod
, type
);
51 if (printed_len
> 0) {
55 if (show_type_number
) {
56 printed_len
= BIO_snprintf(buf
, bufsz
, " [%d]", param
->data_type
);
57 if (printed_len
> 0) {
62 if (param
->data_size
== 0)
63 printed_len
= BIO_snprintf(buf
, bufsz
, " (arbitrary size)");
65 printed_len
= BIO_snprintf(buf
, bufsz
, " (max %zu bytes large)",
67 if (printed_len
> 0) {
75 int print_param_types(const char *thing
, const OSSL_PARAM
*pdefs
, int indent
)
79 } else if (pdefs
->key
== NULL
) {
81 * An empty list? This shouldn't happen, but let's just make sure to
82 * say something if there's a badly written provider...
84 BIO_printf(bio_out
, "%*sEmpty list of %s (!!!)\n", indent
, "", thing
);
86 BIO_printf(bio_out
, "%*s%s:\n", indent
, "", thing
);
87 for (; pdefs
->key
!= NULL
; pdefs
++) {
88 char buf
[200]; /* This should be ample space */
90 describe_param_type(buf
, sizeof(buf
), pdefs
);
91 BIO_printf(bio_out
, "%*s %s\n", indent
, "", buf
);
97 void print_param_value(const OSSL_PARAM
*p
, int indent
)
102 printf("%*s%s: ", indent
, "", p
->key
);
103 switch (p
->data_type
) {
104 case OSSL_PARAM_UNSIGNED_INTEGER
:
105 if (OSSL_PARAM_get_uint64(p
, &u
))
106 BIO_printf(bio_out
, "%llu\n", (unsigned long long int)u
);
108 BIO_printf(bio_out
, "error getting value\n");
110 case OSSL_PARAM_INTEGER
:
111 if (OSSL_PARAM_get_int64(p
, &i
))
112 BIO_printf(bio_out
, "%lld\n", (long long int)i
);
114 BIO_printf(bio_out
, "error getting value\n");
116 case OSSL_PARAM_UTF8_PTR
:
117 BIO_printf(bio_out
, "'%s'\n", *(char **)(p
->data
));
119 case OSSL_PARAM_UTF8_STRING
:
120 BIO_printf(bio_out
, "'%s'\n", (char *)p
->data
);
122 case OSSL_PARAM_OCTET_PTR
:
123 case OSSL_PARAM_OCTET_STRING
:
124 BIO_printf(bio_out
, "<%zu bytes>\n", p
->data_size
);
127 BIO_printf(bio_out
, "unknown type (%u) of %zu bytes\n",
128 p
->data_type
, p
->data_size
);