ASN1_EXTERN_FUNCS.pod 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. =pod
  2. =head1 NAME
  3. ASN1_EXTERN_FUNCS, ASN1_ex_d2i, ASN1_ex_d2i_ex, ASN1_ex_i2d, ASN1_ex_new_func,
  4. ASN1_ex_new_ex_func, ASN1_ex_free_func, ASN1_ex_print_func,
  5. IMPLEMENT_EXTERN_ASN1
  6. - ASN.1 external function support
  7. =head1 SYNOPSIS
  8. #include <openssl/asn1t.h>
  9. typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
  10. const ASN1_ITEM *it, int tag, int aclass, char opt,
  11. ASN1_TLC *ctx);
  12. typedef int ASN1_ex_d2i_ex(ASN1_VALUE **pval, const unsigned char **in, long len,
  13. const ASN1_ITEM *it, int tag, int aclass, char opt,
  14. ASN1_TLC *ctx, OSSL_LIB_CTX *libctx,
  15. const char *propq);
  16. typedef int ASN1_ex_i2d(const ASN1_VALUE **pval, unsigned char **out,
  17. const ASN1_ITEM *it, int tag, int aclass);
  18. typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
  19. typedef int ASN1_ex_new_ex_func(ASN1_VALUE **pval, const ASN1_ITEM *it,
  20. OSSL_LIB_CTX *libctx, const char *propq);
  21. typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
  22. typedef int ASN1_ex_print_func(BIO *out, const ASN1_VALUE **pval,
  23. int indent, const char *fname,
  24. const ASN1_PCTX *pctx);
  25. struct ASN1_EXTERN_FUNCS_st {
  26. void *app_data;
  27. ASN1_ex_new_func *asn1_ex_new;
  28. ASN1_ex_free_func *asn1_ex_free;
  29. ASN1_ex_free_func *asn1_ex_clear;
  30. ASN1_ex_d2i *asn1_ex_d2i;
  31. ASN1_ex_i2d *asn1_ex_i2d;
  32. ASN1_ex_print_func *asn1_ex_print;
  33. ASN1_ex_new_ex_func *asn1_ex_new_ex;
  34. ASN1_ex_d2i_ex *asn1_ex_d2i_ex;
  35. };
  36. typedef struct ASN1_EXTERN_FUNCS_st ASN1_EXTERN_FUNCS;
  37. #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs)
  38. =head1 DESCRIPTION
  39. ASN.1 data structures templates are typically defined in OpenSSL using a series
  40. of macros such as ASN1_SEQUENCE(), ASN1_SEQUENCE_END() and so on. Instead
  41. templates can also be defined based entirely on external functions. These
  42. external functions are called to perform operations such as creating a new
  43. B<ASN1_VALUE> or converting an B<ASN1_VALUE> to or from DER encoding.
  44. The macro IMPLEMENT_EXTERN_ASN1() can be used to create such an externally
  45. defined structure. The name of the structure should be supplied in the I<sname>
  46. parameter. The tag for the structure (e.g. typically B<V_ASN1_SEQUENCE>) should
  47. be supplied in the I<tag> parameter. Finally a pointer to an
  48. B<ASN1_EXTERN_FUNCS> structure should be supplied in the I<fptrs> parameter.
  49. The B<ASN1_EXTERN_FUNCS> structure has the following entries.
  50. =over 4
  51. =item I<app_data>
  52. A pointer to arbitrary application specific data.
  53. =item I<asn1_ex_new>
  54. A "new" function responsible for constructing a new B<ASN1_VALUE> object. The
  55. newly constructed value should be stored in I<*pval>. The I<it> parameter is a
  56. pointer to the B<ASN1_ITEM> template object created via the
  57. IMPLEMENT_EXTERN_ASN1() macro.
  58. Returns a positive value on success or 0 on error.
  59. =item I<asn1_ex_free>
  60. A "free" function responsible for freeing the B<ASN1_VALUE> passed in I<*pval>
  61. that was previously allocated via a "new" function. The I<it> parameter is a
  62. pointer to the B<ASN1_ITEM> template object created via the
  63. IMPLEMENT_EXTERN_ASN1() macro.
  64. =item I<asn1_ex_clear>
  65. A "clear" function responsible for clearing any data in the B<ASN1_VALUE> passed
  66. in I<*pval> and making it suitable for reuse. The I<it> parameter is a pointer
  67. to the B<ASN1_ITEM> template object created via the IMPLEMENT_EXTERN_ASN1()
  68. macro.
  69. =item I<asn1_ex_d2i>
  70. A "d2i" function responsible for converting DER data with the tag I<tag> and
  71. class I<class> into an B<ASN1_VALUE>. If I<*pval> is non-NULL then the
  72. B<ASN_VALUE> it points to should be reused. Otherwise a new B<ASN1_VALUE>
  73. should be allocated and stored in I<*pval>. I<*in> points to the DER data to be
  74. decoded and I<len> is the length of that data. After decoding I<*in> should be
  75. updated to point at the next byte after the decoded data. If the B<ASN1_VALUE>
  76. is considered optional in this context then I<opt> will be nonzero. Otherwise
  77. it will be zero. The I<it> parameter is a pointer to the B<ASN1_ITEM> template
  78. object created via the IMPLEMENT_EXTERN_ASN1() macro. A pointer to the current
  79. B<ASN1_TLC> context (which may be required for other ASN1 function calls) is
  80. passed in the I<ctx> parameter.
  81. The I<asn1_ex_d2i> entry may be NULL if I<asn1_ex_d2i_ex> has been specified
  82. instead.
  83. Returns <= 0 on error or a positive value on success.
  84. =item I<asn1_ex_i2d>
  85. An "i2d" function responsible for converting an B<ASN1_VALUE> into DER encoding.
  86. On entry I<*pval> will contain the B<ASN1_VALUE> to be encoded. If default
  87. tagging is to be used then I<tag> will be -1 on entry. Otherwise if implicit
  88. tagging should be used then I<tag> and I<aclass> will be the tag and associated
  89. class.
  90. If I<out> is not NULL then this function should write the DER encoded data to
  91. the buffer in I<*out>, and then increment I<*out> to point to immediately after
  92. the data just written.
  93. If I<out> is NULL then no data should be written but the length calculated and
  94. returned as if it were.
  95. The I<asn1_ex_i2d> entry may be NULL if I<asn1_ex_i2d_ex> has been specified
  96. instead.
  97. The return value should be negative if a fatal error occurred, or 0 if a
  98. non-fatal error occurred. Otherwise it should return the length of the encoded
  99. data.
  100. =item I<asn1_ex_print>
  101. A "print" function. I<out> is the BIO to print the output to. I<*pval> is the
  102. B<ASN1_VALUE> to be printed. I<indent> is the number of spaces of indenting to
  103. be printed before any data is printed. I<fname> is currently unused and is
  104. always "". I<pctx> is a pointer to the B<ASN1_PCTX> for the print operation.
  105. Returns 0 on error or a positive value on success. If the return value is 2 then
  106. an additional newline will be printed after the data printed by this function.
  107. =item I<asn1_ex_new_ex>
  108. This is the same as I<asn1_ex_new> except that it is additionally passed the
  109. OSSL_LIB_CTX to be used in I<libctx> and any property query string to be used
  110. for algorithm fetching in the I<propq> parameter. See
  111. L<crypto(7)/ALGORITHM FETCHING> for further details. If I<asn1_ex_new_ex> is
  112. non NULL, then it will always be called in preference to I<asn1_ex_new>.
  113. =item I<asn1_ex_d2i_ex>
  114. This is the same as I<asn1_ex_d2i> except that it is additionally passed the
  115. OSSL_LIB_CTX to be used in I<libctx> and any property query string to be used
  116. for algorithm fetching in the I<propq> parameter. See
  117. L<crypto(7)/ALGORITHM FETCHING> for further details. If I<asn1_ex_d2i_ex> is
  118. non NULL, then it will always be called in preference to I<asn1_ex_d2i>.
  119. =back
  120. =head1 RETURN VALUES
  121. Return values for the various callbacks are as described above.
  122. =head1 SEE ALSO
  123. L<ASN1_item_new_ex(3)>
  124. =head1 HISTORY
  125. The I<asn1_ex_new_ex> and I<asn1_ex_d2i_ex> callbacks were added in OpenSSL 3.0.
  126. =head1 COPYRIGHT
  127. Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
  128. Licensed under the Apache License 2.0 (the "License"). You may not use
  129. this file except in compliance with the License. You can obtain a copy
  130. in the file LICENSE in the source distribution or at
  131. L<https://www.openssl.org/source/license.html>.
  132. =cut