blob: 5c001049b0ae83e9bf5449c1fd33236585c0f9dd [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _CONSTR_TYPE_H_
6#define _CONSTR_TYPE_H_
7
8#include <asn_types.h> /* System-dependent types */
9#include <ber_tlv_length.h>
10#include <ber_tlv_tag.h>
11#include <ber_decoder.h>
12#include <der_encoder.h>
13#include <constraints.h>
14
15struct asn1_TYPE_descriptor_s; /* Forward declaration */
16
17/*
18 * Free the structure according to its specification.
19 * If (free_contents_only) is set, the wrapper structure itself (struct_ptr)
20 * will not be freed. (It may be useful in case the structure is allocated
21 * statically or arranged on the stack, yet its elements are allocated
22 * dynamically.)
23 */
24typedef void (asn_struct_free_f)(
25 struct asn1_TYPE_descriptor_s *type_descriptor,
26 void *struct_ptr, int free_contents_only);
27
28/*
29 * Print the structure according to its specification.
30 */
31typedef int (asn_struct_print_f)(
32 struct asn1_TYPE_descriptor_s *type_descriptor,
33 const void *struct_ptr,
34 int level, /* Indentation level */
35 asn_app_consume_bytes_f *callback, void *app_key);
36
37/*
38 * Return the outmost tag of the type.
39 * If the type is untagged CHOICE, the dynamic operation is performed.
40 * NOTE: This function pointer type is only useful internally.
41 * Do not use it in your application.
42 */
43typedef ber_tlv_tag_t (asn_outmost_tag_f)(
44 struct asn1_TYPE_descriptor_s *type_descriptor,
45 const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag);
46/* The instance of the above function type */
47asn_outmost_tag_f asn1_TYPE_outmost_tag;
48
49
50/*
51 * The definitive description of the destination language's structure.
52 */
53typedef struct asn1_TYPE_descriptor_s {
54 char *name; /* A name of the ASN.1 type */
55
56 /*
57 * Generalized functions for dealing with the specific type.
58 * May be directly invoked by applications.
59 */
60 asn_constr_check_f *check_constraints; /* Constraints validator */
61 ber_type_decoder_f *ber_decoder; /* Free-form BER decoder */
62 der_type_encoder_f *der_encoder; /* Canonical DER encoder */
63 asn_struct_print_f *print_struct; /* Human readable output */
64 asn_struct_free_f *free_struct; /* Free the structure */
65
66 /*
67 * Functions used internally. Should not be used by applications.
68 */
69 asn_outmost_tag_f *outmost_tag; /* <optional, internal> */
70
71 /*
72 * Tags that are expected, with some of their vital properties.
73 */
74 ber_tlv_tag_t *tags; /* At least one tag must be specified */
75 int tags_count; /* Number of tags which are expected */
76 int tags_impl_skip; /* Tags to skip in implicit mode */
77 int last_tag_form; /* Acceptable form of the tag (prim, constr) */
78
79 /*
80 * Additional information describing the type, used by appropriate
81 * functions above.
82 */
83 void *specifics;
84} asn1_TYPE_descriptor_t;
85
86/*
vlm31473082004-06-06 07:20:02 +000087 * BER tag to element number mapping.
88 */
89typedef struct asn1_TYPE_tag2member_s {
90 ber_tlv_tag_t el_tag; /* Outmost tag of the member */
91 int el_no; /* Index of the associated member, base 0 */
92} asn1_TYPE_tag2member_t;
93
94
95
96/*
vlmfa67ddc2004-06-03 03:38:44 +000097 * This function is a wrapper around (td)->print_struct, which prints out
98 * the contents of the target language's structure (struct_ptr) into the
99 * file pointer (stream) in human readable form.
100 * RETURN VALUES:
101 * 0: The structure is printed.
102 * -1: Problem dumping the structure.
103 */
104int asn_fprint(FILE *stream, /* Destination stream descriptor */
105 asn1_TYPE_descriptor_t *td, /* ASN.1 type descriptor */
106 const void *struct_ptr); /* Structure to be printed */
107
108#endif /* _CONSTR_TYPE_H_ */