OSSL_DECODER_CTX.pod 9.1 KB

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