2 * Copyright 2019 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
10 #ifndef OPENSSL_SERIALIZER_H
11 # define OPENSSL_SERIALIZER_H
14 # include <openssl/opensslconf.h>
16 # ifndef OPENSSL_NO_STDIO
21 # include <openssl/serializererr.h>
22 # include <openssl/types.h>
23 # include <openssl/core.h>
29 OSSL_SERIALIZER *OSSL_SERIALIZER_fetch(OPENSSL_CTX *libctx,
31 const char *properties);
32 int OSSL_SERIALIZER_up_ref(OSSL_SERIALIZER *ser);
33 void OSSL_SERIALIZER_free(OSSL_SERIALIZER *ser);
35 const OSSL_PROVIDER *OSSL_SERIALIZER_provider(const OSSL_SERIALIZER *ser);
36 const char *OSSL_SERIALIZER_properties(const OSSL_SERIALIZER *ser);
37 int OSSL_SERIALIZER_number(const OSSL_SERIALIZER *ser);
38 int OSSL_SERIALIZER_is_a(const OSSL_SERIALIZER *ser,
41 void OSSL_SERIALIZER_do_all_provided(OPENSSL_CTX *libctx,
42 void (*fn)(OSSL_SERIALIZER *ser,
45 void OSSL_SERIALIZER_names_do_all(const OSSL_SERIALIZER *ser,
46 void (*fn)(const char *name, void *data),
49 const OSSL_PARAM *OSSL_SERIALIZER_settable_ctx_params(OSSL_SERIALIZER *ser);
50 OSSL_SERIALIZER_CTX *OSSL_SERIALIZER_CTX_new(OSSL_SERIALIZER *ser);
51 const OSSL_SERIALIZER *
52 OSSL_SERIALIZER_CTX_get_serializer(OSSL_SERIALIZER_CTX *ctx);
53 int OSSL_SERIALIZER_CTX_set_params(OSSL_SERIALIZER_CTX *ctx,
54 const OSSL_PARAM params[]);
55 void OSSL_SERIALIZER_CTX_free(OSSL_SERIALIZER_CTX *ctx);
57 /* Utilities that help set specific parameters */
58 int OSSL_SERIALIZER_CTX_set_cipher(OSSL_SERIALIZER_CTX *ctx,
59 const char *cipher_name,
60 const char *propquery);
61 int OSSL_SERIALIZER_CTX_set_passphrase(OSSL_SERIALIZER_CTX *ctx,
62 const unsigned char *kstr,
64 int OSSL_SERIALIZER_CTX_set_passphrase_cb(OSSL_SERIALIZER_CTX *ctx, int enc,
65 pem_password_cb *cb, void *cbarg);
66 int OSSL_SERIALIZER_CTX_set_passphrase_ui(OSSL_SERIALIZER_CTX *ctx,
67 const UI_METHOD *ui_method,
70 /* Utilities to output the object to serialize */
71 int OSSL_SERIALIZER_to_bio(OSSL_SERIALIZER_CTX *ctx, BIO *out);
72 #ifndef OPENSSL_NO_STDIO
73 int OSSL_SERIALIZER_to_fp(OSSL_SERIALIZER_CTX *ctx, FILE *fp);
77 * Create the OSSL_SERIALIZER_CTX with an associated type. This will perform
78 * an implicit OSSL_SERIALIZER_fetch(), suitable for the object of that type.
79 * This is more useful than calling OSSL_SERIALIZER_CTX_new().
81 OSSL_SERIALIZER_CTX *OSSL_SERIALIZER_CTX_new_by_EVP_PKEY(const EVP_PKEY *pkey,
82 const char *propquery);
85 * These macros define the last argument to pass to
86 * OSSL_SERIALIZER_CTX_new_by_TYPE().
88 # define OSSL_SERIALIZER_PUBKEY_TO_PEM_PQ "format=pem,type=public"
89 # define OSSL_SERIALIZER_PrivateKey_TO_PEM_PQ "format=pem,type=private"
90 # define OSSL_SERIALIZER_Parameters_TO_PEM_PQ "format=pem,type=parameters"
92 # define OSSL_SERIALIZER_PUBKEY_TO_DER_PQ "format=der,type=public"
93 # define OSSL_SERIALIZER_PrivateKey_TO_DER_PQ "format=der,type=private"
94 # define OSSL_SERIALIZER_Parameters_TO_DER_PQ "format=der,type=parameters"
96 /* Corresponding macros for text output */
97 # define OSSL_SERIALIZER_PUBKEY_TO_TEXT_PQ "format=text,type=public"
98 # define OSSL_SERIALIZER_PrivateKey_TO_TEXT_PQ "format=text,type=private"
99 # define OSSL_SERIALIZER_Parameters_TO_TEXT_PQ "format=text,type=parameters"