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_CTX, 6 1.1 christos OSSL_DECODER_CTX_new, 7 1.1 christos OSSL_DECODER_settable_ctx_params, 8 1.1 christos OSSL_DECODER_CTX_set_params, 9 1.1 christos OSSL_DECODER_CTX_free, 10 1.1 christos OSSL_DECODER_CTX_set_selection, 11 1.1 christos OSSL_DECODER_CTX_set_input_type, 12 1.1 christos OSSL_DECODER_CTX_set_input_structure, 13 1.1 christos OSSL_DECODER_CTX_add_decoder, 14 1.1 christos OSSL_DECODER_CTX_add_extra, 15 1.1 christos OSSL_DECODER_CTX_get_num_decoders, 16 1.1 christos OSSL_DECODER_INSTANCE, 17 1.1 christos OSSL_DECODER_CONSTRUCT, 18 1.1 christos OSSL_DECODER_CLEANUP, 19 1.1 christos OSSL_DECODER_CTX_set_construct, 20 1.1 christos OSSL_DECODER_CTX_set_construct_data, 21 1.1 christos OSSL_DECODER_CTX_set_cleanup, 22 1.1 christos OSSL_DECODER_CTX_get_construct, 23 1.1 christos OSSL_DECODER_CTX_get_construct_data, 24 1.1 christos OSSL_DECODER_CTX_get_cleanup, 25 1.1 christos OSSL_DECODER_export, 26 1.1 christos OSSL_DECODER_INSTANCE_get_decoder, 27 1.1 christos OSSL_DECODER_INSTANCE_get_decoder_ctx, 28 1.1 christos OSSL_DECODER_INSTANCE_get_input_type, 29 1.1 christos OSSL_DECODER_INSTANCE_get_input_structure 30 1.1 christos - Decoder context routines 31 1.1 christos 32 1.1 christos =head1 SYNOPSIS 33 1.1 christos 34 1.1 christos #include <openssl/decoder.h> 35 1.1 christos 36 1.1 christos typedef struct ossl_decoder_ctx_st OSSL_DECODER_CTX; 37 1.1 christos 38 1.1 christos OSSL_DECODER_CTX *OSSL_DECODER_CTX_new(void); 39 1.1 christos const OSSL_PARAM *OSSL_DECODER_settable_ctx_params(OSSL_DECODER *decoder); 40 1.1 christos int OSSL_DECODER_CTX_set_params(OSSL_DECODER_CTX *ctx, 41 1.1 christos const OSSL_PARAM params[]); 42 1.1 christos void OSSL_DECODER_CTX_free(OSSL_DECODER_CTX *ctx); 43 1.1 christos 44 1.1 christos int OSSL_DECODER_CTX_set_selection(OSSL_DECODER_CTX *ctx, int selection); 45 1.1 christos int OSSL_DECODER_CTX_set_input_type(OSSL_DECODER_CTX *ctx, 46 1.1 christos const char *input_type); 47 1.1 christos int OSSL_DECODER_CTX_set_input_structure(OSSL_DECODER_CTX *ctx, 48 1.1 christos const char *input_structure); 49 1.1 christos int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder); 50 1.1 christos int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx, 51 1.1 christos OSSL_LIB_CTX *libctx, 52 1.1 christos const char *propq); 53 1.1 christos int OSSL_DECODER_CTX_get_num_decoders(OSSL_DECODER_CTX *ctx); 54 1.1 christos 55 1.1 christos typedef struct ossl_decoder_instance_st OSSL_DECODER_INSTANCE; 56 1.1 christos OSSL_DECODER * 57 1.1 christos OSSL_DECODER_INSTANCE_get_decoder(OSSL_DECODER_INSTANCE *decoder_inst); 58 1.1 christos void * 59 1.1 christos OSSL_DECODER_INSTANCE_get_decoder_ctx(OSSL_DECODER_INSTANCE *decoder_inst); 60 1.1 christos const char * 61 1.1 christos OSSL_DECODER_INSTANCE_get_input_type(OSSL_DECODER_INSTANCE *decoder_inst); 62 1.1 christos OSSL_DECODER_INSTANCE_get_input_structure(OSSL_DECODER_INSTANCE *decoder_inst, 63 1.1 christos int *was_set); 64 1.1 christos 65 1.1 christos typedef int OSSL_DECODER_CONSTRUCT(OSSL_DECODER_INSTANCE *decoder_inst, 66 1.1 christos const OSSL_PARAM *object, 67 1.1 christos void *construct_data); 68 1.1 christos typedef void OSSL_DECODER_CLEANUP(void *construct_data); 69 1.1 christos 70 1.1 christos int OSSL_DECODER_CTX_set_construct(OSSL_DECODER_CTX *ctx, 71 1.1 christos OSSL_DECODER_CONSTRUCT *construct); 72 1.1 christos int OSSL_DECODER_CTX_set_construct_data(OSSL_DECODER_CTX *ctx, 73 1.1 christos void *construct_data); 74 1.1 christos int OSSL_DECODER_CTX_set_cleanup(OSSL_DECODER_CTX *ctx, 75 1.1 christos OSSL_DECODER_CLEANUP *cleanup); 76 1.1 christos OSSL_DECODER_CONSTRUCT *OSSL_DECODER_CTX_get_construct(OSSL_DECODER_CTX *ctx); 77 1.1 christos void *OSSL_DECODER_CTX_get_construct_data(OSSL_DECODER_CTX *ctx); 78 1.1 christos OSSL_DECODER_CLEANUP *OSSL_DECODER_CTX_get_cleanup(OSSL_DECODER_CTX *ctx); 79 1.1 christos 80 1.1 christos int OSSL_DECODER_export(OSSL_DECODER_INSTANCE *decoder_inst, 81 1.1 christos void *reference, size_t reference_sz, 82 1.1 christos OSSL_CALLBACK *export_cb, void *export_cbarg); 83 1.1 christos 84 1.1 christos =head1 DESCRIPTION 85 1.1 christos 86 1.1 christos The B<OSSL_DECODER_CTX> holds data about multiple decoders, as needed to 87 1.1 christos figure out what the input data is and to attempt to unpack it into one of 88 1.1 christos several possible related results. This also includes chaining decoders, so 89 1.1 christos the output from one can become the input for another. This allows having 90 1.1 christos generic format decoders such as PEM to DER, as well as more specialized 91 1.1 christos decoders like DER to RSA. 92 1.1 christos 93 1.1 christos The chains may be limited by specifying an input type, which is considered a 94 1.1 christos starting point. This is both considered by OSSL_DECODER_CTX_add_extra(), 95 1.1 christos which will stop adding one more decoder implementations when it has already 96 1.1 christos added those that take the specified input type, and functions like 97 1.1 christos L<OSSL_DECODER_from_bio(3)>, which will only start the decoding process with 98 1.1 christos the decoder implementations that take that input type. For example, if the 99 1.1 christos input type is set to C<DER>, a PEM to DER decoder will be ignored. 100 1.1 christos 101 1.1 christos The input type can also be NULL, which means that the caller doesn't know 102 1.1 christos what type of input they have. In this case, OSSL_DECODER_from_bio() will 103 1.1 christos simply try with one decoder implementation after the other, and thereby 104 1.1 christos discover what kind of input the caller gave it. 105 1.1 christos 106 1.1 christos For every decoding done, even an intermediary one, a constructor provided by 107 1.1 christos the caller is called to attempt to construct an appropriate type / structure 108 1.1 christos that the caller knows how to handle from the current decoding result. 109 1.1 christos The constructor is set with OSSL_DECODER_CTX_set_construct(). 110 1.1 christos 111 1.1 christos B<OSSL_DECODER_INSTANCE> is an opaque structure that contains data about the 112 1.1 christos decoder that was just used, and that may be useful for the constructor. 113 1.1 christos There are some functions to extract data from this type, described further 114 1.1 christos down. 115 1.1 christos 116 1.1 christos =head2 Functions 117 1.1 christos 118 1.1 christos OSSL_DECODER_CTX_new() creates a new empty B<OSSL_DECODER_CTX>. 119 1.1 christos 120 1.1 christos OSSL_DECODER_settable_ctx_params() returns an L<OSSL_PARAM(3)> array of 121 1.1 christos parameter descriptors. 122 1.1 christos 123 1.1 christos OSSL_DECODER_CTX_set_params() attempts to set parameters specified with an 124 1.1 christos L<OSSL_PARAM(3)> array I<params>. These parameters are passed to all 125 1.1 christos decoders that have been added to the I<ctx> so far. Parameters that an 126 1.1 christos implementation doesn't recognise should be ignored by it. 127 1.1 christos 128 1.1 christos OSSL_DECODER_CTX_free() frees the given context I<ctx>. 129 1.1.1.2 christos If the argument is NULL, nothing is done. 130 1.1 christos 131 1.1 christos OSSL_DECODER_CTX_add_decoder() populates the B<OSSL_DECODER_CTX> I<ctx> with 132 1.1 christos a decoder, to be used to attempt to decode some encoded input. 133 1.1 christos 134 1.1 christos OSSL_DECODER_CTX_add_extra() finds decoders that generate input for already 135 1.1 christos added decoders, and adds them as well. This is used to build decoder 136 1.1 christos chains. 137 1.1 christos 138 1.1 christos OSSL_DECODER_CTX_set_input_type() sets the starting input type. This limits 139 1.1 christos the decoder chains to be considered, as explained in the general description 140 1.1 christos above. 141 1.1 christos 142 1.1 christos OSSL_DECODER_CTX_set_input_structure() sets the name of the structure that 143 1.1 christos the input is expected to have. This may be used to determines what decoder 144 1.1 christos implementations may be used. NULL is a valid input structure, when it's not 145 1.1 christos relevant, or when the decoder implementations are expected to figure it out. 146 1.1 christos 147 1.1 christos OSSL_DECODER_CTX_get_num_decoders() gets the number of decoders currently 148 1.1 christos added to the context I<ctx>. 149 1.1 christos 150 1.1 christos OSSL_DECODER_CTX_set_construct() sets the constructor I<construct>. 151 1.1 christos 152 1.1 christos OSSL_DECODER_CTX_set_construct_data() sets the constructor data that is 153 1.1 christos passed to the constructor every time it's called. 154 1.1 christos 155 1.1 christos OSSL_DECODER_CTX_set_cleanup() sets the constructor data I<cleanup> 156 1.1 christos function. This is called by L<OSSL_DECODER_CTX_free(3)>. 157 1.1 christos 158 1.1 christos OSSL_DECODER_CTX_get_construct(), OSSL_DECODER_CTX_get_construct_data() and 159 1.1 christos OSSL_DECODER_CTX_get_cleanup() return the values that have been set by 160 1.1 christos OSSL_DECODER_CTX_set_construct(), OSSL_DECODER_CTX_set_construct_data() and 161 1.1 christos OSSL_DECODER_CTX_set_cleanup() respectively. 162 1.1 christos 163 1.1 christos OSSL_DECODER_export() is a fallback function for constructors that cannot 164 1.1 christos use the data they get directly for diverse reasons. It takes the same 165 1.1 christos decode instance I<decoder_inst> that the constructor got and an object 166 1.1 christos I<reference>, unpacks the object which it refers to, and exports it by 167 1.1 christos creating an L<OSSL_PARAM(3)> array that it then passes to I<export_cb>, 168 1.1 christos along with I<export_arg>. 169 1.1 christos 170 1.1 christos =head2 Constructor 171 1.1 christos 172 1.1 christos A B<OSSL_DECODER_CONSTRUCT> gets the following arguments: 173 1.1 christos 174 1.1 christos =over 4 175 1.1 christos 176 1.1 christos =item I<decoder_inst> 177 1.1 christos 178 1.1 christos The B<OSSL_DECODER_INSTANCE> for the decoder from which the constructor gets 179 1.1 christos its data. 180 1.1 christos 181 1.1 christos =item I<object> 182 1.1 christos 183 1.1 christos A provider-native object abstraction produced by the decoder. Further 184 1.1 christos information on the provider-native object abstraction can be found in 185 1.1 christos L<provider-object(7)>. 186 1.1 christos 187 1.1 christos =item I<construct_data> 188 1.1 christos 189 1.1 christos The pointer that was set with OSSL_DECODE_CTX_set_construct_data(). 190 1.1 christos 191 1.1 christos =back 192 1.1 christos 193 1.1 christos The constructor is expected to return 1 when the data it receives can be 194 1.1 christos constructed, otherwise 0. 195 1.1 christos 196 1.1 christos These utility functions may be used by a constructor: 197 1.1 christos 198 1.1 christos OSSL_DECODER_INSTANCE_get_decoder() can be used to get the decoder 199 1.1 christos implementation from a decoder instance I<decoder_inst>. 200 1.1 christos 201 1.1 christos OSSL_DECODER_INSTANCE_get_decoder_ctx() can be used to get the decoder 202 1.1 christos implementation's provider context from a decoder instance I<decoder_inst>. 203 1.1 christos 204 1.1 christos OSSL_DECODER_INSTANCE_get_input_type() can be used to get the decoder 205 1.1 christos implementation's input type from a decoder instance I<decoder_inst>. 206 1.1 christos 207 1.1 christos OSSL_DECODER_INSTANCE_get_input_structure() can be used to get the input 208 1.1 christos structure for the decoder implementation from a decoder instance 209 1.1 christos I<decoder_inst>. 210 1.1 christos This may be NULL. 211 1.1 christos 212 1.1 christos =head1 RETURN VALUES 213 1.1 christos 214 1.1 christos OSSL_DECODER_CTX_new() returns a pointer to a B<OSSL_DECODER_CTX>, or NULL 215 1.1 christos if the context structure couldn't be allocated. 216 1.1 christos 217 1.1 christos OSSL_DECODER_settable_ctx_params() returns an L<OSSL_PARAM(3)> array, or 218 1.1 christos NULL if none is available. 219 1.1 christos 220 1.1 christos OSSL_DECODER_CTX_set_params() returns 1 if all recognised parameters were 221 1.1 christos valid, or 0 if one of them was invalid or caused some other failure in the 222 1.1 christos implementation. 223 1.1 christos 224 1.1 christos OSSL_DECODER_CTX_add_decoder(), OSSL_DECODER_CTX_add_extra(), 225 1.1 christos OSSL_DECODER_CTX_set_construct(), OSSL_DECODER_CTX_set_construct_data() and 226 1.1 christos OSSL_DECODER_CTX_set_cleanup() return 1 on success, or 0 on failure. 227 1.1 christos 228 1.1 christos OSSL_DECODER_CTX_get_construct(), OSSL_DECODER_CTX_get_construct_data() and 229 1.1 christos OSSL_DECODER_CTX_get_cleanup() return the current pointers to the 230 1.1 christos constructor, the constructor data and the cleanup functions, respectively. 231 1.1 christos 232 1.1 christos OSSL_DECODER_CTX_num_decoders() returns the current number of decoders. It 233 1.1 christos returns 0 if I<ctx> is NULL. 234 1.1 christos 235 1.1 christos OSSL_DECODER_export() returns 1 on success, or 0 on failure. 236 1.1 christos 237 1.1 christos OSSL_DECODER_INSTANCE_decoder() returns an B<OSSL_DECODER> pointer on 238 1.1 christos success, or NULL on failure. 239 1.1 christos 240 1.1 christos OSSL_DECODER_INSTANCE_decoder_ctx() returns a provider context pointer on 241 1.1 christos success, or NULL on failure. 242 1.1 christos 243 1.1 christos =head1 SEE ALSO 244 1.1 christos 245 1.1 christos L<provider(7)>, L<OSSL_DECODER(3)>, L<OSSL_DECODER_from_bio(3)> 246 1.1 christos 247 1.1 christos =head1 HISTORY 248 1.1 christos 249 1.1 christos The functions described here were added in OpenSSL 3.0. 250 1.1 christos 251 1.1 christos =head1 COPYRIGHT 252 1.1 christos 253 1.1.1.2 christos Copyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved. 254 1.1 christos 255 1.1 christos Licensed under the Apache License 2.0 (the "License"). You may not use 256 1.1 christos this file except in compliance with the License. You can obtain a copy 257 1.1 christos in the file LICENSE in the source distribution or at 258 1.1 christos L<https://www.openssl.org/source/license.html>. 259 1.1 christos 260 1.1 christos =cut 261