OSDN Git Service

26f5ea89b47e48538c9d63038c087c4af2312859
[ffftp/ffftp.git] / contrib / openssl / include / openssl / asn1t.h
1 /* asn1t.h */\r
2 /*\r
3  * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project\r
4  * 2000.\r
5  */\r
6 /* ====================================================================\r
7  * Copyright (c) 2000-2005 The OpenSSL Project.  All rights reserved.\r
8  *\r
9  * Redistribution and use in source and binary forms, with or without\r
10  * modification, are permitted provided that the following conditions\r
11  * are met:\r
12  *\r
13  * 1. Redistributions of source code must retain the above copyright\r
14  *    notice, this list of conditions and the following disclaimer.\r
15  *\r
16  * 2. Redistributions in binary form must reproduce the above copyright\r
17  *    notice, this list of conditions and the following disclaimer in\r
18  *    the documentation and/or other materials provided with the\r
19  *    distribution.\r
20  *\r
21  * 3. All advertising materials mentioning features or use of this\r
22  *    software must display the following acknowledgment:\r
23  *    "This product includes software developed by the OpenSSL Project\r
24  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
25  *\r
26  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
27  *    endorse or promote products derived from this software without\r
28  *    prior written permission. For written permission, please contact\r
29  *    licensing@OpenSSL.org.\r
30  *\r
31  * 5. Products derived from this software may not be called "OpenSSL"\r
32  *    nor may "OpenSSL" appear in their names without prior written\r
33  *    permission of the OpenSSL Project.\r
34  *\r
35  * 6. Redistributions of any form whatsoever must retain the following\r
36  *    acknowledgment:\r
37  *    "This product includes software developed by the OpenSSL Project\r
38  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
39  *\r
40  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
41  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
43  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
44  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
45  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
46  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
47  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
49  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
50  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
51  * OF THE POSSIBILITY OF SUCH DAMAGE.\r
52  * ====================================================================\r
53  *\r
54  * This product includes cryptographic software written by Eric Young\r
55  * (eay@cryptsoft.com).  This product includes software written by Tim\r
56  * Hudson (tjh@cryptsoft.com).\r
57  *\r
58  */\r
59 #ifndef HEADER_ASN1T_H\r
60 # define HEADER_ASN1T_H\r
61 \r
62 # include <stddef.h>\r
63 # include <openssl/e_os2.h>\r
64 # include <openssl/asn1.h>\r
65 \r
66 # ifdef OPENSSL_BUILD_SHLIBCRYPTO\r
67 #  undef OPENSSL_EXTERN\r
68 #  define OPENSSL_EXTERN OPENSSL_EXPORT\r
69 # endif\r
70 \r
71 /* ASN1 template defines, structures and functions */\r
72 \r
73 #ifdef  __cplusplus\r
74 extern "C" {\r
75 #endif\r
76 \r
77 # ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION\r
78 \r
79 /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */\r
80 #  define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))\r
81 \r
82 /* Macros for start and end of ASN1_ITEM definition */\r
83 \r
84 #  define ASN1_ITEM_start(itname) \\r
85         OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {\r
86 \r
87 #  define ASN1_ITEM_end(itname) \\r
88                 };\r
89 \r
90 # else\r
91 \r
92 /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */\r
93 #  define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))\r
94 \r
95 /* Macros for start and end of ASN1_ITEM definition */\r
96 \r
97 #  define ASN1_ITEM_start(itname) \\r
98         const ASN1_ITEM * itname##_it(void) \\r
99         { \\r
100                 static const ASN1_ITEM local_it = {\r
101 \r
102 #  define ASN1_ITEM_end(itname) \\r
103                 }; \\r
104         return &local_it; \\r
105         }\r
106 \r
107 # endif\r
108 \r
109 /* Macros to aid ASN1 template writing */\r
110 \r
111 # define ASN1_ITEM_TEMPLATE(tname) \\r
112         static const ASN1_TEMPLATE tname##_item_tt\r
113 \r
114 # define ASN1_ITEM_TEMPLATE_END(tname) \\r
115         ;\\r
116         ASN1_ITEM_start(tname) \\r
117                 ASN1_ITYPE_PRIMITIVE,\\r
118                 -1,\\r
119                 &tname##_item_tt,\\r
120                 0,\\r
121                 NULL,\\r
122                 0,\\r
123                 #tname \\r
124         ASN1_ITEM_end(tname)\r
125 \r
126 /* This is a ASN1 type which just embeds a template */\r
127 \r
128 /*-\r
129  * This pair helps declare a SEQUENCE. We can do:\r
130  *\r
131  *      ASN1_SEQUENCE(stname) = {\r
132  *              ... SEQUENCE components ...\r
133  *      } ASN1_SEQUENCE_END(stname)\r
134  *\r
135  *      This will produce an ASN1_ITEM called stname_it\r
136  *      for a structure called stname.\r
137  *\r
138  *      If you want the same structure but a different\r
139  *      name then use:\r
140  *\r
141  *      ASN1_SEQUENCE(itname) = {\r
142  *              ... SEQUENCE components ...\r
143  *      } ASN1_SEQUENCE_END_name(stname, itname)\r
144  *\r
145  *      This will create an item called itname_it using\r
146  *      a structure called stname.\r
147  */\r
148 \r
149 # define ASN1_SEQUENCE(tname) \\r
150         static const ASN1_TEMPLATE tname##_seq_tt[]\r
151 \r
152 # define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)\r
153 \r
154 # define ASN1_SEQUENCE_END_name(stname, tname) \\r
155         ;\\r
156         ASN1_ITEM_start(tname) \\r
157                 ASN1_ITYPE_SEQUENCE,\\r
158                 V_ASN1_SEQUENCE,\\r
159                 tname##_seq_tt,\\r
160                 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\\r
161                 NULL,\\r
162                 sizeof(stname),\\r
163                 #stname \\r
164         ASN1_ITEM_end(tname)\r
165 \r
166 # define ASN1_NDEF_SEQUENCE(tname) \\r
167         ASN1_SEQUENCE(tname)\r
168 \r
169 # define ASN1_NDEF_SEQUENCE_cb(tname, cb) \\r
170         ASN1_SEQUENCE_cb(tname, cb)\r
171 \r
172 # define ASN1_SEQUENCE_cb(tname, cb) \\r
173         static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \\r
174         ASN1_SEQUENCE(tname)\r
175 \r
176 # define ASN1_BROKEN_SEQUENCE(tname) \\r
177         static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \\r
178         ASN1_SEQUENCE(tname)\r
179 \r
180 # define ASN1_SEQUENCE_ref(tname, cb, lck) \\r
181         static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \\r
182         ASN1_SEQUENCE(tname)\r
183 \r
184 # define ASN1_SEQUENCE_enc(tname, enc, cb) \\r
185         static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \\r
186         ASN1_SEQUENCE(tname)\r
187 \r
188 # define ASN1_NDEF_SEQUENCE_END(tname) \\r
189         ;\\r
190         ASN1_ITEM_start(tname) \\r
191                 ASN1_ITYPE_NDEF_SEQUENCE,\\r
192                 V_ASN1_SEQUENCE,\\r
193                 tname##_seq_tt,\\r
194                 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\\r
195                 NULL,\\r
196                 sizeof(tname),\\r
197                 #tname \\r
198         ASN1_ITEM_end(tname)\r
199 \r
200 # define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)\r
201 \r
202 # define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)\r
203 \r
204 # define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)\r
205 \r
206 # define ASN1_SEQUENCE_END_ref(stname, tname) \\r
207         ;\\r
208         ASN1_ITEM_start(tname) \\r
209                 ASN1_ITYPE_SEQUENCE,\\r
210                 V_ASN1_SEQUENCE,\\r
211                 tname##_seq_tt,\\r
212                 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\\r
213                 &tname##_aux,\\r
214                 sizeof(stname),\\r
215                 #stname \\r
216         ASN1_ITEM_end(tname)\r
217 \r
218 # define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \\r
219         ;\\r
220         ASN1_ITEM_start(tname) \\r
221                 ASN1_ITYPE_NDEF_SEQUENCE,\\r
222                 V_ASN1_SEQUENCE,\\r
223                 tname##_seq_tt,\\r
224                 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\\r
225                 &tname##_aux,\\r
226                 sizeof(stname),\\r
227                 #stname \\r
228         ASN1_ITEM_end(tname)\r
229 \r
230 /*-\r
231  * This pair helps declare a CHOICE type. We can do:\r
232  *\r
233  *      ASN1_CHOICE(chname) = {\r
234  *              ... CHOICE options ...\r
235  *      ASN1_CHOICE_END(chname)\r
236  *\r
237  *      This will produce an ASN1_ITEM called chname_it\r
238  *      for a structure called chname. The structure\r
239  *      definition must look like this:\r
240  *      typedef struct {\r
241  *              int type;\r
242  *              union {\r
243  *                      ASN1_SOMETHING *opt1;\r
244  *                      ASN1_SOMEOTHER *opt2;\r
245  *              } value;\r
246  *      } chname;\r
247  *\r
248  *      the name of the selector must be 'type'.\r
249  *      to use an alternative selector name use the\r
250  *      ASN1_CHOICE_END_selector() version.\r
251  */\r
252 \r
253 # define ASN1_CHOICE(tname) \\r
254         static const ASN1_TEMPLATE tname##_ch_tt[]\r
255 \r
256 # define ASN1_CHOICE_cb(tname, cb) \\r
257         static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \\r
258         ASN1_CHOICE(tname)\r
259 \r
260 # define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)\r
261 \r
262 # define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)\r
263 \r
264 # define ASN1_CHOICE_END_selector(stname, tname, selname) \\r
265         ;\\r
266         ASN1_ITEM_start(tname) \\r
267                 ASN1_ITYPE_CHOICE,\\r
268                 offsetof(stname,selname) ,\\r
269                 tname##_ch_tt,\\r
270                 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\\r
271                 NULL,\\r
272                 sizeof(stname),\\r
273                 #stname \\r
274         ASN1_ITEM_end(tname)\r
275 \r
276 # define ASN1_CHOICE_END_cb(stname, tname, selname) \\r
277         ;\\r
278         ASN1_ITEM_start(tname) \\r
279                 ASN1_ITYPE_CHOICE,\\r
280                 offsetof(stname,selname) ,\\r
281                 tname##_ch_tt,\\r
282                 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\\r
283                 &tname##_aux,\\r
284                 sizeof(stname),\\r
285                 #stname \\r
286         ASN1_ITEM_end(tname)\r
287 \r
288 /* This helps with the template wrapper form of ASN1_ITEM */\r
289 \r
290 # define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \\r
291         (flags), (tag), 0,\\r
292         #name, ASN1_ITEM_ref(type) }\r
293 \r
294 /* These help with SEQUENCE or CHOICE components */\r
295 \r
296 /* used to declare other types */\r
297 \r
298 # define ASN1_EX_TYPE(flags, tag, stname, field, type) { \\r
299         (flags), (tag), offsetof(stname, field),\\r
300         #field, ASN1_ITEM_ref(type) }\r
301 \r
302 /* used when the structure is combined with the parent */\r
303 \r
304 # define ASN1_EX_COMBINE(flags, tag, type) { \\r
305         (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }\r
306 \r
307 /* implicit and explicit helper macros */\r
308 \r
309 # define ASN1_IMP_EX(stname, field, type, tag, ex) \\r
310                 ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)\r
311 \r
312 # define ASN1_EXP_EX(stname, field, type, tag, ex) \\r
313                 ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)\r
314 \r
315 /* Any defined by macros: the field used is in the table itself */\r
316 \r
317 # ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION\r
318 #  define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }\r
319 #  define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }\r
320 # else\r
321 #  define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }\r
322 #  define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }\r
323 # endif\r
324 /* Plain simple type */\r
325 # define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)\r
326 \r
327 /* OPTIONAL simple type */\r
328 # define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)\r
329 \r
330 /* IMPLICIT tagged simple type */\r
331 # define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)\r
332 \r
333 /* IMPLICIT tagged OPTIONAL simple type */\r
334 # define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)\r
335 \r
336 /* Same as above but EXPLICIT */\r
337 \r
338 # define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)\r
339 # define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)\r
340 \r
341 /* SEQUENCE OF type */\r
342 # define ASN1_SEQUENCE_OF(stname, field, type) \\r
343                 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)\r
344 \r
345 /* OPTIONAL SEQUENCE OF */\r
346 # define ASN1_SEQUENCE_OF_OPT(stname, field, type) \\r
347                 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)\r
348 \r
349 /* Same as above but for SET OF */\r
350 \r
351 # define ASN1_SET_OF(stname, field, type) \\r
352                 ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)\r
353 \r
354 # define ASN1_SET_OF_OPT(stname, field, type) \\r
355                 ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)\r
356 \r
357 /* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */\r
358 \r
359 # define ASN1_IMP_SET_OF(stname, field, type, tag) \\r
360                         ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)\r
361 \r
362 # define ASN1_EXP_SET_OF(stname, field, type, tag) \\r
363                         ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)\r
364 \r
365 # define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \\r
366                         ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)\r
367 \r
368 # define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \\r
369                         ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)\r
370 \r
371 # define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \\r
372                         ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)\r
373 \r
374 # define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \\r
375                         ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)\r
376 \r
377 # define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \\r
378                         ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)\r
379 \r
380 # define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \\r
381                         ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)\r
382 \r
383 /* EXPLICIT using indefinite length constructed form */\r
384 # define ASN1_NDEF_EXP(stname, field, type, tag) \\r
385                         ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF)\r
386 \r
387 /* EXPLICIT OPTIONAL using indefinite length constructed form */\r
388 # define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \\r
389                         ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)\r
390 \r
391 /* Macros for the ASN1_ADB structure */\r
392 \r
393 # define ASN1_ADB(name) \\r
394         static const ASN1_ADB_TABLE name##_adbtbl[]\r
395 \r
396 # ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION\r
397 \r
398 #  define ASN1_ADB_END(name, flags, field, app_table, def, none) \\r
399         ;\\r
400         static const ASN1_ADB name##_adb = {\\r
401                 flags,\\r
402                 offsetof(name, field),\\r
403                 app_table,\\r
404                 name##_adbtbl,\\r
405                 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\\r
406                 def,\\r
407                 none\\r
408         }\r
409 \r
410 # else\r
411 \r
412 #  define ASN1_ADB_END(name, flags, field, app_table, def, none) \\r
413         ;\\r
414         static const ASN1_ITEM *name##_adb(void) \\r
415         { \\r
416         static const ASN1_ADB internal_adb = \\r
417                 {\\r
418                 flags,\\r
419                 offsetof(name, field),\\r
420                 app_table,\\r
421                 name##_adbtbl,\\r
422                 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\\r
423                 def,\\r
424                 none\\r
425                 }; \\r
426                 return (const ASN1_ITEM *) &internal_adb; \\r
427         } \\r
428         void dummy_function(void)\r
429 \r
430 # endif\r
431 \r
432 # define ADB_ENTRY(val, template) {val, template}\r
433 \r
434 # define ASN1_ADB_TEMPLATE(name) \\r
435         static const ASN1_TEMPLATE name##_tt\r
436 \r
437 /*\r
438  * This is the ASN1 template structure that defines a wrapper round the\r
439  * actual type. It determines the actual position of the field in the value\r
440  * structure, various flags such as OPTIONAL and the field name.\r
441  */\r
442 \r
443 struct ASN1_TEMPLATE_st {\r
444     unsigned long flags;        /* Various flags */\r
445     long tag;                   /* tag, not used if no tagging */\r
446     unsigned long offset;       /* Offset of this field in structure */\r
447 # ifndef NO_ASN1_FIELD_NAMES\r
448     const char *field_name;     /* Field name */\r
449 # endif\r
450     ASN1_ITEM_EXP *item;        /* Relevant ASN1_ITEM or ASN1_ADB */\r
451 };\r
452 \r
453 /* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */\r
454 \r
455 # define ASN1_TEMPLATE_item(t) (t->item_ptr)\r
456 # define ASN1_TEMPLATE_adb(t) (t->item_ptr)\r
457 \r
458 typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;\r
459 typedef struct ASN1_ADB_st ASN1_ADB;\r
460 \r
461 struct ASN1_ADB_st {\r
462     unsigned long flags;        /* Various flags */\r
463     unsigned long offset;       /* Offset of selector field */\r
464     STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */\r
465     const ASN1_ADB_TABLE *tbl;  /* Table of possible types */\r
466     long tblcount;              /* Number of entries in tbl */\r
467     const ASN1_TEMPLATE *default_tt; /* Type to use if no match */\r
468     const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */\r
469 };\r
470 \r
471 struct ASN1_ADB_TABLE_st {\r
472     long value;                 /* NID for an object or value for an int */\r
473     const ASN1_TEMPLATE tt;     /* item for this value */\r
474 };\r
475 \r
476 /* template flags */\r
477 \r
478 /* Field is optional */\r
479 # define ASN1_TFLG_OPTIONAL      (0x1)\r
480 \r
481 /* Field is a SET OF */\r
482 # define ASN1_TFLG_SET_OF        (0x1 << 1)\r
483 \r
484 /* Field is a SEQUENCE OF */\r
485 # define ASN1_TFLG_SEQUENCE_OF   (0x2 << 1)\r
486 \r
487 /*\r
488  * Special case: this refers to a SET OF that will be sorted into DER order\r
489  * when encoded *and* the corresponding STACK will be modified to match the\r
490  * new order.\r
491  */\r
492 # define ASN1_TFLG_SET_ORDER     (0x3 << 1)\r
493 \r
494 /* Mask for SET OF or SEQUENCE OF */\r
495 # define ASN1_TFLG_SK_MASK       (0x3 << 1)\r
496 \r
497 /*\r
498  * These flags mean the tag should be taken from the tag field. If EXPLICIT\r
499  * then the underlying type is used for the inner tag.\r
500  */\r
501 \r
502 /* IMPLICIT tagging */\r
503 # define ASN1_TFLG_IMPTAG        (0x1 << 3)\r
504 \r
505 /* EXPLICIT tagging, inner tag from underlying type */\r
506 # define ASN1_TFLG_EXPTAG        (0x2 << 3)\r
507 \r
508 # define ASN1_TFLG_TAG_MASK      (0x3 << 3)\r
509 \r
510 /* context specific IMPLICIT */\r
511 # define ASN1_TFLG_IMPLICIT      ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT\r
512 \r
513 /* context specific EXPLICIT */\r
514 # define ASN1_TFLG_EXPLICIT      ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT\r
515 \r
516 /*\r
517  * If tagging is in force these determine the type of tag to use. Otherwise\r
518  * the tag is determined by the underlying type. These values reflect the\r
519  * actual octet format.\r
520  */\r
521 \r
522 /* Universal tag */\r
523 # define ASN1_TFLG_UNIVERSAL     (0x0<<6)\r
524 /* Application tag */\r
525 # define ASN1_TFLG_APPLICATION   (0x1<<6)\r
526 /* Context specific tag */\r
527 # define ASN1_TFLG_CONTEXT       (0x2<<6)\r
528 /* Private tag */\r
529 # define ASN1_TFLG_PRIVATE       (0x3<<6)\r
530 \r
531 # define ASN1_TFLG_TAG_CLASS     (0x3<<6)\r
532 \r
533 /*\r
534  * These are for ANY DEFINED BY type. In this case the 'item' field points to\r
535  * an ASN1_ADB structure which contains a table of values to decode the\r
536  * relevant type\r
537  */\r
538 \r
539 # define ASN1_TFLG_ADB_MASK      (0x3<<8)\r
540 \r
541 # define ASN1_TFLG_ADB_OID       (0x1<<8)\r
542 \r
543 # define ASN1_TFLG_ADB_INT       (0x1<<9)\r
544 \r
545 /*\r
546  * This flag means a parent structure is passed instead of the field: this is\r
547  * useful is a SEQUENCE is being combined with a CHOICE for example. Since\r
548  * this means the structure and item name will differ we need to use the\r
549  * ASN1_CHOICE_END_name() macro for example.\r
550  */\r
551 \r
552 # define ASN1_TFLG_COMBINE       (0x1<<10)\r
553 \r
554 /*\r
555  * This flag when present in a SEQUENCE OF, SET OF or EXPLICIT causes\r
556  * indefinite length constructed encoding to be used if required.\r
557  */\r
558 \r
559 # define ASN1_TFLG_NDEF          (0x1<<11)\r
560 \r
561 /* This is the actual ASN1 item itself */\r
562 \r
563 struct ASN1_ITEM_st {\r
564     char itype;                 /* The item type, primitive, SEQUENCE, CHOICE\r
565                                  * or extern */\r
566     long utype;                 /* underlying type */\r
567     const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains\r
568                                      * the contents */\r
569     long tcount;                /* Number of templates if SEQUENCE or CHOICE */\r
570     const void *funcs;          /* functions that handle this type */\r
571     long size;                  /* Structure size (usually) */\r
572 # ifndef NO_ASN1_FIELD_NAMES\r
573     const char *sname;          /* Structure name */\r
574 # endif\r
575 };\r
576 \r
577 /*-\r
578  * These are values for the itype field and\r
579  * determine how the type is interpreted.\r
580  *\r
581  * For PRIMITIVE types the underlying type\r
582  * determines the behaviour if items is NULL.\r
583  *\r
584  * Otherwise templates must contain a single\r
585  * template and the type is treated in the\r
586  * same way as the type specified in the template.\r
587  *\r
588  * For SEQUENCE types the templates field points\r
589  * to the members, the size field is the\r
590  * structure size.\r
591  *\r
592  * For CHOICE types the templates field points\r
593  * to each possible member (typically a union)\r
594  * and the 'size' field is the offset of the\r
595  * selector.\r
596  *\r
597  * The 'funcs' field is used for application\r
598  * specific functions.\r
599  *\r
600  * For COMPAT types the funcs field gives a\r
601  * set of functions that handle this type, this\r
602  * supports the old d2i, i2d convention.\r
603  *\r
604  * The EXTERN type uses a new style d2i/i2d.\r
605  * The new style should be used where possible\r
606  * because it avoids things like the d2i IMPLICIT\r
607  * hack.\r
608  *\r
609  * MSTRING is a multiple string type, it is used\r
610  * for a CHOICE of character strings where the\r
611  * actual strings all occupy an ASN1_STRING\r
612  * structure. In this case the 'utype' field\r
613  * has a special meaning, it is used as a mask\r
614  * of acceptable types using the B_ASN1 constants.\r
615  *\r
616  * NDEF_SEQUENCE is the same as SEQUENCE except\r
617  * that it will use indefinite length constructed\r
618  * encoding if requested.\r
619  *\r
620  */\r
621 \r
622 # define ASN1_ITYPE_PRIMITIVE            0x0\r
623 \r
624 # define ASN1_ITYPE_SEQUENCE             0x1\r
625 \r
626 # define ASN1_ITYPE_CHOICE               0x2\r
627 \r
628 # define ASN1_ITYPE_COMPAT               0x3\r
629 \r
630 # define ASN1_ITYPE_EXTERN               0x4\r
631 \r
632 # define ASN1_ITYPE_MSTRING              0x5\r
633 \r
634 # define ASN1_ITYPE_NDEF_SEQUENCE        0x6\r
635 \r
636 /*\r
637  * Cache for ASN1 tag and length, so we don't keep re-reading it for things\r
638  * like CHOICE\r
639  */\r
640 \r
641 struct ASN1_TLC_st {\r
642     char valid;                 /* Values below are valid */\r
643     int ret;                    /* return value */\r
644     long plen;                  /* length */\r
645     int ptag;                   /* class value */\r
646     int pclass;                 /* class value */\r
647     int hdrlen;                 /* header length */\r
648 };\r
649 \r
650 /* Typedefs for ASN1 function pointers */\r
651 \r
652 typedef ASN1_VALUE *ASN1_new_func(void);\r
653 typedef void ASN1_free_func(ASN1_VALUE *a);\r
654 typedef ASN1_VALUE *ASN1_d2i_func(ASN1_VALUE **a, const unsigned char **in,\r
655                                   long length);\r
656 typedef int ASN1_i2d_func(ASN1_VALUE *a, unsigned char **in);\r
657 \r
658 typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\r
659                         const ASN1_ITEM *it, int tag, int aclass, char opt,\r
660                         ASN1_TLC *ctx);\r
661 \r
662 typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out,\r
663                         const ASN1_ITEM *it, int tag, int aclass);\r
664 typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
665 typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
666 \r
667 typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval,\r
668                                int indent, const char *fname,\r
669                                const ASN1_PCTX *pctx);\r
670 \r
671 typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont,\r
672                                int *putype, const ASN1_ITEM *it);\r
673 typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont,\r
674                                int len, int utype, char *free_cont,\r
675                                const ASN1_ITEM *it);\r
676 typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval,\r
677                                  const ASN1_ITEM *it, int indent,\r
678                                  const ASN1_PCTX *pctx);\r
679 \r
680 typedef struct ASN1_COMPAT_FUNCS_st {\r
681     ASN1_new_func *asn1_new;\r
682     ASN1_free_func *asn1_free;\r
683     ASN1_d2i_func *asn1_d2i;\r
684     ASN1_i2d_func *asn1_i2d;\r
685 } ASN1_COMPAT_FUNCS;\r
686 \r
687 typedef struct ASN1_EXTERN_FUNCS_st {\r
688     void *app_data;\r
689     ASN1_ex_new_func *asn1_ex_new;\r
690     ASN1_ex_free_func *asn1_ex_free;\r
691     ASN1_ex_free_func *asn1_ex_clear;\r
692     ASN1_ex_d2i *asn1_ex_d2i;\r
693     ASN1_ex_i2d *asn1_ex_i2d;\r
694     ASN1_ex_print_func *asn1_ex_print;\r
695 } ASN1_EXTERN_FUNCS;\r
696 \r
697 typedef struct ASN1_PRIMITIVE_FUNCS_st {\r
698     void *app_data;\r
699     unsigned long flags;\r
700     ASN1_ex_new_func *prim_new;\r
701     ASN1_ex_free_func *prim_free;\r
702     ASN1_ex_free_func *prim_clear;\r
703     ASN1_primitive_c2i *prim_c2i;\r
704     ASN1_primitive_i2c *prim_i2c;\r
705     ASN1_primitive_print *prim_print;\r
706 } ASN1_PRIMITIVE_FUNCS;\r
707 \r
708 /*\r
709  * This is the ASN1_AUX structure: it handles various miscellaneous\r
710  * requirements. For example the use of reference counts and an informational\r
711  * callback. The "informational callback" is called at various points during\r
712  * the ASN1 encoding and decoding. It can be used to provide minor\r
713  * customisation of the structures used. This is most useful where the\r
714  * supplied routines *almost* do the right thing but need some extra help at\r
715  * a few points. If the callback returns zero then it is assumed a fatal\r
716  * error has occurred and the main operation should be abandoned. If major\r
717  * changes in the default behaviour are required then an external type is\r
718  * more appropriate.\r
719  */\r
720 \r
721 typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it,\r
722                         void *exarg);\r
723 \r
724 typedef struct ASN1_AUX_st {\r
725     void *app_data;\r
726     int flags;\r
727     int ref_offset;             /* Offset of reference value */\r
728     int ref_lock;               /* Lock type to use */\r
729     ASN1_aux_cb *asn1_cb;\r
730     int enc_offset;             /* Offset of ASN1_ENCODING structure */\r
731 } ASN1_AUX;\r
732 \r
733 /* For print related callbacks exarg points to this structure */\r
734 typedef struct ASN1_PRINT_ARG_st {\r
735     BIO *out;\r
736     int indent;\r
737     const ASN1_PCTX *pctx;\r
738 } ASN1_PRINT_ARG;\r
739 \r
740 /* For streaming related callbacks exarg points to this structure */\r
741 typedef struct ASN1_STREAM_ARG_st {\r
742     /* BIO to stream through */\r
743     BIO *out;\r
744     /* BIO with filters appended */\r
745     BIO *ndef_bio;\r
746     /* Streaming I/O boundary */\r
747     unsigned char **boundary;\r
748 } ASN1_STREAM_ARG;\r
749 \r
750 /* Flags in ASN1_AUX */\r
751 \r
752 /* Use a reference count */\r
753 # define ASN1_AFLG_REFCOUNT      1\r
754 /* Save the encoding of structure (useful for signatures) */\r
755 # define ASN1_AFLG_ENCODING      2\r
756 /* The Sequence length is invalid */\r
757 # define ASN1_AFLG_BROKEN        4\r
758 \r
759 /* operation values for asn1_cb */\r
760 \r
761 # define ASN1_OP_NEW_PRE         0\r
762 # define ASN1_OP_NEW_POST        1\r
763 # define ASN1_OP_FREE_PRE        2\r
764 # define ASN1_OP_FREE_POST       3\r
765 # define ASN1_OP_D2I_PRE         4\r
766 # define ASN1_OP_D2I_POST        5\r
767 # define ASN1_OP_I2D_PRE         6\r
768 # define ASN1_OP_I2D_POST        7\r
769 # define ASN1_OP_PRINT_PRE       8\r
770 # define ASN1_OP_PRINT_POST      9\r
771 # define ASN1_OP_STREAM_PRE      10\r
772 # define ASN1_OP_STREAM_POST     11\r
773 # define ASN1_OP_DETACHED_PRE    12\r
774 # define ASN1_OP_DETACHED_POST   13\r
775 \r
776 /* Macro to implement a primitive type */\r
777 # define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)\r
778 # define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \\r
779                                 ASN1_ITEM_start(itname) \\r
780                                         ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \\r
781                                 ASN1_ITEM_end(itname)\r
782 \r
783 /* Macro to implement a multi string type */\r
784 # define IMPLEMENT_ASN1_MSTRING(itname, mask) \\r
785                                 ASN1_ITEM_start(itname) \\r
786                                         ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \\r
787                                 ASN1_ITEM_end(itname)\r
788 \r
789 /* Macro to implement an ASN1_ITEM in terms of old style funcs */\r
790 \r
791 # define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE)\r
792 \r
793 # define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \\r
794         static const ASN1_COMPAT_FUNCS sname##_ff = { \\r
795                 (ASN1_new_func *)sname##_new, \\r
796                 (ASN1_free_func *)sname##_free, \\r
797                 (ASN1_d2i_func *)d2i_##sname, \\r
798                 (ASN1_i2d_func *)i2d_##sname, \\r
799         }; \\r
800         ASN1_ITEM_start(sname) \\r
801                 ASN1_ITYPE_COMPAT, \\r
802                 tag, \\r
803                 NULL, \\r
804                 0, \\r
805                 &sname##_ff, \\r
806                 0, \\r
807                 #sname \\r
808         ASN1_ITEM_end(sname)\r
809 \r
810 # define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \\r
811         ASN1_ITEM_start(sname) \\r
812                 ASN1_ITYPE_EXTERN, \\r
813                 tag, \\r
814                 NULL, \\r
815                 0, \\r
816                 &fptrs, \\r
817                 0, \\r
818                 #sname \\r
819         ASN1_ITEM_end(sname)\r
820 \r
821 /* Macro to implement standard functions in terms of ASN1_ITEM structures */\r
822 \r
823 # define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)\r
824 \r
825 # define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)\r
826 \r
827 # define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \\r
828                         IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)\r
829 \r
830 # define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \\r
831                 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname)\r
832 \r
833 # define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \\r
834                 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)\r
835 \r
836 # define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \\r
837         pre stname *fname##_new(void) \\r
838         { \\r
839                 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \\r
840         } \\r
841         pre void fname##_free(stname *a) \\r
842         { \\r
843                 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \\r
844         }\r
845 \r
846 # define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \\r
847         stname *fname##_new(void) \\r
848         { \\r
849                 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \\r
850         } \\r
851         void fname##_free(stname *a) \\r
852         { \\r
853                 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \\r
854         }\r
855 \r
856 # define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \\r
857         IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \\r
858         IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)\r
859 \r
860 # define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \\r
861         stname *d2i_##fname(stname **a, const unsigned char **in, long len) \\r
862         { \\r
863                 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\\r
864         } \\r
865         int i2d_##fname(stname *a, unsigned char **out) \\r
866         { \\r
867                 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\\r
868         }\r
869 \r
870 # define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \\r
871         int i2d_##stname##_NDEF(stname *a, unsigned char **out) \\r
872         { \\r
873                 return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\\r
874         }\r
875 \r
876 /*\r
877  * This includes evil casts to remove const: they will go away when full ASN1\r
878  * constification is done.\r
879  */\r
880 # define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \\r
881         stname *d2i_##fname(stname **a, const unsigned char **in, long len) \\r
882         { \\r
883                 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\\r
884         } \\r
885         int i2d_##fname(const stname *a, unsigned char **out) \\r
886         { \\r
887                 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\\r
888         }\r
889 \r
890 # define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \\r
891         stname * stname##_dup(stname *x) \\r
892         { \\r
893         return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \\r
894         }\r
895 \r
896 # define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \\r
897         IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname)\r
898 \r
899 # define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \\r
900         int fname##_print_ctx(BIO *out, stname *x, int indent, \\r
901                                                 const ASN1_PCTX *pctx) \\r
902         { \\r
903                 return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \\r
904                         ASN1_ITEM_rptr(itname), pctx); \\r
905         }\r
906 \r
907 # define IMPLEMENT_ASN1_FUNCTIONS_const(name) \\r
908                 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)\r
909 \r
910 # define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \\r
911         IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \\r
912         IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)\r
913 \r
914 /* external definitions for primitive types */\r
915 \r
916 DECLARE_ASN1_ITEM(ASN1_BOOLEAN)\r
917 DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)\r
918 DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)\r
919 DECLARE_ASN1_ITEM(ASN1_SEQUENCE)\r
920 DECLARE_ASN1_ITEM(CBIGNUM)\r
921 DECLARE_ASN1_ITEM(BIGNUM)\r
922 DECLARE_ASN1_ITEM(LONG)\r
923 DECLARE_ASN1_ITEM(ZLONG)\r
924 \r
925 DECLARE_STACK_OF(ASN1_VALUE)\r
926 \r
927 /* Functions used internally by the ASN1 code */\r
928 \r
929 int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
930 void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
931 int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);\r
932 int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
933 \r
934 void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);\r
935 int ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\r
936                       const ASN1_TEMPLATE *tt);\r
937 int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\r
938                      const ASN1_ITEM *it, int tag, int aclass, char opt,\r
939                      ASN1_TLC *ctx);\r
940 \r
941 int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,\r
942                      const ASN1_ITEM *it, int tag, int aclass);\r
943 int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out,\r
944                       const ASN1_TEMPLATE *tt);\r
945 void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
946 \r
947 int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,\r
948                 const ASN1_ITEM *it);\r
949 int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,\r
950                 int utype, char *free_cont, const ASN1_ITEM *it);\r
951 \r
952 int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
953 int asn1_set_choice_selector(ASN1_VALUE **pval, int value,\r
954                              const ASN1_ITEM *it);\r
955 \r
956 ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);\r
957 \r
958 const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,\r
959                                  int nullerr);\r
960 \r
961 int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);\r
962 \r
963 void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
964 void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
965 int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,\r
966                      const ASN1_ITEM *it);\r
967 int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,\r
968                   const ASN1_ITEM *it);\r
969 \r
970 #ifdef  __cplusplus\r
971 }\r
972 #endif\r
973 #endif\r