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
10 #ifndef OPENSSL_ENCODER_H
11 # define OPENSSL_ENCODER_H
14 # include <openssl/opensslconf.h>
16 # ifndef OPENSSL_NO_STDIO
21 # include <openssl/encodererr.h>
22 # include <openssl/types.h>
23 # include <openssl/core.h>
29 OSSL_ENCODER *OSSL_ENCODER_fetch(OPENSSL_CTX *libctx, const char *name,
30 const char *properties);
31 int OSSL_ENCODER_up_ref(OSSL_ENCODER *encoder);
32 void OSSL_ENCODER_free(OSSL_ENCODER *encoder);
34 const OSSL_PROVIDER *OSSL_ENCODER_provider(const OSSL_ENCODER *encoder);
35 const char *OSSL_ENCODER_properties(const OSSL_ENCODER *encoder);
36 int OSSL_ENCODER_number(const OSSL_ENCODER *encoder);
37 int OSSL_ENCODER_is_a(const OSSL_ENCODER *encoder, const char *name);
39 void OSSL_ENCODER_do_all_provided(OPENSSL_CTX *libctx,
40 void (*fn)(OSSL_ENCODER *encoder, void *arg),
42 void OSSL_ENCODER_names_do_all(const OSSL_ENCODER *encoder,
43 void (*fn)(const char *name, void *data),
46 const OSSL_PARAM *OSSL_ENCODER_settable_ctx_params(OSSL_ENCODER *encoder);
47 OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new(OSSL_ENCODER *encoder);
48 const OSSL_ENCODER *OSSL_ENCODER_CTX_get_encoder(OSSL_ENCODER_CTX *ctx);
49 int OSSL_ENCODER_CTX_set_params(OSSL_ENCODER_CTX *ctx,
50 const OSSL_PARAM params[]);
51 void OSSL_ENCODER_CTX_free(OSSL_ENCODER_CTX *ctx);
53 /* Utilities that help set specific parameters */
54 int OSSL_ENCODER_CTX_set_cipher(OSSL_ENCODER_CTX *ctx,
55 const char *cipher_name,
56 const char *propquery);
57 int OSSL_ENCODER_CTX_set_passphrase(OSSL_ENCODER_CTX *ctx,
58 const unsigned char *kstr,
60 int OSSL_ENCODER_CTX_set_passphrase_cb(OSSL_ENCODER_CTX *ctx,
61 pem_password_cb *cb, void *cbarg);
62 int OSSL_ENCODER_CTX_set_passphrase_ui(OSSL_ENCODER_CTX *ctx,
63 const UI_METHOD *ui_method,
66 /* Utilities to output the object to encode */
67 int OSSL_ENCODER_to_bio(OSSL_ENCODER_CTX *ctx, BIO *out);
68 #ifndef OPENSSL_NO_STDIO
69 int OSSL_ENCODER_to_fp(OSSL_ENCODER_CTX *ctx, FILE *fp);
73 * Create the OSSL_ENCODER_CTX with an associated type. This will perform
74 * an implicit OSSL_ENCODER_fetch(), suitable for the object of that type.
75 * This is more useful than calling OSSL_ENCODER_CTX_new().
77 OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new_by_EVP_PKEY(const EVP_PKEY *pkey,
78 const char *propquery);
81 * These macros define the last argument to pass to
82 * OSSL_ENCODER_CTX_new_by_TYPE().
84 # define OSSL_ENCODER_PUBKEY_TO_PEM_PQ "format=pem,type=public"
85 # define OSSL_ENCODER_PrivateKey_TO_PEM_PQ "format=pem,type=private"
86 # define OSSL_ENCODER_Parameters_TO_PEM_PQ "format=pem,type=parameters"
88 # define OSSL_ENCODER_PUBKEY_TO_DER_PQ "format=der,type=public"
89 # define OSSL_ENCODER_PrivateKey_TO_DER_PQ "format=der,type=private"
90 # define OSSL_ENCODER_Parameters_TO_DER_PQ "format=der,type=parameters"
92 /* Corresponding macros for text output */
93 # define OSSL_ENCODER_PUBKEY_TO_TEXT_PQ "format=text,type=public"
94 # define OSSL_ENCODER_PrivateKey_TO_TEXT_PQ "format=text,type=private"
95 # define OSSL_ENCODER_Parameters_TO_TEXT_PQ "format=text,type=parameters"