'openssl list' and 'openssl provider': adapt display of multiple names
[openssl.git] / apps / provider.c
index ab91e68f431b745f36161267bfafe10fb1992e85..325a7424cd73802430b2abb3adfcfc08d5d38738 100644 (file)
@@ -12,6 +12,7 @@
 #include "apps.h"
 #include "app_params.h"
 #include "progs.h"
+#include "names.h"
 #include <openssl/err.h>
 #include <openssl/evp.h>
 #include <openssl/safestack.h>
@@ -40,7 +41,7 @@ typedef struct info_st INFO;
 typedef struct meta_st META;
 
 struct info_st {
-    const char *name;
+    void (*collect_names_fn)(void *method, STACK_OF(OPENSSL_CSTRING) *names);
     void *method;
     const OSSL_PARAM *gettable_params;
     const OSSL_PARAM *gettable_ctx_params;
@@ -58,11 +59,58 @@ struct meta_st {
     void (*fn)(META *meta, INFO *info);
 };
 
+static void collect_cipher_names(void *method,
+                                 STACK_OF(OPENSSL_CSTRING) *names)
+{
+    EVP_CIPHER_names_do_all(method, collect_names, names);
+}
+
+static void collect_digest_names(void *method,
+                                 STACK_OF(OPENSSL_CSTRING) *names)
+{
+    EVP_MD_names_do_all(method, collect_names, names);
+}
+
+static void collect_mac_names(void *method,
+                              STACK_OF(OPENSSL_CSTRING) *names)
+{
+    EVP_MAC_names_do_all(method, collect_names, names);
+}
+
+static void collect_keymgmt_names(void *method,
+                                  STACK_OF(OPENSSL_CSTRING) *names)
+{
+    EVP_KEYMGMT_names_do_all(method, collect_names, names);
+}
+
+static void collect_keyexch_names(void *method,
+                                  STACK_OF(OPENSSL_CSTRING) *names)
+{
+    EVP_KEYEXCH_names_do_all(method, collect_names, names);
+}
+
+static void collect_signature_names(void *method,
+                                  STACK_OF(OPENSSL_CSTRING) *names)
+{
+    EVP_SIGNATURE_names_do_all(method, collect_names, names);
+}
+
+static void print_method_names(BIO *out, INFO *info)
+{
+    STACK_OF(OPENSSL_CSTRING) *names = sk_OPENSSL_CSTRING_new(name_cmp);
+
+    info->collect_names_fn(info->method, names);
+    print_names(out, names);
+    sk_OPENSSL_CSTRING_free(names);
+}
+
 static void print_caps(META *meta, INFO *info)
 {
     switch (meta->verbose) {
     case 1:
-        BIO_printf(bio_out, meta->first ? "%s" : " %s", info->name);
+        if (!meta->first)
+            BIO_printf(bio_out, "; ");
+        print_method_names(bio_out, info);
         break;
     case 2:
         if (meta->first) {
@@ -70,12 +118,14 @@ static void print_caps(META *meta, INFO *info)
                 BIO_printf(bio_out, "\n");
             BIO_printf(bio_out, "%*s%ss:", meta->indent, "", meta->label);
         }
-        BIO_printf(bio_out, " %s", info->name);
+        BIO_printf(bio_out, " ");
+        print_method_names(bio_out, info);
         break;
     case 3:
     default:
-        BIO_printf(bio_out, "%*s%s %s\n", meta->indent, "", meta->label,
-                   info->name);
+        BIO_printf(bio_out, "%*s%s ", meta->indent, "", meta->label);
+        print_method_names(bio_out, info);
+        BIO_printf(bio_out, "\n");
         print_param_types("retrievable algorithm parameters",
                           info->gettable_params, meta->subindent);
         print_param_types("retrievable operation parameters",
@@ -87,7 +137,9 @@ static void print_caps(META *meta, INFO *info)
     meta->first = 0;
 }
 
-static void do_method(void *method, const char *name,
+static void do_method(void *method,
+                      void (*collect_names_fn)(void *method,
+                                               STACK_OF(OPENSSL_CSTRING) *names),
                       const OSSL_PARAM *gettable_params,
                       const OSSL_PARAM *gettable_ctx_params,
                       const OSSL_PARAM *settable_ctx_params,
@@ -95,7 +147,7 @@ static void do_method(void *method, const char *name,
 {
     INFO info;
 
-    info.name = name;
+    info.collect_names_fn = collect_names_fn;
     info.method = method;
     info.gettable_params = gettable_params;
     info.gettable_ctx_params = gettable_ctx_params;
@@ -106,7 +158,7 @@ static void do_method(void *method, const char *name,
 
 static void do_cipher(EVP_CIPHER *cipher, void *meta)
 {
-    do_method(cipher, EVP_CIPHER_name(cipher),
+    do_method(cipher, collect_cipher_names,
               EVP_CIPHER_gettable_params(cipher),
               EVP_CIPHER_gettable_ctx_params(cipher),
               EVP_CIPHER_settable_ctx_params(cipher),
@@ -115,7 +167,7 @@ static void do_cipher(EVP_CIPHER *cipher, void *meta)
 
 static void do_digest(EVP_MD *digest, void *meta)
 {
-    do_method(digest, EVP_MD_name(digest),
+    do_method(digest, collect_digest_names,
               EVP_MD_gettable_params(digest),
               EVP_MD_gettable_ctx_params(digest),
               EVP_MD_settable_ctx_params(digest),
@@ -124,35 +176,60 @@ static void do_digest(EVP_MD *digest, void *meta)
 
 static void do_mac(EVP_MAC *mac, void *meta)
 {
-    do_method(mac, EVP_MAC_name(mac),
+    do_method(mac, collect_mac_names,
               EVP_MAC_gettable_params(mac),
               EVP_MAC_gettable_ctx_params(mac),
               EVP_MAC_settable_ctx_params(mac),
               meta);
 }
 
+static void do_keymgmt(EVP_KEYMGMT *keymgmt, void *meta)
+{
+    do_method(keymgmt, collect_keymgmt_names,
 /*
  * TODO(3.0) Enable when KEYMGMT and KEYEXCH have gettables and settables
  */
 #if 0
-static void do_keymgmt(EVP_KEYMGMT *keymgmt, void *meta)
-{
-    do_method(keymgmt, EVP_KEYMGMT_name(keymgmt),
               EVP_KEYMGMT_gettable_params(keymgmt),
               EVP_KEYMGMT_gettable_ctx_params(keymgmt),
               EVP_KEYMGMT_settable_ctx_params(keymgmt),
+#else
+              NULL, NULL, NULL,
+#endif
               meta);
 }
 
 static void do_keyexch(EVP_KEYEXCH *keyexch, void *meta)
 {
-    do_method(keyexch, EVP_KEYEXCH_name(keyexch),
+    do_method(keyexch, collect_keyexch_names,
+/*
+ * TODO(3.0) Enable when KEYMGMT and KEYEXCH have gettables and settables
+ */
+#if 0
               EVP_KEYEXCH_gettable_params(keyexch),
               EVP_KEYEXCH_gettable_ctx_params(keyexch),
               EVP_KEYEXCH_settable_ctx_params(keyexch),
+#else
+              NULL, NULL, NULL,
+#endif
               meta);
 }
+
+static void do_signature(EVP_SIGNATURE *signature, void *meta)
+{
+    do_method(signature, collect_signature_names,
+/*
+ * TODO(3.0) Enable when KEYMGMT and SIGNATURE have gettables and settables
+ */
+#if 0
+              EVP_SIGNATURE_gettable_params(signature),
+              EVP_SIGNATURE_gettable_ctx_params(signature),
+              EVP_SIGNATURE_settable_ctx_params(signature),
+#else
+              NULL, NULL, NULL,
 #endif
+              meta);
+}
 
 int provider_main(int argc, char **argv)
 {
@@ -231,33 +308,33 @@ int provider_main(int argc, char **argv)
                     data.first = 1;
                     data.label = "Cipher";
                 }
-                EVP_CIPHER_do_all_ex(NULL, do_cipher, &data);
+                EVP_CIPHER_do_all_provided(NULL, do_cipher, &data);
                 if (verbose > 1) {
                     data.first = 1;
                     data.label = "Digest";
                 }
-                EVP_MD_do_all_ex(NULL, do_digest, &data);
+                EVP_MD_do_all_provided(NULL, do_digest, &data);
                 if (verbose > 1) {
                     data.first = 1;
                     data.label = "MAC";
                 }
-                EVP_MAC_do_all_ex(NULL, do_mac, &data);
+                EVP_MAC_do_all_provided(NULL, do_mac, &data);
 
-/*
- * TODO(3.0) Enable when KEYMGMT and KEYEXCH have do_all_ex functions
- */
-#if 0
                 if (verbose > 1) {
                     data.first = 1;
                     data.label = "Key manager";
                 }
-                EVP_KEYMGMT_do_all_ex(NULL, do_keymgmt, &data);
+                EVP_KEYMGMT_do_all_provided(NULL, do_keymgmt, &data);
                 if (verbose > 1) {
                     data.first = 1;
                     data.label = "Key exchange";
                 }
-                EVP_KEYEXCH_do_all_ex(NULL, do_keyexch, &data);
-#endif
+                EVP_KEYEXCH_do_all_provided(NULL, do_keyexch, &data);
+                if (verbose > 1) {
+                    data.first = 1;
+                    data.label = "Signature";
+                }
+                EVP_SIGNATURE_do_all_provided(NULL, do_signature, &data);
 
                 switch (verbose) {
                 default: