xref: /freebsd/crypto/openssl/doc/man3/OSSL_DECODER.pod (revision a7148ab39c03abd4d1a84997c70bf96f15dd2a09)
1b077aed3SPierre Pronchery=pod
2b077aed3SPierre Pronchery
3b077aed3SPierre Pronchery=head1 NAME
4b077aed3SPierre Pronchery
5b077aed3SPierre ProncheryOSSL_DECODER,
6b077aed3SPierre ProncheryOSSL_DECODER_fetch,
7b077aed3SPierre ProncheryOSSL_DECODER_up_ref,
8b077aed3SPierre ProncheryOSSL_DECODER_free,
9b077aed3SPierre ProncheryOSSL_DECODER_get0_provider,
10b077aed3SPierre ProncheryOSSL_DECODER_get0_properties,
11b077aed3SPierre ProncheryOSSL_DECODER_is_a,
12b077aed3SPierre ProncheryOSSL_DECODER_get0_name,
13b077aed3SPierre ProncheryOSSL_DECODER_get0_description,
14b077aed3SPierre ProncheryOSSL_DECODER_do_all_provided,
15b077aed3SPierre ProncheryOSSL_DECODER_names_do_all,
16b077aed3SPierre ProncheryOSSL_DECODER_gettable_params,
17b077aed3SPierre ProncheryOSSL_DECODER_get_params
18b077aed3SPierre Pronchery- Decoder method routines
19b077aed3SPierre Pronchery
20b077aed3SPierre Pronchery=head1 SYNOPSIS
21b077aed3SPierre Pronchery
22b077aed3SPierre Pronchery #include <openssl/decoder.h>
23b077aed3SPierre Pronchery
24b077aed3SPierre Pronchery typedef struct ossl_decoder_st OSSL_DECODER;
25b077aed3SPierre Pronchery
26b077aed3SPierre Pronchery OSSL_DECODER *OSSL_DECODER_fetch(OSSL_LIB_CTX *ctx, const char *name,
27b077aed3SPierre Pronchery                                  const char *properties);
28b077aed3SPierre Pronchery int OSSL_DECODER_up_ref(OSSL_DECODER *decoder);
29b077aed3SPierre Pronchery void OSSL_DECODER_free(OSSL_DECODER *decoder);
30b077aed3SPierre Pronchery const OSSL_PROVIDER *OSSL_DECODER_get0_provider(const OSSL_DECODER *decoder);
31b077aed3SPierre Pronchery const char *OSSL_DECODER_get0_properties(const OSSL_DECODER *decoder);
32b077aed3SPierre Pronchery int OSSL_DECODER_is_a(const OSSL_DECODER *decoder, const char *name);
33b077aed3SPierre Pronchery const char *OSSL_DECODER_get0_name(const OSSL_DECODER *decoder);
34b077aed3SPierre Pronchery const char *OSSL_DECODER_get0_description(const OSSL_DECODER *decoder);
35b077aed3SPierre Pronchery void OSSL_DECODER_do_all_provided(OSSL_LIB_CTX *libctx,
36b077aed3SPierre Pronchery                                   void (*fn)(OSSL_DECODER *decoder, void *arg),
37b077aed3SPierre Pronchery                                   void *arg);
38b077aed3SPierre Pronchery int OSSL_DECODER_names_do_all(const OSSL_DECODER *decoder,
39b077aed3SPierre Pronchery                               void (*fn)(const char *name, void *data),
40b077aed3SPierre Pronchery                               void *data);
41b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_DECODER_gettable_params(OSSL_DECODER *decoder);
42b077aed3SPierre Pronchery int OSSL_DECODER_get_params(OSSL_DECODER_CTX *ctx, const OSSL_PARAM params[]);
43b077aed3SPierre Pronchery
44b077aed3SPierre Pronchery=head1 DESCRIPTION
45b077aed3SPierre Pronchery
46b077aed3SPierre ProncheryB<OSSL_DECODER> is a method for decoders, which know how to
47b077aed3SPierre Proncherydecode encoded data into an object of some type that the rest
48b077aed3SPierre Proncheryof OpenSSL knows how to handle.
49b077aed3SPierre Pronchery
50b077aed3SPierre ProncheryOSSL_DECODER_fetch() looks for an algorithm within the provider that
51b077aed3SPierre Proncheryhas been loaded into the B<OSSL_LIB_CTX> given by I<ctx>, having the
52b077aed3SPierre Proncheryname given by I<name> and the properties given by I<properties>.
53b077aed3SPierre ProncheryThe I<name> determines what type of object the fetched decoder
54b077aed3SPierre Proncherymethod is expected to be able to decode, and the properties are
55b077aed3SPierre Proncheryused to determine the expected output type.
56b077aed3SPierre ProncheryFor known properties and the values they may have, please have a look
57b077aed3SPierre Proncheryin L<provider-encoder(7)/Names and properties>.
58b077aed3SPierre Pronchery
59b077aed3SPierre ProncheryOSSL_DECODER_up_ref() increments the reference count for the given
60b077aed3SPierre ProncheryI<decoder>.
61b077aed3SPierre Pronchery
62b077aed3SPierre ProncheryOSSL_DECODER_free() decrements the reference count for the given
63b077aed3SPierre ProncheryI<decoder>, and when the count reaches zero, frees it.
64*a7148ab3SEnji CooperIf the argument is NULL, nothing is done.
65b077aed3SPierre Pronchery
66b077aed3SPierre ProncheryOSSL_DECODER_get0_provider() returns the provider of the given
67b077aed3SPierre ProncheryI<decoder>.
68b077aed3SPierre Pronchery
69b077aed3SPierre ProncheryOSSL_DECODER_get0_properties() returns the property definition associated
70b077aed3SPierre Proncherywith the given I<decoder>.
71b077aed3SPierre Pronchery
72b077aed3SPierre ProncheryOSSL_DECODER_is_a() checks if I<decoder> is an implementation
73b077aed3SPierre Proncheryof an algorithm that's identifiable with I<name>.
74b077aed3SPierre Pronchery
75b077aed3SPierre ProncheryOSSL_DECODER_get0_name() returns the name used to fetch the given I<decoder>.
76b077aed3SPierre Pronchery
77b077aed3SPierre ProncheryOSSL_DECODER_get0_description() returns a description of the I<decoder>, meant
78b077aed3SPierre Proncheryfor display and human consumption.  The description is at the discretion
79b077aed3SPierre Proncheryof the I<decoder> implementation.
80b077aed3SPierre Pronchery
81b077aed3SPierre ProncheryOSSL_DECODER_names_do_all() traverses all names for the given
82b077aed3SPierre ProncheryI<decoder>, and calls I<fn> with each name and I<data> as arguments.
83b077aed3SPierre Pronchery
84b077aed3SPierre ProncheryOSSL_DECODER_do_all_provided() traverses all decoder
85b077aed3SPierre Proncheryimplementations by all activated providers in the library context
86b077aed3SPierre ProncheryI<libctx>, and for each of the implementations, calls I<fn> with the
87b077aed3SPierre Proncheryimplementation method and I<arg> as arguments.
88b077aed3SPierre Pronchery
89b077aed3SPierre ProncheryOSSL_DECODER_gettable_params() returns an L<OSSL_PARAM(3)>
90b077aed3SPierre Proncheryarray of parameter descriptors.
91b077aed3SPierre Pronchery
92b077aed3SPierre ProncheryOSSL_DECODER_get_params() attempts to get parameters specified
93b077aed3SPierre Proncherywith an L<OSSL_PARAM(3)> array I<params>.  Parameters that the
94b077aed3SPierre Proncheryimplementation doesn't recognise should be ignored.
95b077aed3SPierre Pronchery
96b077aed3SPierre Pronchery=head1 RETURN VALUES
97b077aed3SPierre Pronchery
98b077aed3SPierre ProncheryOSSL_DECODER_fetch() returns a pointer to an OSSL_DECODER object,
99b077aed3SPierre Proncheryor NULL on error.
100b077aed3SPierre Pronchery
101b077aed3SPierre ProncheryOSSL_DECODER_up_ref() returns 1 on success, or 0 on error.
102b077aed3SPierre Pronchery
103b077aed3SPierre ProncheryOSSL_DECODER_free() doesn't return any value.
104b077aed3SPierre Pronchery
105b077aed3SPierre ProncheryOSSL_DECODER_get0_provider() returns a pointer to a provider object, or
106b077aed3SPierre ProncheryNULL on error.
107b077aed3SPierre Pronchery
108b077aed3SPierre ProncheryOSSL_DECODER_get0_properties() returns a pointer to a property
109b077aed3SPierre Proncherydefinition string, or NULL on error.
110b077aed3SPierre Pronchery
111b077aed3SPierre ProncheryOSSL_DECODER_is_a() returns 1 if I<decoder> was identifiable,
112b077aed3SPierre Proncheryotherwise 0.
113b077aed3SPierre Pronchery
114b077aed3SPierre ProncheryOSSL_DECODER_get0_name() returns the algorithm name from the provided
115b077aed3SPierre Proncheryimplementation for the given I<decoder>. Note that the I<decoder> may have
116b077aed3SPierre Proncherymultiple synonyms associated with it. In this case the first name from the
117b077aed3SPierre Proncheryalgorithm definition is returned. Ownership of the returned string is retained
118b077aed3SPierre Proncheryby the I<decoder> object and should not be freed by the caller.
119b077aed3SPierre Pronchery
120aa795734SPierre ProncheryOSSL_DECODER_get0_description() returns a pointer to a description, or NULL if
121b077aed3SPierre Proncherythere isn't one.
122b077aed3SPierre Pronchery
123b077aed3SPierre ProncheryOSSL_DECODER_names_do_all() returns 1 if the callback was called for all
124b077aed3SPierre Proncherynames. A return value of 0 means that the callback was not called for any names.
125b077aed3SPierre Pronchery
126b077aed3SPierre Pronchery=head1 NOTES
127b077aed3SPierre Pronchery
128b077aed3SPierre ProncheryOSSL_DECODER_fetch() may be called implicitly by other fetching
129b077aed3SPierre Proncheryfunctions, using the same library context and properties.
130b077aed3SPierre ProncheryAny other API that uses keys will typically do this.
131b077aed3SPierre Pronchery
132b077aed3SPierre Pronchery=head1 EXAMPLES
133b077aed3SPierre Pronchery
134b077aed3SPierre ProncheryTo list all decoders in a provider to a bio_out:
135b077aed3SPierre Pronchery
136b077aed3SPierre Pronchery static void collect_decoders(OSSL_DECODER *decoder, void *stack)
137b077aed3SPierre Pronchery {
138b077aed3SPierre Pronchery     STACK_OF(OSSL_DECODER) *decoder_stack = stack;
139b077aed3SPierre Pronchery
140b077aed3SPierre Pronchery     sk_OSSL_DECODER_push(decoder_stack, decoder);
141b077aed3SPierre Pronchery     OSSL_DECODER_up_ref(decoder);
142b077aed3SPierre Pronchery }
143b077aed3SPierre Pronchery
144b077aed3SPierre Pronchery void print_name(const char *name, void *vdata)
145b077aed3SPierre Pronchery {
146b077aed3SPierre Pronchery     BIO *bio = vdata;
147b077aed3SPierre Pronchery
148b077aed3SPierre Pronchery     BIO_printf(bio, "%s ", name);
149b077aed3SPierre Pronchery }
150b077aed3SPierre Pronchery
151b077aed3SPierre Pronchery
152b077aed3SPierre Pronchery STACK_OF(OSSL_DECODER) *decoders;
153b077aed3SPierre Pronchery int i;
154b077aed3SPierre Pronchery
155b077aed3SPierre Pronchery decoders = sk_OSSL_DECODER_new_null();
156b077aed3SPierre Pronchery
157b077aed3SPierre Pronchery BIO_printf(bio_out, "DECODERs provided by %s:\n", provider);
158b077aed3SPierre Pronchery OSSL_DECODER_do_all_provided(NULL, collect_decoders,
159b077aed3SPierre Pronchery                              decoders);
160b077aed3SPierre Pronchery
161b077aed3SPierre Pronchery for (i = 0; i < sk_OSSL_DECODER_num(decoders); i++) {
162b077aed3SPierre Pronchery     OSSL_DECODER *decoder = sk_OSSL_DECODER_value(decoders, i);
163b077aed3SPierre Pronchery
164b077aed3SPierre Pronchery     if (strcmp(OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(decoder)),
165b077aed3SPierre Pronchery                provider) != 0)
166b077aed3SPierre Pronchery         continue;
167b077aed3SPierre Pronchery
168b077aed3SPierre Pronchery     if (OSSL_DECODER_names_do_all(decoder, print_name, bio_out))
169b077aed3SPierre Pronchery            BIO_printf(bio_out, "\n");
170b077aed3SPierre Pronchery }
171b077aed3SPierre Pronchery sk_OSSL_DECODER_pop_free(decoders, OSSL_DECODER_free);
172b077aed3SPierre Pronchery
173b077aed3SPierre Pronchery=head1 SEE ALSO
174b077aed3SPierre Pronchery
175b077aed3SPierre ProncheryL<provider(7)>, L<OSSL_DECODER_CTX(3)>, L<OSSL_DECODER_from_bio(3)>,
176b077aed3SPierre ProncheryL<OSSL_DECODER_CTX_new_for_pkey(3)>, L<OSSL_LIB_CTX(3)>
177b077aed3SPierre Pronchery
178b077aed3SPierre Pronchery=head1 HISTORY
179b077aed3SPierre Pronchery
180b077aed3SPierre ProncheryThe functions described here were added in OpenSSL 3.0.
181b077aed3SPierre Pronchery
182b077aed3SPierre Pronchery=head1 COPYRIGHT
183b077aed3SPierre Pronchery
184*a7148ab3SEnji CooperCopyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved.
185b077aed3SPierre Pronchery
186b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
187b077aed3SPierre Proncherythis file except in compliance with the License.  You can obtain a copy
188b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at
189b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>.
190b077aed3SPierre Pronchery
191b077aed3SPierre Pronchery=cut
192