7 OSSL_DECODER_CTX_set_input_type,
8 OSSL_DECODER_CTX_add_decoder,
9 OSSL_DECODER_CTX_add_extra,
10 OSSL_DECODER_CTX_num_decoders,
11 OSSL_DECODER_INSTANCE,
12 OSSL_DECODER_CONSTRUCT,
14 OSSL_DECODER_CTX_set_construct,
15 OSSL_DECODER_CTX_set_construct_data,
16 OSSL_DECODER_CTX_set_cleanup,
17 OSSL_DECODER_CTX_get_construct,
18 OSSL_DECODER_CTX_get_construct_data,
19 OSSL_DECODER_CTX_get_cleanup,
21 OSSL_DECODER_INSTANCE_decoder,
22 OSSL_DECODER_INSTANCE_decoder_ctx
23 - Routines to perform a decoding
27 #include <openssl/decoder.h>
29 int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in);
30 int OSSL_DECODER_from_fp(OSSL_DECODER_CTX *ctx, FILE *fp);
32 int OSSL_DECODER_CTX_set_input_type(OSSL_DECODER_CTX *ctx,
33 const char *input_type);
34 int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder);
35 int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx);
36 int OSSL_DECODER_CTX_num_decoders(OSSL_DECODER_CTX *ctx);
38 typedef struct ossl_decoder_instance_st OSSL_DECODER_INSTANCE;
40 OSSL_DECODER_INSTANCE_decoder(OSSL_DECODER_INSTANCE *decoder_inst);
41 void *OSSL_DECODER_INSTANCE_decoder_ctx(OSSL_DECODER_INSTANCE *decoder_inst);
43 typedef int (OSSL_DECODER_CONSTRUCT)(OSSL_DECODER_INSTANCE *decoder_inst,
44 const OSSL_PARAM *params,
45 void *construct_data);
46 typedef void (OSSL_DECODER_CLEANUP)(void *construct_data);
48 int OSSL_DECODER_CTX_set_construct(OSSL_DECODER_CTX *ctx,
49 OSSL_DECODER_CONSTRUCT *construct);
50 int OSSL_DECODER_CTX_set_construct_data(OSSL_DECODER_CTX *ctx,
51 void *construct_data);
52 int OSSL_DECODER_CTX_set_cleanup(OSSL_DECODER_CTX *ctx,
53 OSSL_DECODER_CLEANUP *cleanup);
54 OSSL_DECODER_CONSTRUCT *OSSL_DECODER_CTX_get_construct(OSSL_DECODER_CTX *ctx);
55 void *OSSL_DECODER_CTX_get_construct_data(OSSL_DECODER_CTX *ctx);
56 OSSL_DECODER_CLEANUP *OSSL_DECODER_CTX_get_cleanup(OSSL_DECODER_CTX *ctx);
58 int OSSL_DECODER_export(OSSL_DECODER_INSTANCE *decoder_inst,
59 void *reference, size_t reference_sz,
60 OSSL_CALLBACK *export_cb, void *export_cbarg);
62 Feature availability macros:
66 =item OSSL_DECODER_from_fp() is only available when B<OPENSSL_NO_STDIO>
73 The B<OSSL_DECODER_CTX> holds data about multiple decoders, as
74 needed to figure out what the input data is and to attempt to unpack it into
75 one of several possible related results. This also includes chaining
76 decoders, so the output from one can become the input for another.
77 This allows having generic format decoders such as PEM to DER, as well
78 as more specialized decoders like DER to RSA.
80 The chains may be limited by specifying an input type, which is considered a
82 This is both considered by OSSL_DECODER_CTX_add_extra(), which will
83 stop adding on more decoder implementations when it has already added
84 those that take the specified input type, and OSSL_DECODER_from_bio(),
85 which will only start the decoding process with the decoder
86 implementations that take that input type. For example, if the input type
87 is set to C<DER>, a PEM to DER decoder will be ignored.
89 The input type can also be NULL, which means that the caller doesn't know
90 what type of input they have. In this case, OSSL_DECODER_from_bio()
91 will simply try with one decoder implementation after the other, and
92 thereby discover what kind of input the caller gave it.
94 For every decoding done, even an intermediary one, a constructor
95 provided by the caller is called to attempt to construct an appropriate type
96 / structure that the caller knows how to handle from the current
98 The constructor is set with OSSL_DECODER_CTX_set_construct().
100 B<OSSL_DECODER_INSTANCE> is an opaque structure that contains
101 data about the decoder that was just used, and that may be
102 useful for the constructor. There are some functions to extract data
103 from this type, described further down.
107 OSSL_DECODER_from_bio() runs the decoding process for the
108 context I<ctx>, with the input coming from the B<BIO> I<in>. Should
109 it make a difference, it's recommended to have the BIO set in binary
110 mode rather than text mode.
112 OSSL_DECODER_from_fp() does the same thing as OSSL_DECODER_from_bio(),
113 except that the input is coming from the B<FILE> I<fp>.
115 OSSL_DECODER_CTX_add_decoder() populates the B<OSSL_DECODER_CTX>
116 I<ctx> with a decoder, to be used to attempt to decode some
119 OSSL_DECODER_CTX_add_extra() finds decoders that generate
120 input for already added decoders, and adds them as well. This is
121 used to build decoder chains.
123 OSSL_DECODER_CTX_set_input_type() sets the starting input type. This
124 limits the decoder chains to be considered, as explained in the general
127 OSSL_DECODER_CTX_num_decoders() gets the number of
128 decoders currently added to the context I<ctx>.
130 OSSL_DECODER_CTX_set_construct() sets the constructor I<construct>.
132 OSSL_DECODER_CTX_set_construct_data() sets the constructor data that is
133 passed to the constructor every time it's called.
135 OSSL_DECODER_CTX_set_cleanup() sets the constructor data I<cleanup>
136 function. This is called by L<OSSL_DECODER_CTX_free(3)>.
138 OSSL_DECODER_CTX_get_construct(),
139 OSSL_DECODER_CTX_get_construct_data() and
140 OSSL_DECODER_CTX_get_cleanup()
141 return the values that have been set by
142 OSSL_DECODER_CTX_set_construct(),
143 OSSL_DECODER_CTX_set_construct_data() and
144 OSSL_DECODER_CTX_set_cleanup() respectively.
146 OSSL_DECODER_export() is a fallback function for constructors that
147 cannot use the data they get directly for diverse reasons. It takes the same
148 decode instance I<decoder_inst> that the constructor got and an object
149 I<reference>, unpacks the object which it refers to, and exports it by creating
150 an L<OSSL_PARAM(3)> array that it then passes to I<export_cb>, along with
153 OSSL_DECODER_INSTANCE_decoder() can be used to get the
154 decoder method from a decoder instance I<decoder_inst>.
156 OSSL_DECODER_INSTANCE_decoder-ctx() can be used to get the
157 decoder method's provider context from a decoder instance
162 A B<OSSL_DECODER_CONSTRUCT> gets the following arguments:
166 =item I<decoder_inst>
168 The B<OSSL_DECODER_INSTANCE> for the decoder from which
169 the constructor gets its data.
173 The data produced by the decoder, further described below.
175 =item I<construct_data>
177 The pointer that was set with OSSL_DECODE_CTX_set_construct_data().
181 The constructor is expected to return 1 when the data it receives can
182 be constructed, otherwise 0.
184 The globally known parameters that the constructor can get in I<params>
189 =item "data-type" (B<OSSL_DECODER_PARAM_DATA_TYPE>) <UTF8 string>
191 This is a detected content type that some decoders may provide.
192 For example, PEM input sometimes has a type specified in its header,
193 and some decoders may add that information as this parameter.
194 This is an optional parameter, but may be useful for extra checks in
197 =item "data" (B<OSSL_DECODER_PARAM_DATA>) <octet string>
199 The decoded data itself, as an octet string. This is produced by
200 decoders when it's possible to pass an object in this form. Most
201 often, this is simply meant to be passed to the next decoder in a
202 chain, but could be considered final data as well, at the discretion
205 =item "reference" (B<OSSL_DECODER_PARAM_DATA>) <octet string>
207 The decoded data itself, as a reference to an object. The
208 reference itself is an octet string, and can be passed to other
209 operations and functions within the same provider as the one that
214 At least one of "data" or "reference" must be present, and it's
215 possible that both can be. A constructor should choose to use the
216 "reference" parameter if possible, otherwise it should use the "data"
219 If it's not possible to use the "reference" parameter, but that's
220 still what a constructor wants to do, it is possible to use
221 OSSL_DECODER_export() as a fallback.
225 OSSL_DECODER_from_bio() and OSSL_DECODER_from_fp() return 1 on
226 success, or 0 on failure.
228 OSSL_DECODER_CTX_add_decoder(),
229 OSSL_DECODER_CTX_add_extra(),
230 OSSL_DECODER_CTX_set_construct(),
231 OSSL_DECODER_CTX_set_construct_data() and
232 OSSL_DECODER_CTX_set_cleanup() return 1 on success, or 0 on
235 OSSL_DECODER_CTX_get_construct(),
236 OSSL_DECODER_CTX_get_construct_data() and
237 OSSL_DECODER_CTX_get_cleanup() return the current pointers to the
238 cosntructor, the constructor data and the cleanup functions, respectively.
240 OSSL_DECODER_CTX_num_decoders() returns the current
241 number of decoders. It returns 0 if I<ctx> is NULL.
243 OSSL_DECODER_export() returns 1 on success, or 0 on failure.
245 OSSL_DECODER_INSTANCE_decoder() returns an
246 B<OSSL_DECODER> pointer on success, or NULL on failure.
248 OSSL_DECODER_INSTANCE_decoder_ctx() returns a provider
249 context pointer on success, or NULL on failure.>
251 =begin comment TODO(3.0) Add examples!
255 Text, because pod2xxx doesn't like empty sections
261 L<provider(7)>, L<OSSL_DECODER_CTX(3)>
265 The functions described here were added in OpenSSL 3.0.
269 Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
271 Licensed under the Apache License 2.0 (the "License"). You may not use
272 this file except in compliance with the License. You can obtain a copy
273 in the file LICENSE in the source distribution or at
274 L<https://www.openssl.org/source/license.html>.