summaryrefslogtreecommitdiffstats
path: root/apps/list.c
diff options
context:
space:
mode:
authorPauli <paul.dale@oracle.com>2020-07-27 14:47:59 +1000
committerPauli <paul.dale@oracle.com>2020-07-30 20:15:59 +1000
commita3f15e237c0325718f488ebf9a242c031f4f864e (patch)
treee7967fa597f7e7ba61ea7bd5d5de7541bcf709bf /apps/list.c
parentdfc0857d8191d43be320f4ba472b7c782248a35d (diff)
deserialisation: add deserialisation to the base provider
Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/12104)
Diffstat (limited to 'apps/list.c')
-rw-r--r--apps/list.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/apps/list.c b/apps/list.c
index 5b93f7dfed..69a516763c 100644
--- a/apps/list.c
+++ b/apps/list.c
@@ -17,6 +17,7 @@
#include <openssl/safestack.h>
#include <openssl/kdf.h>
#include <openssl/serializer.h>
+#include <openssl/deserializer.h>
#include <openssl/core_names.h>
#include "apps.h"
#include "app_params.h"
@@ -413,6 +414,67 @@ static void list_serializers(void)
sk_OSSL_SERIALIZER_pop_free(serializers, OSSL_SERIALIZER_free);
}
+/*
+ * Deserializers
+ */
+DEFINE_STACK_OF(OSSL_DESERIALIZER)
+static int deserializer_cmp(const OSSL_DESERIALIZER * const *a,
+ const OSSL_DESERIALIZER * const *b)
+{
+ int ret = OSSL_DESERIALIZER_number(*a) - OSSL_DESERIALIZER_number(*b);
+
+ if (ret == 0)
+ ret = strcmp(OSSL_PROVIDER_name(OSSL_DESERIALIZER_provider(*a)),
+ OSSL_PROVIDER_name(OSSL_DESERIALIZER_provider(*b)));
+ return ret;
+}
+
+static void collect_deserializers(OSSL_DESERIALIZER *deserializer, void *stack)
+{
+ STACK_OF(OSSL_DESERIALIZER) *deserializer_stack = stack;
+
+ sk_OSSL_DESERIALIZER_push(deserializer_stack, deserializer);
+ OSSL_DESERIALIZER_up_ref(deserializer);
+}
+
+static void list_deserializers(void)
+{
+ STACK_OF(OSSL_DESERIALIZER) *deserializers;
+ int i;
+
+ deserializers = sk_OSSL_DESERIALIZER_new(deserializer_cmp);
+ if (deserializers == NULL) {
+ BIO_printf(bio_err, "ERROR: Memory allocation\n");
+ return;
+ }
+ BIO_printf(bio_out, "Provided DESERIALIZERs:\n");
+ OSSL_DESERIALIZER_do_all_provided(NULL, collect_deserializers,
+ deserializers);
+ sk_OSSL_DESERIALIZER_sort(deserializers);
+
+ for (i = 0; i < sk_OSSL_DESERIALIZER_num(deserializers); i++) {
+ OSSL_DESERIALIZER *k = sk_OSSL_DESERIALIZER_value(deserializers, i);
+ STACK_OF(OPENSSL_CSTRING) *names =
+ sk_OPENSSL_CSTRING_new(name_cmp);
+
+ OSSL_DESERIALIZER_names_do_all(k, collect_names, names);
+
+ BIO_printf(bio_out, " ");
+ print_names(bio_out, names);
+ BIO_printf(bio_out, " @ %s (%s)\n",
+ OSSL_PROVIDER_name(OSSL_DESERIALIZER_provider(k)),
+ OSSL_DESERIALIZER_properties(k));
+
+ sk_OPENSSL_CSTRING_free(names);
+
+ if (verbose) {
+ print_param_types("settable operation parameters",
+ OSSL_DESERIALIZER_settable_ctx_params(k), 4);
+ }
+ }
+ sk_OSSL_DESERIALIZER_pop_free(deserializers, OSSL_DESERIALIZER_free);
+}
+
static void list_missing_help(void)
{
const FUNCTION *fp;
@@ -760,6 +822,7 @@ typedef enum HELPLIST_CHOICE {
OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED,
OPT_KDF_ALGORITHMS, OPT_RANDOM_GENERATORS, OPT_SERIALIZERS,
+ OPT_DESERIALIZERS,
OPT_MISSING_HELP, OPT_OBJECTS,
#ifndef OPENSSL_NO_DEPRECATED_3_0
OPT_ENGINES,
@@ -791,6 +854,8 @@ const OPTIONS list_options[] = {
{"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
"List of cipher algorithms"},
{"serializers", OPT_SERIALIZERS, '-', "List of serialization methods" },
+ {"deserializers", OPT_DESERIALIZERS, '-',
+ "List of deserialization methods" },
{"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
"List of public key algorithms"},
#ifndef OPENSSL_NO_DEPRECATED_3_0
@@ -826,6 +891,7 @@ int list_main(int argc, char **argv)
unsigned int cipher_commands:1;
unsigned int cipher_algorithms:1;
unsigned int serializer_algorithms:1;
+ unsigned int deserializer_algorithms:1;
unsigned int pk_algorithms:1;
unsigned int pk_method:1;
#ifndef OPENSSL_NO_DEPRECATED_3_0
@@ -880,6 +946,9 @@ opthelp:
case OPT_SERIALIZERS:
todo.serializer_algorithms = 1;
break;
+ case OPT_DESERIALIZERS:
+ todo.deserializer_algorithms = 1;
+ break;
case OPT_PK_ALGORITHMS:
todo.pk_algorithms = 1;
break;
@@ -936,6 +1005,8 @@ opthelp:
list_ciphers();
if (todo.serializer_algorithms)
list_serializers();
+ if (todo.deserializer_algorithms)
+ list_deserializers();
if (todo.pk_algorithms)
list_pkey();
#ifndef OPENSSL_NO_DEPRECATED_3_0