2
0

ASN1_aux_cb.pod 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. =pod
  2. =head1 NAME
  3. ASN1_AUX, ASN1_PRINT_ARG, ASN1_STREAM_ARG, ASN1_aux_cb, ASN1_aux_const_cb
  4. - ASN.1 auxiliary data
  5. =head1 SYNOPSIS
  6. #include <openssl/asn1t.h>
  7. struct ASN1_AUX_st {
  8. void *app_data;
  9. int flags;
  10. int ref_offset; /* Offset of reference value */
  11. int ref_lock; /* Offset to an CRYPTO_RWLOCK */
  12. ASN1_aux_cb *asn1_cb;
  13. int enc_offset; /* Offset of ASN1_ENCODING structure */
  14. ASN1_aux_const_cb *asn1_const_cb; /* for ASN1_OP_I2D_ and ASN1_OP_PRINT_ */
  15. };
  16. typedef struct ASN1_AUX_st ASN1_AUX;
  17. struct ASN1_PRINT_ARG_st {
  18. BIO *out;
  19. int indent;
  20. const ASN1_PCTX *pctx;
  21. };
  22. typedef struct ASN1_PRINT_ARG_st ASN1_PRINT_ARG;
  23. struct ASN1_STREAM_ARG_st {
  24. BIO *out;
  25. BIO *ndef_bio;
  26. unsigned char **boundary;
  27. };
  28. typedef struct ASN1_STREAM_ARG_st ASN1_STREAM_ARG;
  29. typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it,
  30. void *exarg);
  31. typedef int ASN1_aux_const_cb(int operation, const ASN1_VALUE **in,
  32. const ASN1_ITEM *it, void *exarg);
  33. =head1 DESCRIPTION
  34. ASN.1 data structures can be associated with an B<ASN1_AUX> object to supply
  35. additional information about the ASN.1 structure. An B<ASN1_AUX> structure is
  36. associated with the structure during the definition of the ASN.1 template. For
  37. example an B<ASN1_AUX> structure will be associated by using one of the various
  38. ASN.1 template definition macros that supply auxiliary information such as
  39. ASN1_SEQUENCE_enc(), ASN1_SEQUENCE_ref(), ASN1_SEQUENCE_cb_const_cb(),
  40. ASN1_SEQUENCE_const_cb(), ASN1_SEQUENCE_cb() or ASN1_NDEF_SEQUENCE_cb().
  41. An B<ASN1_AUX> structure contains the following information.
  42. =over 4
  43. =item I<app_data>
  44. Arbitrary application data
  45. =item I<flags>
  46. Flags which indicate the auxiliarly functionality supported.
  47. The B<ASN1_AFLG_REFCOUNT> flag indicates that objects support reference counting.
  48. The B<ASN1_AFLG_ENCODING> flag indicates that the original encoding of the
  49. object will be saved.
  50. The B<ASN1_AFLG_BROKEN> flag is a work around for broken encoders where the
  51. sequence length value may not be correct. This should generally not be used.
  52. The B<ASN1_AFLG_CONST_CB> flag indicates that the "const" form of the
  53. B<ASN1_AUX> callback should be used in preference to the non-const form.
  54. =item I<ref_offset>
  55. If the B<ASN1_AFLG_REFCOUNT> flag is set then this value is assumed to be an
  56. offset into the B<ASN1_VALUE> structure where a B<CRYPTO_REF_COUNT> may be
  57. found for the purposes of reference counting.
  58. =item I<ref_lock>
  59. If the B<ASN1_AFLG_REFCOUNT> flag is set then this value is assumed to be an
  60. offset into the B<ASN1_VALUE> structure where a B<CRYPTO_RWLOCK> may be
  61. found for the purposes of reference counting.
  62. =item I<asn1_cb>
  63. A callback that will be invoked at various points during the processing of
  64. the the B<ASN1_VALLUE>. See below for further details.
  65. =item I<enc_offset>
  66. Offset into the B<ASN1_VALUE> object where the original encoding of the object
  67. will be saved if the B<ASN1_AFLG_ENCODING> flag has been set.
  68. =item I<asn1_const_cb>
  69. A callback that will be invoked at various points during the processing of
  70. the the B<ASN1_VALLUE>. This is used in preference to the I<asn1_cb> callback if
  71. the B<ASN1_AFLG_CONST_CB> flag is set. See below for further details.
  72. =back
  73. During the processing of an B<ASN1_VALUE> object the callbacks set via
  74. I<asn1_cb> or I<asn1_const_cb> will be invoked as a result of various events
  75. indicated via the I<operation> parameter. The value of I<*in> will be the
  76. B<ASN1_VALUE> object being processed based on the template in I<it>. An
  77. additional operation specific parameter may be passed in I<exarg>. The currently
  78. supported operations are as follows. The callbacks should return a positive
  79. value on success or zero on error, unless otherwise noted below.
  80. =over 4
  81. =item B<ASN1_OP_NEW_PRE>
  82. Invoked when processing a B<CHOICE>, B<SEQUENCE> or B<NDEF_SEQUENCE> structure
  83. prior to an B<ASN1_VALUE> object being allocated. The callback may allocate the
  84. B<ASN1_VALUE> itself and store it in I<*pval>. If it does so it should return 2
  85. from the callback. On error it should return 0.
  86. =item B<ASN1_OP_NEW_POST>
  87. Invoked when processing a B<CHOICE>, B<SEQUENCE> or B<NDEF_SEQUENCE> structure
  88. after an B<ASN1_VALUE> object has been allocated. The allocated object is in
  89. I<*pval>.
  90. =item B<ASN1_OP_FREE_PRE>
  91. Invoked when processing a B<CHOICE>, B<SEQUENCE> or B<NDEF_SEQUENCE> structure
  92. immediately before an B<ASN1_VALUE> is freed. If the callback originally
  93. constructed the B<ASN1_VALUE> via B<ASN1_OP_NEW_PRE> then it should free it at
  94. this point and return 2 from the callback. Otherwise it should return 1 for
  95. success or 0 on error.
  96. =item B<ASN1_OP_FREE_POST>
  97. Invoked when processing a B<CHOICE>, B<SEQUENCE> or B<NDEF_SEQUENCE> structure
  98. immediately after B<ASN1_VALUE> sub-structures are freed.
  99. =item B<ASN1_OP_D2I_PRE>
  100. Invoked when processing a B<CHOICE>, B<SEQUENCE> or B<NDEF_SEQUENCE> structure
  101. immediately before a "d2i" operation for the B<ASN1_VALUE>.
  102. =item B<ASN1_OP_D2I_POST>
  103. Invoked when processing a B<CHOICE>, B<SEQUENCE> or B<NDEF_SEQUENCE> structure
  104. immediately after a "d2i" operation for the B<ASN1_VALUE>.
  105. =item B<ASN1_OP_I2D_PRE>
  106. Invoked when processing a B<CHOICE>, B<SEQUENCE> or B<NDEF_SEQUENCE> structure
  107. immediately before a "i2d" operation for the B<ASN1_VALUE>.
  108. =item B<ASN1_OP_I2D_POST>
  109. Invoked when processing a B<CHOICE>, B<SEQUENCE> or B<NDEF_SEQUENCE> structure
  110. immediately after a "i2d" operation for the B<ASN1_VALUE>.
  111. =item B<ASN1_OP_PRINT_PRE>
  112. Invoked when processing a B<SEQUENCE> or B<NDEF_SEQUENCE> structure immediately
  113. before printing the B<ASN1_VALUE>. The I<exarg> argument will be a pointer to an
  114. B<ASN1_PRINT_ARG> structure (see below).
  115. =item B<ASN1_OP_PRINT_POST>
  116. Invoked when processing a B<SEQUENCE> or B<NDEF_SEQUENCE> structure immediately
  117. after printing the B<ASN1_VALUE>. The I<exarg> argument will be a pointer to an
  118. B<ASN1_PRINT_ARG> structure (see below).
  119. =item B<ASN1_OP_STREAM_PRE>
  120. Invoked immediately prior to streaming the B<ASN1_VALUE> data using indefinite
  121. length encoding. The I<exarg> argument will be a pointer to a B<ASN1_STREAM_ARG>
  122. structure (see below).
  123. =item B<ASN1_OP_STREAM_POST>
  124. Invoked immediately after streaming the B<ASN1_VALUE> data using indefinite
  125. length encoding. The I<exarg> argument will be a pointer to a B<ASN1_STREAM_ARG>
  126. structure (see below).
  127. =item B<ASN1_OP_DETACHED_PRE>
  128. Invoked immediately prior to processing the B<ASN1_VALUE> data as a "detached"
  129. value (as used in CMS and PKCS7). The I<exarg> argument will be a pointer to a
  130. B<ASN1_STREAM_ARG> structure (see below).
  131. =item B<ASN1_OP_DETACHED_POST>
  132. Invoked immediately after processing the B<ASN1_VALUE> data as a "detached"
  133. value (as used in CMS and PKCS7). The I<exarg> argument will be a pointer to a
  134. B<ASN1_STREAM_ARG> structure (see below).
  135. =item B<ASN1_OP_DUP_PRE>
  136. Invoked immediate prior to an ASN1_VALUE being duplicated via a call to
  137. ASN1_item_dup().
  138. =item B<ASN1_OP_DUP_POST>
  139. Invoked immediate after to an ASN1_VALUE has been duplicated via a call to
  140. ASN1_item_dup().
  141. =item B<ASN1_OP_GET0_LIBCTX>
  142. Invoked in order to obtain the B<OSSL_LIB_CTX> associated with an B<ASN1_VALUE>
  143. if any. A pointer to an B<OSSL_LIB_CTX> should be stored in I<*exarg> if such
  144. a value exists.
  145. =item B<ASN1_OP_GET0_PROPQ>
  146. Invoked in order to obtain the property query string associated with an
  147. B<ASN1_VALUE> if any. A pointer to the property query string should be stored in
  148. I<*exarg> if such a value exists.
  149. =back
  150. An B<ASN1_PRINT_ARG> object is used during processing of B<ASN1_OP_PRINT_PRE>
  151. and B<ASN1_OP_PRINT_POST> callback operations. It contains the following
  152. information.
  153. =over 4
  154. =item I<out>
  155. The B<BIO> being used to print the data out.
  156. =item I<ndef_bio>
  157. The current number of indent spaces that should be used for printing this data.
  158. =item I<pctx>
  159. The context for the B<ASN1_PCTX> operation.
  160. =back
  161. An B<ASN1_STREAM_ARG> object is used during processing of B<ASN1_OP_STREAM_PRE>,
  162. B<ASN1_OP_STREAM_POST>, B<ASN1_OP_DETACHED_PRE> and B<ASN1_OP_DETACHED_POST>
  163. callback operations. It contains the following information.
  164. =over 4
  165. =item I<out>
  166. The B<BIO> to stream through
  167. =item I<ndef_bio>
  168. The B<BIO> with filters appended
  169. =item I<boundary>
  170. The streaming I/O boundary.
  171. =back
  172. =head1 RETURN VALUES
  173. The callbacks return 0 on error and a positive value on success. Some operations
  174. require specific positive success values as noted above.
  175. =head1 SEE ALSO
  176. L<ASN1_item_new_ex(3)>
  177. =head1 HISTORY
  178. The ASN1_aux_const_cb() callback and the B<ASN1_OP_GET0_LIBCTX> and
  179. B<ASN1_OP_GET0_PROPQ> operation types were added in OpenSSL 3.0.
  180. =head1 COPYRIGHT
  181. Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
  182. Licensed under the Apache License 2.0 (the "License"). You may not use
  183. this file except in compliance with the License. You can obtain a copy
  184. in the file LICENSE in the source distribution or at
  185. L<https://www.openssl.org/source/license.html>.
  186. =cut