xref: /freebsd/crypto/openssl/doc/man3/ASN1_EXTERN_FUNCS.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1*b077aed3SPierre Pronchery=pod
2*b077aed3SPierre Pronchery
3*b077aed3SPierre Pronchery=head1 NAME
4*b077aed3SPierre Pronchery
5*b077aed3SPierre ProncheryASN1_EXTERN_FUNCS, ASN1_ex_d2i, ASN1_ex_d2i_ex, ASN1_ex_i2d, ASN1_ex_new_func,
6*b077aed3SPierre ProncheryASN1_ex_new_ex_func, ASN1_ex_free_func, ASN1_ex_print_func,
7*b077aed3SPierre ProncheryIMPLEMENT_EXTERN_ASN1
8*b077aed3SPierre Pronchery- ASN.1 external function support
9*b077aed3SPierre Pronchery
10*b077aed3SPierre Pronchery=head1 SYNOPSIS
11*b077aed3SPierre Pronchery
12*b077aed3SPierre Pronchery #include <openssl/asn1t.h>
13*b077aed3SPierre Pronchery
14*b077aed3SPierre Pronchery typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
15*b077aed3SPierre Pronchery                         const ASN1_ITEM *it, int tag, int aclass, char opt,
16*b077aed3SPierre Pronchery                         ASN1_TLC *ctx);
17*b077aed3SPierre Pronchery typedef int ASN1_ex_d2i_ex(ASN1_VALUE **pval, const unsigned char **in, long len,
18*b077aed3SPierre Pronchery                            const ASN1_ITEM *it, int tag, int aclass, char opt,
19*b077aed3SPierre Pronchery                            ASN1_TLC *ctx, OSSL_LIB_CTX *libctx,
20*b077aed3SPierre Pronchery                            const char *propq);
21*b077aed3SPierre Pronchery typedef int ASN1_ex_i2d(const ASN1_VALUE **pval, unsigned char **out,
22*b077aed3SPierre Pronchery                         const ASN1_ITEM *it, int tag, int aclass);
23*b077aed3SPierre Pronchery typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
24*b077aed3SPierre Pronchery typedef int ASN1_ex_new_ex_func(ASN1_VALUE **pval, const ASN1_ITEM *it,
25*b077aed3SPierre Pronchery                                 OSSL_LIB_CTX *libctx, const char *propq);
26*b077aed3SPierre Pronchery typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
27*b077aed3SPierre Pronchery typedef int ASN1_ex_print_func(BIO *out, const ASN1_VALUE **pval,
28*b077aed3SPierre Pronchery                                int indent, const char *fname,
29*b077aed3SPierre Pronchery                                const ASN1_PCTX *pctx);
30*b077aed3SPierre Pronchery
31*b077aed3SPierre Pronchery struct ASN1_EXTERN_FUNCS_st {
32*b077aed3SPierre Pronchery    void *app_data;
33*b077aed3SPierre Pronchery    ASN1_ex_new_func *asn1_ex_new;
34*b077aed3SPierre Pronchery    ASN1_ex_free_func *asn1_ex_free;
35*b077aed3SPierre Pronchery    ASN1_ex_free_func *asn1_ex_clear;
36*b077aed3SPierre Pronchery    ASN1_ex_d2i *asn1_ex_d2i;
37*b077aed3SPierre Pronchery    ASN1_ex_i2d *asn1_ex_i2d;
38*b077aed3SPierre Pronchery    ASN1_ex_print_func *asn1_ex_print;
39*b077aed3SPierre Pronchery    ASN1_ex_new_ex_func *asn1_ex_new_ex;
40*b077aed3SPierre Pronchery    ASN1_ex_d2i_ex *asn1_ex_d2i_ex;
41*b077aed3SPierre Pronchery };
42*b077aed3SPierre Pronchery typedef struct ASN1_EXTERN_FUNCS_st ASN1_EXTERN_FUNCS;
43*b077aed3SPierre Pronchery
44*b077aed3SPierre Pronchery #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs)
45*b077aed3SPierre Pronchery
46*b077aed3SPierre Pronchery=head1 DESCRIPTION
47*b077aed3SPierre Pronchery
48*b077aed3SPierre ProncheryASN.1 data structures templates are typically defined in OpenSSL using a series
49*b077aed3SPierre Proncheryof macros such as ASN1_SEQUENCE(), ASN1_SEQUENCE_END() and so on. Instead
50*b077aed3SPierre Proncherytemplates can also be defined based entirely on external functions. These
51*b077aed3SPierre Proncheryexternal functions are called to perform operations such as creating a new
52*b077aed3SPierre ProncheryB<ASN1_VALUE> or converting an B<ASN1_VALUE> to or from DER encoding.
53*b077aed3SPierre Pronchery
54*b077aed3SPierre ProncheryThe macro IMPLEMENT_EXTERN_ASN1() can be used to create such an externally
55*b077aed3SPierre Proncherydefined structure. The name of the structure should be supplied in the I<sname>
56*b077aed3SPierre Proncheryparameter. The tag for the structure (e.g. typically B<V_ASN1_SEQUENCE>) should
57*b077aed3SPierre Proncherybe supplied in the I<tag> parameter. Finally a pointer to an
58*b077aed3SPierre ProncheryB<ASN1_EXTERN_FUNCS> structure should be supplied in the I<fptrs> parameter.
59*b077aed3SPierre Pronchery
60*b077aed3SPierre ProncheryThe B<ASN1_EXTERN_FUNCS> structure has the following entries.
61*b077aed3SPierre Pronchery
62*b077aed3SPierre Pronchery=over 4
63*b077aed3SPierre Pronchery
64*b077aed3SPierre Pronchery=item I<app_data>
65*b077aed3SPierre Pronchery
66*b077aed3SPierre ProncheryA pointer to arbitrary application specific data.
67*b077aed3SPierre Pronchery
68*b077aed3SPierre Pronchery=item I<asn1_ex_new>
69*b077aed3SPierre Pronchery
70*b077aed3SPierre ProncheryA "new" function responsible for constructing a new B<ASN1_VALUE> object. The
71*b077aed3SPierre Proncherynewly constructed value should be stored in I<*pval>. The I<it> parameter is a
72*b077aed3SPierre Proncherypointer to the B<ASN1_ITEM> template object created via the
73*b077aed3SPierre ProncheryIMPLEMENT_EXTERN_ASN1() macro.
74*b077aed3SPierre Pronchery
75*b077aed3SPierre ProncheryReturns a positive value on success or 0 on error.
76*b077aed3SPierre Pronchery
77*b077aed3SPierre Pronchery=item I<asn1_ex_free>
78*b077aed3SPierre Pronchery
79*b077aed3SPierre ProncheryA "free" function responsible for freeing the B<ASN1_VALUE> passed in I<*pval>
80*b077aed3SPierre Proncherythat was previously allocated via a "new" function. The I<it> parameter is a
81*b077aed3SPierre Proncherypointer to the B<ASN1_ITEM> template object created via the
82*b077aed3SPierre ProncheryIMPLEMENT_EXTERN_ASN1() macro.
83*b077aed3SPierre Pronchery
84*b077aed3SPierre Pronchery=item I<asn1_ex_clear>
85*b077aed3SPierre Pronchery
86*b077aed3SPierre ProncheryA "clear" function responsible for clearing any data in the B<ASN1_VALUE> passed
87*b077aed3SPierre Proncheryin I<*pval> and making it suitable for reuse. The I<it> parameter is a pointer
88*b077aed3SPierre Proncheryto the B<ASN1_ITEM> template object created via the IMPLEMENT_EXTERN_ASN1()
89*b077aed3SPierre Proncherymacro.
90*b077aed3SPierre Pronchery
91*b077aed3SPierre Pronchery=item I<asn1_ex_d2i>
92*b077aed3SPierre Pronchery
93*b077aed3SPierre ProncheryA "d2i" function responsible for converting DER data with the tag I<tag> and
94*b077aed3SPierre Proncheryclass I<class> into an B<ASN1_VALUE>. If I<*pval> is non-NULL then the
95*b077aed3SPierre ProncheryB<ASN_VALUE> it points to should be reused. Otherwise a new B<ASN1_VALUE>
96*b077aed3SPierre Proncheryshould be allocated and stored in I<*pval>. I<*in> points to the DER data to be
97*b077aed3SPierre Proncherydecoded and I<len> is the length of that data. After decoding I<*in> should be
98*b077aed3SPierre Proncheryupdated to point at the next byte after the decoded data. If the B<ASN1_VALUE>
99*b077aed3SPierre Proncheryis considered optional in this context then I<opt> will be nonzero. Otherwise
100*b077aed3SPierre Proncheryit will be zero. The I<it> parameter is a pointer to the B<ASN1_ITEM> template
101*b077aed3SPierre Proncheryobject created via the IMPLEMENT_EXTERN_ASN1() macro. A pointer to the current
102*b077aed3SPierre ProncheryB<ASN1_TLC> context (which may be required for other ASN1 function calls) is
103*b077aed3SPierre Proncherypassed in the I<ctx> parameter.
104*b077aed3SPierre Pronchery
105*b077aed3SPierre ProncheryThe I<asn1_ex_d2i> entry may be NULL if I<asn1_ex_d2i_ex> has been specified
106*b077aed3SPierre Proncheryinstead.
107*b077aed3SPierre Pronchery
108*b077aed3SPierre ProncheryReturns <= 0 on error or a positive value on success.
109*b077aed3SPierre Pronchery
110*b077aed3SPierre Pronchery=item I<asn1_ex_i2d>
111*b077aed3SPierre Pronchery
112*b077aed3SPierre ProncheryAn "i2d" function responsible for converting an B<ASN1_VALUE> into DER encoding.
113*b077aed3SPierre ProncheryOn entry I<*pval> will contain the B<ASN1_VALUE> to be encoded. If default
114*b077aed3SPierre Proncherytagging is to be used then I<tag> will be -1 on entry. Otherwise if implicit
115*b077aed3SPierre Proncherytagging should be used then I<tag> and I<aclass> will be the tag and associated
116*b077aed3SPierre Proncheryclass.
117*b077aed3SPierre Pronchery
118*b077aed3SPierre ProncheryIf I<out> is not NULL then this function should write the DER encoded data to
119*b077aed3SPierre Proncherythe buffer in I<*out>, and then increment I<*out> to point to immediately after
120*b077aed3SPierre Proncherythe data just written.
121*b077aed3SPierre Pronchery
122*b077aed3SPierre ProncheryIf I<out> is NULL then no data should be written but the length calculated and
123*b077aed3SPierre Proncheryreturned as if it were.
124*b077aed3SPierre Pronchery
125*b077aed3SPierre ProncheryThe I<asn1_ex_i2d> entry may be NULL if I<asn1_ex_i2d_ex> has been specified
126*b077aed3SPierre Proncheryinstead.
127*b077aed3SPierre Pronchery
128*b077aed3SPierre ProncheryThe return value should be negative if a fatal error occurred, or 0 if a
129*b077aed3SPierre Proncherynon-fatal error occurred. Otherwise it should return the length of the encoded
130*b077aed3SPierre Proncherydata.
131*b077aed3SPierre Pronchery
132*b077aed3SPierre Pronchery=item I<asn1_ex_print>
133*b077aed3SPierre Pronchery
134*b077aed3SPierre ProncheryA "print" function. I<out> is the BIO to print the output to. I<*pval> is the
135*b077aed3SPierre ProncheryB<ASN1_VALUE> to be printed. I<indent> is the number of spaces of indenting to
136*b077aed3SPierre Proncherybe printed before any data is printed. I<fname> is currently unused and is
137*b077aed3SPierre Proncheryalways "". I<pctx> is a pointer to the B<ASN1_PCTX> for the print operation.
138*b077aed3SPierre Pronchery
139*b077aed3SPierre ProncheryReturns 0 on error or a positive value on success. If the return value is 2 then
140*b077aed3SPierre Proncheryan additional newline will be printed after the data printed by this function.
141*b077aed3SPierre Pronchery
142*b077aed3SPierre Pronchery=item I<asn1_ex_new_ex>
143*b077aed3SPierre Pronchery
144*b077aed3SPierre ProncheryThis is the same as I<asn1_ex_new> except that it is additionally passed the
145*b077aed3SPierre ProncheryOSSL_LIB_CTX to be used in I<libctx> and any property query string to be used
146*b077aed3SPierre Proncheryfor algorithm fetching in the I<propq> parameter. See
147*b077aed3SPierre ProncheryL<crypto(7)/ALGORITHM FETCHING> for further details. If I<asn1_ex_new_ex> is
148*b077aed3SPierre Proncherynon NULL, then it will always be called in preference to I<asn1_ex_new>.
149*b077aed3SPierre Pronchery
150*b077aed3SPierre Pronchery=item I<asn1_ex_d2i_ex>
151*b077aed3SPierre Pronchery
152*b077aed3SPierre ProncheryThis is the same as I<asn1_ex_d2i> except that it is additionally passed the
153*b077aed3SPierre ProncheryOSSL_LIB_CTX to be used in I<libctx> and any property query string to be used
154*b077aed3SPierre Proncheryfor algorithm fetching in the I<propq> parameter. See
155*b077aed3SPierre ProncheryL<crypto(7)/ALGORITHM FETCHING> for further details. If I<asn1_ex_d2i_ex> is
156*b077aed3SPierre Proncherynon NULL, then it will always be called in preference to I<asn1_ex_d2i>.
157*b077aed3SPierre Pronchery
158*b077aed3SPierre Pronchery=back
159*b077aed3SPierre Pronchery
160*b077aed3SPierre Pronchery=head1 RETURN VALUES
161*b077aed3SPierre Pronchery
162*b077aed3SPierre ProncheryReturn values for the various callbacks are as described above.
163*b077aed3SPierre Pronchery
164*b077aed3SPierre Pronchery=head1 SEE ALSO
165*b077aed3SPierre Pronchery
166*b077aed3SPierre ProncheryL<ASN1_item_new_ex(3)>
167*b077aed3SPierre Pronchery
168*b077aed3SPierre Pronchery=head1 HISTORY
169*b077aed3SPierre Pronchery
170*b077aed3SPierre ProncheryThe I<asn1_ex_new_ex> and I<asn1_ex_d2i_ex> callbacks were added in OpenSSL 3.0.
171*b077aed3SPierre Pronchery
172*b077aed3SPierre Pronchery=head1 COPYRIGHT
173*b077aed3SPierre Pronchery
174*b077aed3SPierre ProncheryCopyright 2021 The OpenSSL Project Authors. All Rights Reserved.
175*b077aed3SPierre Pronchery
176*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
177*b077aed3SPierre Proncherythis file except in compliance with the License.  You can obtain a copy
178*b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at
179*b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>.
180*b077aed3SPierre Pronchery
181*b077aed3SPierre Pronchery=cut
182