+struct collected_encoder_st {
+ const char *output_type;
+ STACK_OF(OSSL_ENCODER) *encoders;
+ int error_occured;
+};
+
+static void collect_encoder(OSSL_ENCODER *encoder, void *arg)
+{
+ struct collected_encoder_st *data = arg;
+ OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
+ const char *output_type = NULL;
+
+ if (data->error_occured)
+ return;
+
+ /*
+ * Ask for the output type. If the encoder doesn't answer to that,
+ * we refuse it.
+ */
+ params[0] =
+ OSSL_PARAM_construct_utf8_ptr(OSSL_ENCODER_PARAM_OUTPUT_TYPE,
+ (char **)&output_type, 0);
+ if (!encoder->get_params(params)
+ || !OSSL_PARAM_modified(¶ms[0])
+ || output_type == NULL
+ || strcasecmp(output_type, data->output_type) != 0)
+ return;
+
+ data->error_occured = 1; /* Assume the worst */
+
+ if (!OSSL_ENCODER_up_ref(encoder) /* ref++ */)
+ return;
+ if (sk_OSSL_ENCODER_push(data->encoders, encoder) <= 0) {
+ OSSL_ENCODER_free(encoder); /* ref-- */
+ return;
+ }
+
+ data->error_occured = 0; /* All is good now */
+}
+
+struct collected_names_st {