1OSSL_ENCODER_CTX(3ossl) OpenSSL OSSL_ENCODER_CTX(3ossl)
2
3
4
6 OSSL_ENCODER_CTX, OSSL_ENCODER_CTX_new,
7 OSSL_ENCODER_settable_ctx_params, OSSL_ENCODER_CTX_set_params,
8 OSSL_ENCODER_CTX_free, OSSL_ENCODER_CTX_set_selection,
9 OSSL_ENCODER_CTX_set_output_type,
10 OSSL_ENCODER_CTX_set_output_structure, OSSL_ENCODER_CTX_add_encoder,
11 OSSL_ENCODER_CTX_add_extra, OSSL_ENCODER_CTX_get_num_encoders,
12 OSSL_ENCODER_INSTANCE, OSSL_ENCODER_INSTANCE_get_encoder,
13 OSSL_ENCODER_INSTANCE_get_encoder_ctx,
14 OSSL_ENCODER_INSTANCE_get_output_type,
15 OSSL_ENCODER_INSTANCE_get_output_structure, OSSL_ENCODER_CONSTRUCT,
16 OSSL_ENCODER_CLEANUP, OSSL_ENCODER_CTX_set_construct,
17 OSSL_ENCODER_CTX_set_construct_data, OSSL_ENCODER_CTX_set_cleanup -
18 Encoder context routines
19
21 #include <openssl/encoder.h>
22
23 typedef struct ossl_encoder_ctx_st OSSL_ENCODER_CTX;
24
25 OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new();
26 const OSSL_PARAM *OSSL_ENCODER_settable_ctx_params(OSSL_ENCODER *encoder);
27 int OSSL_ENCODER_CTX_set_params(OSSL_ENCODER_CTX *ctx,
28 const OSSL_PARAM params[]);
29 void OSSL_ENCODER_CTX_free(OSSL_ENCODER_CTX *ctx);
30
31 int OSSL_ENCODER_CTX_set_selection(OSSL_ENCODER_CTX *ctx, int selection);
32 int OSSL_ENCODER_CTX_set_output_type(OSSL_ENCODER_CTX *ctx,
33 const char *output_type);
34 int OSSL_ENCODER_CTX_set_output_structure(OSSL_ENCODER_CTX *ctx,
35 const char *output_structure);
36
37 int OSSL_ENCODER_CTX_add_encoder(OSSL_ENCODER_CTX *ctx, OSSL_ENCODER *encoder);
38 int OSSL_ENCODER_CTX_add_extra(OSSL_ENCODER_CTX *ctx,
39 OSSL_LIB_CTX *libctx, const char *propq);
40 int OSSL_ENCODER_CTX_get_num_encoders(OSSL_ENCODER_CTX *ctx);
41
42 typedef struct ossl_encoder_instance_st OSSL_ENCODER_INSTANCE;
43 OSSL_ENCODER *
44 OSSL_ENCODER_INSTANCE_get_encoder(OSSL_ENCODER_INSTANCE *encoder_inst);
45 void *
46 OSSL_ENCODER_INSTANCE_get_encoder_ctx(OSSL_ENCODER_INSTANCE *encoder_inst);
47 const char *
48 OSSL_ENCODER_INSTANCE_get_output_type(OSSL_ENCODER_INSTANCE *encoder_inst);
49 const char *
50 OSSL_ENCODER_INSTANCE_get_output_structure(OSSL_ENCODER_INSTANCE *encoder_inst);
51
52 typedef const void *OSSL_ENCODER_CONSTRUCT(OSSL_ENCODER_INSTANCE *encoder_inst,
53 void *construct_data);
54 typedef void OSSL_ENCODER_CLEANUP(void *construct_data);
55
56 int OSSL_ENCODER_CTX_set_construct(OSSL_ENCODER_CTX *ctx,
57 OSSL_ENCODER_CONSTRUCT *construct);
58 int OSSL_ENCODER_CTX_set_construct_data(OSSL_ENCODER_CTX *ctx,
59 void *construct_data);
60 int OSSL_ENCODER_CTX_set_cleanup(OSSL_ENCODER_CTX *ctx,
61 OSSL_ENCODER_CLEANUP *cleanup);
62
64 Encoding an input object to the desired encoding may be done with a
65 chain of encoder implementations, which means that the output from one
66 encoder may be the input for the next in the chain. The
67 OSSL_ENCODER_CTX holds all the data about these encoders. This allows
68 having generic format encoders such as DER to PEM, as well as more
69 specialized encoders like RSA to DER.
70
71 The final output type must be given, and a chain of encoders must end
72 with an implementation that produces that output type.
73
74 At the beginning of the encoding process, a contructor provided by the
75 caller is called to ensure that there is an appropriate provider-side
76 object to start with. The constructor is set with
77 OSSL_ENCODER_CTX_set_construct().
78
79 OSSL_ENCODER_INSTANCE is an opaque structure that contains data about
80 the encoder that is going to be used, and that may be useful for the
81 constructor. There are some functions to extract data from this type,
82 described in "Constructor" below.
83
84 Functions
85 OSSL_ENCODER_CTX_new() creates a OSSL_ENCODER_CTX.
86
87 OSSL_ENCODER_settable_ctx_params() returns an OSSL_PARAM(3) array of
88 parameter descriptors.
89
90 OSSL_ENCODER_CTX_set_params() attempts to set parameters specified with
91 an OSSL_PARAM(3) array params. Parameters that the implementation
92 doesn't recognise should be ignored.
93
94 OSSL_ENCODER_CTX_free() frees the given context ctx.
95
96 OSSL_ENCODER_CTX_add_encoder() populates the OSSL_ENCODER_CTX ctx with
97 a encoder, to be used to encode an input object.
98
99 OSSL_ENCODER_CTX_add_extra() finds encoders that further encodes output
100 from already added encoders, and adds them as well. This is used to
101 build encoder chains.
102
103 OSSL_ENCODER_CTX_set_output_type() sets the ending output type. This
104 must be specified, and determines if a complete encoder chain is
105 available.
106
107 OSSL_ENCODER_CTX_set_output_structure() sets the desired output
108 structure. This may be used to determines what encoder implementations
109 may be used. Depending on the type of object being encoded, the output
110 structure may not be relevant.
111
112 OSSL_ENCODER_CTX_get_num_encoders() gets the number of encoders
113 currently added to the context ctx.
114
115 OSSL_ENCODER_CTX_set_construct() sets the constructor construct.
116
117 OSSL_ENCODER_CTX_set_construct_data() sets the constructor data that is
118 passed to the constructor every time it's called.
119
120 OSSL_ENCODER_CTX_set_cleanup() sets the constructor data cleanup
121 function. This is called by OSSL_ENCODER_CTX_free(3).
122
123 Constructor
124 A OSSL_ENCODER_CONSTRUCT gets the following arguments:
125
126 encoder_inst
127 The OSSL_ENCODER_INSTANCE for the encoder from which the
128 constructor gets its data.
129
130 construct_data
131 The pointer that was set with OSSL_ENCODE_CTX_set_construct_data().
132
133 The constructor is expected to return a valid (non-NULL) pointer to a
134 provider-native object that can be used as first input of an encoding
135 chain, or NULL to indicate that an error has occured.
136
137 These utility functions may be used by a constructor:
138
139 OSSL_ENCODER_INSTANCE_get_encoder() can be used to get the encoder
140 implementation of the encoder instance encoder_inst.
141
142 OSSL_ENCODER_INSTANCE_get_encoder_ctx() can be used to get the encoder
143 implementation's provider context of the encoder instance encoder_inst.
144
145 OSSL_ENCODER_INSTANCE_get_output_type() can be used to get the output
146 type for the encoder implementation of the encoder instance
147 encoder_inst. This will never be NULL.
148
149 OSSL_ENCODER_INSTANCE_get_output_structure() can be used to get the
150 output structure for the encoder implementation of the encoder instance
151 encoder_inst. This may be NULL.
152
154 OSSL_ENCODER_CTX_new() returns a pointer to a OSSL_ENCODER_CTX, or NULL
155 if the context structure couldn't be allocated.
156
157 OSSL_ENCODER_settable_ctx_params() returns an OSSL_PARAM(3) array, or
158 NULL if none is available.
159
160 OSSL_ENCODER_CTX_set_params() returns 1 if all recognised parameters
161 were valid, or 0 if one of them was invalid or caused some other
162 failure in the implementation.
163
164 OSSL_ENCODER_CTX_add_encoder(), OSSL_ENCODER_CTX_add_extra(),
165 OSSL_ENCODER_CTX_set_construct(), OSSL_ENCODER_CTX_set_construct_data()
166 and OSSL_ENCODER_CTX_set_cleanup() return 1 on success, or 0 on
167 failure.
168
169 OSSL_ENCODER_CTX_get_num_encoders() returns the current number of
170 encoders. It returns 0 if ctx is NULL.
171
172 OSSL_ENCODER_INSTANCE_get_encoder() returns an OSSL_ENCODER pointer on
173 success, or NULL on failure.
174
175 OSSL_ENCODER_INSTANCE_get_encoder_ctx() returns a provider context
176 pointer on success, or NULL on failure.
177
178 OSSL_ENCODER_INSTANCE_get_output_type() returns a string with the name
179 of the input type, if relevant. NULL is a valid returned value.
180
181 OSSL_ENCODER_INSTANCE_get_output_type() returns a string with the name
182 of the output type.
183
184 OSSL_ENCODER_INSTANCE_get_output_structure() returns a string with the
185 name of the output structure.
186
188 provider(7), OSSL_ENCODER(3)
189
191 The functions described here were added in OpenSSL 3.0.
192
194 Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
195
196 Licensed under the Apache License 2.0 (the "License"). You may not use
197 this file except in compliance with the License. You can obtain a copy
198 in the file LICENSE in the source distribution or at
199 <https://www.openssl.org/source/license.html>.
200
201
202
2033.0.5 2022-11-01 OSSL_ENCODER_CTX(3ossl)