]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/encode_decode/encoder_local.h
ASN1: Fix d2i_KeyParams() to advance |pp| like all other d2i functions do
[thirdparty/openssl.git] / crypto / encode_decode / encoder_local.h
CommitLineData
ece9304c
RL
1/*
2 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10#include <openssl/core_dispatch.h>
11#include <openssl/types.h>
12#include <openssl/safestack.h>
13#include <openssl/encoder.h>
14#include <openssl/decoder.h>
15#include "internal/cryptlib.h"
a517edec 16#include "internal/passphrase.h"
ece9304c
RL
17#include "internal/refcount.h"
18
19struct ossl_serdes_base_st {
20 OSSL_PROVIDER *prov;
21 int id;
22 const char *propdef;
23
24 CRYPTO_REF_COUNT refcnt;
25 CRYPTO_RWLOCK *lock;
26};
27
28struct ossl_encoder_st {
29 struct ossl_serdes_base_st base;
30 OSSL_FUNC_encoder_newctx_fn *newctx;
31 OSSL_FUNC_encoder_freectx_fn *freectx;
32 OSSL_FUNC_encoder_set_ctx_params_fn *set_ctx_params;
33 OSSL_FUNC_encoder_settable_ctx_params_fn *settable_ctx_params;
34 OSSL_FUNC_encoder_encode_data_fn *encode_data;
35 OSSL_FUNC_encoder_encode_object_fn *encode_object;
36};
37
38struct ossl_decoder_st {
39 struct ossl_serdes_base_st base;
40 OSSL_FUNC_decoder_newctx_fn *newctx;
41 OSSL_FUNC_decoder_freectx_fn *freectx;
42 OSSL_FUNC_decoder_get_params_fn *get_params;
43 OSSL_FUNC_decoder_gettable_params_fn *gettable_params;
44 OSSL_FUNC_decoder_set_ctx_params_fn *set_ctx_params;
45 OSSL_FUNC_decoder_settable_ctx_params_fn *settable_ctx_params;
46 OSSL_FUNC_decoder_decode_fn *decode;
47 OSSL_FUNC_decoder_export_object_fn *export_object;
48};
49
50struct ossl_encoder_ctx_st {
51 OSSL_ENCODER *encoder;
52 void *serctx;
53
54 int selection;
55
56 /*-
57 * Output / encoding data, used by OSSL_ENCODER_to_{bio,fp}
58 *
59 * |object| is the libcrypto object to handle.
60 * |do_output| performs the actual encoding.
61 *
62 * |do_output| must have intimate knowledge of |object|.
63 */
64 const void *object;
65 int (*do_output)(OSSL_ENCODER_CTX *ctx, BIO *out);
66
67 /* For any function that needs a passphrase reader */
a517edec 68 struct ossl_passphrase_data_st pwdata;
ece9304c
RL
69};
70
71struct ossl_decoder_instance_st {
72 OSSL_DECODER *decoder; /* Never NULL */
73 void *deserctx; /* Never NULL */
74 const char *input_type; /* Never NULL */
75};
76
77DEFINE_STACK_OF(OSSL_DECODER_INSTANCE)
78
79struct ossl_decoder_ctx_st {
80 /*
81 * The caller may know the input type of the data they pass. If not,
82 * this will remain NULL and the decoding functionality will start
83 * with trying to decode with any desencoder in |decoder_insts|,
84 * regardless of their respective input type.
85 */
86 const char *start_input_type;
87
88 /*
89 * Decoders that are components of any current decoding path.
90 */
91 STACK_OF(OSSL_DECODER_INSTANCE) *decoder_insts;
92
93 /*
94 * The constructors of a decoding, and its caller argument.
95 */
96 OSSL_DECODER_CONSTRUCT *construct;
97 OSSL_DECODER_CLEANUP *cleanup;
98 void *construct_data;
99
100 /* For any function that needs a passphrase reader */
a517edec 101 struct ossl_passphrase_data_st pwdata;
ece9304c 102};