OSSL_DECODER_CTX.pod 10 KB

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