OSSL_DECODER_CTX.pod 10 KB

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