]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/OSSL_DESERIALIZER_from_bio.pod
Rename OSSL_SERIALIZER / OSSL_DESERIALIZER to OSSL_ENCODE / OSSL_DECODE
[thirdparty/openssl.git] / doc / man3 / OSSL_DESERIALIZER_from_bio.pod
CommitLineData
c3e4c1f3
RL
1=pod
2
3=head1 NAME
4
5OSSL_DESERIALIZER_from_bio,
6OSSL_DESERIALIZER_from_fp,
7OSSL_DESERIALIZER_CTX_set_input_type,
8OSSL_DESERIALIZER_CTX_add_deserializer,
9OSSL_DESERIALIZER_CTX_add_extra,
10OSSL_DESERIALIZER_CTX_num_deserializers,
11OSSL_DESERIALIZER_INSTANCE,
3c033c5b
RL
12OSSL_DESERIALIZER_CONSTRUCT,
13OSSL_DESERIALIZER_CLEANUP,
14OSSL_DESERIALIZER_CTX_set_construct,
15OSSL_DESERIALIZER_CTX_set_construct_data,
16OSSL_DESERIALIZER_CTX_set_cleanup,
17OSSL_DESERIALIZER_CTX_get_construct,
18OSSL_DESERIALIZER_CTX_get_construct_data,
19OSSL_DESERIALIZER_CTX_get_cleanup,
c3e4c1f3
RL
20OSSL_DESERIALIZER_export,
21OSSL_DESERIALIZER_INSTANCE_deserializer,
22OSSL_DESERIALIZER_INSTANCE_deserializer_ctx
23- Routines to perform a deserialization
24
25=head1 SYNOPSIS
26
27 #include <openssl/deserializer.h>
28
29 int OSSL_DESERIALIZER_from_bio(OSSL_DESERIALIZER_CTX *ctx, BIO *in);
30 int OSSL_DESERIALIZER_from_fp(OSSL_DESERIALIZER_CTX *ctx, FILE *fp);
31
32 int OSSL_DESERIALIZER_CTX_set_input_type(OSSL_DESERIALIZER_CTX *ctx,
33 const char *input_type);
34 int OSSL_DESERIALIZER_CTX_add_deserializer(OSSL_DESERIALIZER_CTX *ctx,
35 OSSL_DESERIALIZER *deser);
36 int OSSL_DESERIALIZER_CTX_add_extra(OSSL_DESERIALIZER_CTX *ctx);
37 int OSSL_DESERIALIZER_CTX_num_deserializers(OSSL_DESERIALIZER_CTX *ctx);
38
39 typedef struct ossl_deserializer_instance_st OSSL_DESERIALIZER_INSTANCE;
3c033c5b
RL
40 OSSL_DESERIALIZER *OSSL_DESERIALIZER_INSTANCE_deserializer
41 (OSSL_DESERIALIZER_INSTANCE *deser_inst);
42 void *OSSL_DESERIALIZER_INSTANCE_deserializer_ctx
43 (OSSL_DESERIALIZER_INSTANCE *deser_inst);
c3e4c1f3 44
3c033c5b
RL
45 typedef int (OSSL_DESERIALIZER_CONSTRUCT)
46 (OSSL_DESERIALIZER_INSTANCE *deser_inst,
47 const OSSL_PARAM *params, void *construct_data);
48 typedef void (OSSL_DESERIALIZER_CLEANUP)(void *construct_data);
49
50 int OSSL_DESERIALIZER_CTX_set_construct
51 (OSSL_DESERIALIZER_CTX *ctx, OSSL_DESERIALIZER_CONSTRUCT *construct);
52 int OSSL_DESERIALIZER_CTX_set_construct_data
53 (OSSL_DESERIALIZER_CTX *ctx, void *construct_data);
54 int OSSL_DESERIALIZER_CTX_set_cleanup(OSSL_DESERIALIZER_CTX *ctx,
55 OSSL_DESERIALIZER_CLEANUP *cleanup);
56 OSSL_DESERIALIZER_CONSTRUCT *
57 OSSL_DESERIALIZER_CTX_get_construct(OSSL_DESERIALIZER_CTX *ctx);
58 void *OSSL_DESERIALIZER_CTX_get_construct_data(OSSL_DESERIALIZER_CTX *ctx);
59 OSSL_DESERIALIZER_CLEANUP *
60 OSSL_DESERIALIZER_CTX_get_cleanup(OSSL_DESERIALIZER_CTX *ctx);
c3e4c1f3
RL
61
62 int OSSL_DESERIALIZER_export(OSSL_DESERIALIZER_INSTANCE *deser_inst,
63 void *reference, size_t reference_sz,
64 OSSL_CALLBACK *export_cb, void *export_cbarg);
65
c3e4c1f3
RL
66Feature availability macros:
67
68=over 4
69
70=item OSSL_DESERIALIZER_from_fp() is only available when B<OPENSSL_NO_STDIO>
71is undefined.
72
73=back
74
75=head1 DESCRIPTION
76
77The B<OSSL_DESERIALIZER_CTX> holds data about multiple deserializers, as
78needed to figure out what the input data is and to attempt to unpack it into
79one of several possible related results. This also includes chaining
80deserializers, so the output from one can become the input for another.
81This allows having generic format deserializers such as PEM to DER, as well
82as more specialized deserializers like DER to RSA.
83
84The chains may be limited by specifying an input type, which is considered a
85starting point.
86This is both considered by OSSL_DESERIALIZER_CTX_add_extra(), which will
87stop adding on more deserializer implementations when it has already added
88those that take the specified input type, and OSSL_DESERIALIZER_from_bio(),
89which will only start the deserializing process with the deserializer
90implementations that take that input type. For example, if the input type
91is set to C<DER>, a PEM to DER deserializer will be ignored.
92
93The input type can also be NULL, which means that the caller doesn't know
94what type of input they have. In this case, OSSL_DESERIALIZER_from_bio()
95will simply try with one deserializer implementation after the other, and
96thereby discover what kind of input the caller gave it.
97
3c033c5b
RL
98For every deserialization done, even an intermediary one, a constructor
99provided by the caller is called to attempt to construct an appropriate type
100/ structure that the caller knows how to handle from the current
101deserialization result.
102The constructor is set with OSSL_DESERIALIZER_CTX_set_construct().
c3e4c1f3
RL
103
104B<OSSL_DESERIALIZER_INSTANCE> is an opaque structure that contains
105data about the deserializer that was just used, and that may be
3c033c5b 106useful for the constructor. There are some functions to extract data
c3e4c1f3
RL
107from this type, described further down.
108
109=head2 Functions
110
111OSSL_DESERIALIZER_from_bio() runs the deserialization process for the
3c033c5b
RL
112context I<ctx>, with the input coming from the B<BIO> I<in>. Should
113it make a difference, it's recommended to have the BIO set in binary
114mode rather than text mode.
c3e4c1f3
RL
115
116OSSL_DESERIALIZER_from_fp() does the same thing as OSSL_DESERIALIZER_from_bio(),
117except that the input is coming from the B<FILE> I<fp>.
118
119OSSL_DESERIALIZER_CTX_add_deserializer() populates the B<OSSL_DESERIALIZER_CTX>
120I<ctx> with a deserializer, to be used to attempt to deserialize some
121serialized input.
122
123OSSL_DESERIALIZER_CTX_add_extra() finds deserializers that generate
124input for already added deserializers, and adds them as well. This is
125used to build deserializer chains.
126
127OSSL_DESERIALIZER_CTX_set_input_type() sets the starting input type. This
128limits the deserializer chains to be considered, as explained in the general
129description above.
130
131OSSL_DESERIALIZER_CTX_num_deserializers() gets the number of
132deserializers currently added to the context I<ctx>.
133
3c033c5b 134OSSL_DESERIALIZER_CTX_set_construct() sets the constructor I<construct>.
c3e4c1f3 135
3c033c5b
RL
136OSSL_DESERIALIZER_CTX_set_construct_data() sets the constructor data that is
137passed to the constructor every time it's called.
138
139OSSL_DESERIALIZER_CTX_set_cleanup() sets the constructor data I<cleanup>
140function. This is called by L<OSSL_DESERIALIZER_CTX_free(3)>.
141
142OSSL_DESERIALIZER_CTX_get_construct(),
143OSSL_DESERIALIZER_CTX_get_construct_data() and
144OSSL_DESERIALIZER_CTX_get_cleanup()
145return the values that have been set by
146OSSL_DESERIALIZER_CTX_set_construct(),
147OSSL_DESERIALIZER_CTX_set_construct_data() and
148OSSL_DESERIALIZER_CTX_set_cleanup() respectively.
149
150OSSL_DESERIALIZER_export() is a fallback function for constructors that
151cannot use the data they get directly for diverse reasons. It takes the same
152deserialize instance I<deser_inst> that the constructor got and an object
153I<reference>, unpacks the object which it refers to, and exports it by creating
154an L<OSSL_PARAM(3)> array that it then passes to I<export_cb>, along with
155I<export_arg>.
c3e4c1f3
RL
156
157OSSL_DESERIALIZER_INSTANCE_deserializer() can be used to get the
158deserializer method from a deserializer instance I<deser_inst>.
159
160OSSL_DESERIALIZER_INSTANCE_deserializer-ctx() can be used to get the
161deserializer method's provider context from a deserializer instance
162I<deser_inst>.
163
3c033c5b 164=head2 Constructor
c3e4c1f3 165
3c033c5b 166A B<OSSL_DESERIALIZER_CONSTRUCT> gets the following arguments:
c3e4c1f3
RL
167
168=over 4
169
170=item I<deser_inst>
171
172The B<OSSL_DESERIALIZER_INSTANCE> for the deserializer from which
3c033c5b 173the constructor gets its data.
c3e4c1f3
RL
174
175=item I<params>
176
177The data produced by the deserializer, further described below.
178
3c033c5b 179=item I<construct_data>
c3e4c1f3 180
3c033c5b 181The pointer that was set with OSSL_DESERIALIZE_CTX_set_construct_data().
c3e4c1f3
RL
182
183=back
184
3c033c5b
RL
185The constructor is expected to return 1 when the data it receives can
186be constructed, otherwise 0.
c3e4c1f3 187
3c033c5b 188The globally known parameters that the constructor can get in I<params>
c3e4c1f3
RL
189are:
190
191=over 4
192
193=item "data-type" (B<OSSL_DESERIALIZER_PARAM_DATA_TYPE>) <UTF8 string>
194
195This is a detected content type that some deserializers may provide.
196For example, PEM input sometimes has a type specified in its header,
197and some deserializers may add that information as this parameter.
198This is an optional parameter, but may be useful for extra checks in
3c033c5b 199the constructor.
c3e4c1f3
RL
200
201=item "data" (B<OSSL_DESERIALIZER_PARAM_DATA>) <octet string>
202
203The deserialized data itself, as an octet string. This is produced by
204deserializers when it's possible to pass an object in this form. Most
205often, this is simply meant to be passed to the next deserializer in a
206chain, but could be considered final data as well, at the discretion
3c033c5b 207of the constructor.
c3e4c1f3
RL
208
209=item "reference" (B<OSSL_DESERIALIZER_PARAM_DATA>) <octet string>
210
211The deserialized data itself, as a reference to an object. The
212reference itself is an octet string, and can be passed to other
213operations and functions within the same provider as the one that
214provides I<deser>.
215
216=back
217
218At least one of "data" or "reference" must be present, and it's
3c033c5b
RL
219possible that both can be. A constructor should choose to use the
220"reference" parameter if possible, otherwise it should use the "data"
221parameter.
c3e4c1f3
RL
222
223If it's not possible to use the "reference" parameter, but that's
3c033c5b 224still what a constructor wants to do, it is possible to use
c3e4c1f3
RL
225OSSL_DESERIALIZER_export() as a fallback.
226
227=head1 RETURN VALUES
228
229OSSL_DESERIALIZER_from_bio() and OSSL_DESERIALIZER_from_fp() return 1 on
230success, or 0 on failure.
231
232OSSL_DESERIALIZER_CTX_add_deserializer(),
3c033c5b
RL
233OSSL_DESERIALIZER_CTX_add_extra(),
234OSSL_DESERIALIZER_CTX_set_construct(),
235OSSL_DESERIALIZER_CTX_set_construct_data() and
236OSSL_DESERIALIZER_CTX_set_cleanup() return 1 on success, or 0 on
c3e4c1f3
RL
237failure.
238
3c033c5b
RL
239OSSL_DESERIALIZER_CTX_get_construct(),
240OSSL_DESERIALIZER_CTX_get_construct_data() and
241OSSL_DESERIALIZER_CTX_get_cleanup() return the current pointers to the
242cosntructor, the constructor data and the cleanup functions, respectively.
243
c3e4c1f3
RL
244OSSL_DESERIALIZER_CTX_num_deserializers() returns the current
245number of deserializers. It returns 0 if I<ctx> is NULL.
246
247OSSL_DESERIALIZER_export() returns 1 on success, or 0 on failure.
248
249OSSL_DESERIALIZER_INSTANCE_deserializer() returns an
250B<OSSL_DESERIALIZER> pointer on success, or NULL on failure.
251
252OSSL_DESERIALIZER_INSTANCE_deserializer_ctx() returns a provider
253context pointer on success, or NULL on failure.>
254
255=begin comment TODO(3.0) Add examples!
256
257=head1 EXAMPLES
258
259Text, because pod2xxx doesn't like empty sections
260
261=end comment
262
263=head1 SEE ALSO
264
265L<provider(7)>, L<OSSL_DESERIALIZER_CTX(3)>
266
267=head1 HISTORY
268
269The functions described here were added in OpenSSL 3.0.
270
271=head1 COPYRIGHT
272
273Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
274
275Licensed under the Apache License 2.0 (the "License"). You may not use
276this file except in compliance with the License. You can obtain a copy
277in the file LICENSE in the source distribution or at
278L<https://www.openssl.org/source/license.html>.
279
280=cut