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. 64b077aed3SPierre Pronchery 65b077aed3SPierre ProncheryOSSL_DECODER_get0_provider() returns the provider of the given 66b077aed3SPierre ProncheryI<decoder>. 67b077aed3SPierre Pronchery 68b077aed3SPierre ProncheryOSSL_DECODER_get0_properties() returns the property definition associated 69b077aed3SPierre Proncherywith the given I<decoder>. 70b077aed3SPierre Pronchery 71b077aed3SPierre ProncheryOSSL_DECODER_is_a() checks if I<decoder> is an implementation 72b077aed3SPierre Proncheryof an algorithm that's identifiable with I<name>. 73b077aed3SPierre Pronchery 74b077aed3SPierre ProncheryOSSL_DECODER_get0_name() returns the name used to fetch the given I<decoder>. 75b077aed3SPierre Pronchery 76b077aed3SPierre ProncheryOSSL_DECODER_get0_description() returns a description of the I<decoder>, meant 77b077aed3SPierre Proncheryfor display and human consumption. The description is at the discretion 78b077aed3SPierre Proncheryof the I<decoder> implementation. 79b077aed3SPierre Pronchery 80b077aed3SPierre ProncheryOSSL_DECODER_names_do_all() traverses all names for the given 81b077aed3SPierre ProncheryI<decoder>, and calls I<fn> with each name and I<data> as arguments. 82b077aed3SPierre Pronchery 83b077aed3SPierre ProncheryOSSL_DECODER_do_all_provided() traverses all decoder 84b077aed3SPierre Proncheryimplementations by all activated providers in the library context 85b077aed3SPierre ProncheryI<libctx>, and for each of the implementations, calls I<fn> with the 86b077aed3SPierre Proncheryimplementation method and I<arg> as arguments. 87b077aed3SPierre Pronchery 88b077aed3SPierre ProncheryOSSL_DECODER_gettable_params() returns an L<OSSL_PARAM(3)> 89b077aed3SPierre Proncheryarray of parameter descriptors. 90b077aed3SPierre Pronchery 91b077aed3SPierre ProncheryOSSL_DECODER_get_params() attempts to get parameters specified 92b077aed3SPierre Proncherywith an L<OSSL_PARAM(3)> array I<params>. Parameters that the 93b077aed3SPierre Proncheryimplementation doesn't recognise should be ignored. 94b077aed3SPierre Pronchery 95b077aed3SPierre Pronchery=head1 RETURN VALUES 96b077aed3SPierre Pronchery 97b077aed3SPierre ProncheryOSSL_DECODER_fetch() returns a pointer to an OSSL_DECODER object, 98b077aed3SPierre Proncheryor NULL on error. 99b077aed3SPierre Pronchery 100b077aed3SPierre ProncheryOSSL_DECODER_up_ref() returns 1 on success, or 0 on error. 101b077aed3SPierre Pronchery 102b077aed3SPierre ProncheryOSSL_DECODER_free() doesn't return any value. 103b077aed3SPierre Pronchery 104b077aed3SPierre ProncheryOSSL_DECODER_get0_provider() returns a pointer to a provider object, or 105b077aed3SPierre ProncheryNULL on error. 106b077aed3SPierre Pronchery 107b077aed3SPierre ProncheryOSSL_DECODER_get0_properties() returns a pointer to a property 108b077aed3SPierre Proncherydefinition string, or NULL on error. 109b077aed3SPierre Pronchery 110b077aed3SPierre ProncheryOSSL_DECODER_is_a() returns 1 if I<decoder> was identifiable, 111b077aed3SPierre Proncheryotherwise 0. 112b077aed3SPierre Pronchery 113b077aed3SPierre ProncheryOSSL_DECODER_get0_name() returns the algorithm name from the provided 114b077aed3SPierre Proncheryimplementation for the given I<decoder>. Note that the I<decoder> may have 115b077aed3SPierre Proncherymultiple synonyms associated with it. In this case the first name from the 116b077aed3SPierre Proncheryalgorithm definition is returned. Ownership of the returned string is retained 117b077aed3SPierre Proncheryby the I<decoder> object and should not be freed by the caller. 118b077aed3SPierre Pronchery 119*aa795734SPierre ProncheryOSSL_DECODER_get0_description() returns a pointer to a description, or NULL if 120b077aed3SPierre Proncherythere isn't one. 121b077aed3SPierre Pronchery 122b077aed3SPierre ProncheryOSSL_DECODER_names_do_all() returns 1 if the callback was called for all 123b077aed3SPierre Proncherynames. A return value of 0 means that the callback was not called for any names. 124b077aed3SPierre Pronchery 125b077aed3SPierre Pronchery=head1 NOTES 126b077aed3SPierre Pronchery 127b077aed3SPierre ProncheryOSSL_DECODER_fetch() may be called implicitly by other fetching 128b077aed3SPierre Proncheryfunctions, using the same library context and properties. 129b077aed3SPierre ProncheryAny other API that uses keys will typically do this. 130b077aed3SPierre Pronchery 131b077aed3SPierre Pronchery=head1 EXAMPLES 132b077aed3SPierre Pronchery 133b077aed3SPierre ProncheryTo list all decoders in a provider to a bio_out: 134b077aed3SPierre Pronchery 135b077aed3SPierre Pronchery static void collect_decoders(OSSL_DECODER *decoder, void *stack) 136b077aed3SPierre Pronchery { 137b077aed3SPierre Pronchery STACK_OF(OSSL_DECODER) *decoder_stack = stack; 138b077aed3SPierre Pronchery 139b077aed3SPierre Pronchery sk_OSSL_DECODER_push(decoder_stack, decoder); 140b077aed3SPierre Pronchery OSSL_DECODER_up_ref(decoder); 141b077aed3SPierre Pronchery } 142b077aed3SPierre Pronchery 143b077aed3SPierre Pronchery void print_name(const char *name, void *vdata) 144b077aed3SPierre Pronchery { 145b077aed3SPierre Pronchery BIO *bio = vdata; 146b077aed3SPierre Pronchery 147b077aed3SPierre Pronchery BIO_printf(bio, "%s ", name); 148b077aed3SPierre Pronchery } 149b077aed3SPierre Pronchery 150b077aed3SPierre Pronchery 151b077aed3SPierre Pronchery STACK_OF(OSSL_DECODER) *decoders; 152b077aed3SPierre Pronchery int i; 153b077aed3SPierre Pronchery 154b077aed3SPierre Pronchery decoders = sk_OSSL_DECODER_new_null(); 155b077aed3SPierre Pronchery 156b077aed3SPierre Pronchery BIO_printf(bio_out, "DECODERs provided by %s:\n", provider); 157b077aed3SPierre Pronchery OSSL_DECODER_do_all_provided(NULL, collect_decoders, 158b077aed3SPierre Pronchery decoders); 159b077aed3SPierre Pronchery 160b077aed3SPierre Pronchery for (i = 0; i < sk_OSSL_DECODER_num(decoders); i++) { 161b077aed3SPierre Pronchery OSSL_DECODER *decoder = sk_OSSL_DECODER_value(decoders, i); 162b077aed3SPierre Pronchery 163b077aed3SPierre Pronchery if (strcmp(OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(decoder)), 164b077aed3SPierre Pronchery provider) != 0) 165b077aed3SPierre Pronchery continue; 166b077aed3SPierre Pronchery 167b077aed3SPierre Pronchery if (OSSL_DECODER_names_do_all(decoder, print_name, bio_out)) 168b077aed3SPierre Pronchery BIO_printf(bio_out, "\n"); 169b077aed3SPierre Pronchery } 170b077aed3SPierre Pronchery sk_OSSL_DECODER_pop_free(decoders, OSSL_DECODER_free); 171b077aed3SPierre Pronchery 172b077aed3SPierre Pronchery=head1 SEE ALSO 173b077aed3SPierre Pronchery 174b077aed3SPierre ProncheryL<provider(7)>, L<OSSL_DECODER_CTX(3)>, L<OSSL_DECODER_from_bio(3)>, 175b077aed3SPierre ProncheryL<OSSL_DECODER_CTX_new_for_pkey(3)>, L<OSSL_LIB_CTX(3)> 176b077aed3SPierre Pronchery 177b077aed3SPierre Pronchery=head1 HISTORY 178b077aed3SPierre Pronchery 179b077aed3SPierre ProncheryThe functions described here were added in OpenSSL 3.0. 180b077aed3SPierre Pronchery 181b077aed3SPierre Pronchery=head1 COPYRIGHT 182b077aed3SPierre Pronchery 183*aa795734SPierre ProncheryCopyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved. 184b077aed3SPierre Pronchery 185b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 186b077aed3SPierre Proncherythis file except in compliance with the License. You can obtain a copy 187b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at 188b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>. 189b077aed3SPierre Pronchery 190b077aed3SPierre Pronchery=cut 191