2
0

OSSL_DECODER_CTX.pod 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. OSSL_DECODER_CTX_add_decoder() populates the B<OSSL_DECODER_CTX> I<ctx> with
  108. a decoder, to be used to attempt to decode some encoded input.
  109. OSSL_DECODER_CTX_add_extra() finds decoders that generate input for already
  110. added decoders, and adds them as well. This is used to build decoder
  111. chains.
  112. OSSL_DECODER_CTX_set_input_type() sets the starting input type. This limits
  113. the decoder chains to be considered, as explained in the general description
  114. above.
  115. OSSL_DECODER_CTX_set_input_structure() sets the name of the structure that
  116. the input is expected to have. This may be used to determines what decoder
  117. implementations may be used. NULL is a valid input structure, when it's not
  118. relevant, or when the decoder implementations are expected to figure it out.
  119. OSSL_DECODER_CTX_get_num_decoders() gets the number of decoders currently
  120. added to the context I<ctx>.
  121. OSSL_DECODER_CTX_set_construct() sets the constructor I<construct>.
  122. OSSL_DECODER_CTX_set_construct_data() sets the constructor data that is
  123. passed to the constructor every time it's called.
  124. OSSL_DECODER_CTX_set_cleanup() sets the constructor data I<cleanup>
  125. function. This is called by L<OSSL_DECODER_CTX_free(3)>.
  126. OSSL_DECODER_CTX_get_construct(), OSSL_DECODER_CTX_get_construct_data() and
  127. OSSL_DECODER_CTX_get_cleanup() return the values that have been set by
  128. OSSL_DECODER_CTX_set_construct(), OSSL_DECODER_CTX_set_construct_data() and
  129. OSSL_DECODER_CTX_set_cleanup() respectively.
  130. OSSL_DECODER_export() is a fallback function for constructors that cannot
  131. use the data they get directly for diverse reasons. It takes the same
  132. decode instance I<decoder_inst> that the constructor got and an object
  133. I<reference>, unpacks the object which it refers to, and exports it by
  134. creating an L<OSSL_PARAM(3)> array that it then passes to I<export_cb>,
  135. along with I<export_arg>.
  136. =head2 Constructor
  137. A B<OSSL_DECODER_CONSTRUCT> gets the following arguments:
  138. =over 4
  139. =item I<decoder_inst>
  140. The B<OSSL_DECODER_INSTANCE> for the decoder from which the constructor gets
  141. its data.
  142. =item I<object>
  143. A provider-native object abstraction produced by the decoder. Further
  144. information on the provider-native object abstraction can be found in
  145. L<provider-object(7)>.
  146. =item I<construct_data>
  147. The pointer that was set with OSSL_DECODE_CTX_set_construct_data().
  148. =back
  149. The constructor is expected to return 1 when the data it receives can be
  150. constructed, otherwise 0.
  151. These utility functions may be used by a constructor:
  152. OSSL_DECODER_INSTANCE_get_decoder() can be used to get the decoder
  153. implementation from a decoder instance I<decoder_inst>.
  154. OSSL_DECODER_INSTANCE_get_decoder_ctx() can be used to get the decoder
  155. implementation's provider context from a decoder instance I<decoder_inst>.
  156. OSSL_DECODER_INSTANCE_get_input_type() can be used to get the decoder
  157. implementation's input type from a decoder instance I<decoder_inst>.
  158. OSSL_DECODER_INSTANCE_get_input_structure() can be used to get the input
  159. structure for the decoder implementation from a decoder instance
  160. I<decoder_inst>.
  161. This may be NULL.
  162. =head1 RETURN VALUES
  163. OSSL_DECODER_CTX_new() returns a pointer to a B<OSSL_DECODER_CTX>, or NULL
  164. if the context structure couldn't be allocated.
  165. OSSL_DECODER_settable_ctx_params() returns an L<OSSL_PARAM(3)> array, or
  166. NULL if none is available.
  167. OSSL_DECODER_CTX_set_params() returns 1 if all recognised parameters were
  168. valid, or 0 if one of them was invalid or caused some other failure in the
  169. implementation.
  170. OSSL_DECODER_CTX_add_decoder(), OSSL_DECODER_CTX_add_extra(),
  171. OSSL_DECODER_CTX_set_construct(), OSSL_DECODER_CTX_set_construct_data() and
  172. OSSL_DECODER_CTX_set_cleanup() return 1 on success, or 0 on failure.
  173. OSSL_DECODER_CTX_get_construct(), OSSL_DECODER_CTX_get_construct_data() and
  174. OSSL_DECODER_CTX_get_cleanup() return the current pointers to the
  175. constructor, the constructor data and the cleanup functions, respectively.
  176. OSSL_DECODER_CTX_num_decoders() returns the current number of decoders. It
  177. returns 0 if I<ctx> is NULL.
  178. OSSL_DECODER_export() returns 1 on success, or 0 on failure.
  179. OSSL_DECODER_INSTANCE_decoder() returns an B<OSSL_DECODER> pointer on
  180. success, or NULL on failure.
  181. OSSL_DECODER_INSTANCE_decoder_ctx() returns a provider context pointer on
  182. success, or NULL on failure.
  183. =head1 SEE ALSO
  184. L<provider(7)>, L<OSSL_DECODER(3)>, L<OSSL_DECODER_from_bio(3)>
  185. =head1 HISTORY
  186. The functions described here were added in OpenSSL 3.0.
  187. =head1 COPYRIGHT
  188. Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
  189. Licensed under the Apache License 2.0 (the "License"). You may not use
  190. this file except in compliance with the License. You can obtain a copy
  191. in the file LICENSE in the source distribution or at
  192. L<https://www.openssl.org/source/license.html>.
  193. =cut