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