Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / asn1.h
bloba91ea1ffb6de30a01071d2f5800b297913aef9ea
1 /** @file
3 * Common data for ASN.1
4 * 2007 Anders Broman
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #ifndef __ASN1_H__
14 #define __ASN1_H__
16 #include "ws_symbol_export.h"
18 typedef enum {
19 ASN1_ENC_BER, /* X.690 - BER, CER, DER */
20 ASN1_ENC_PER, /* X.691 - PER */
21 ASN1_ENC_ECN, /* X.692 - ECN */
22 ASN1_ENC_XER, /* X.693 - XER */
23 ASN1_ENC_OER /* X.696 - OER */
24 } asn1_enc_e;
26 typedef enum {
27 CB_ASN1_ENC,
28 CB_NEW_DISSECTOR,
29 CB_DISSECTOR_HANDLE
30 } asn1_cb_variant;
32 typedef enum {
33 ASN1_PAR_IRR, /* irrelevant parameter */
34 /* value */
35 ASN1_PAR_BOOLEAN,
36 ASN1_PAR_INTEGER,
37 /* type */
38 ASN1_PAR_TYPE
39 } asn1_par_type;
41 typedef struct _asn1_par_def_t {
42 const char *name;
43 asn1_par_type ptype;
44 } asn1_par_def_t;
46 typedef struct _asn1_par_t {
47 const char *name;
48 asn1_par_type ptype;
49 union {
50 bool v_boolean;
51 int32_t v_integer;
52 void *v_type;
53 } value;
54 struct _asn1_par_t *next;
55 } asn1_par_t;
57 typedef struct _asn1_stack_frame_t {
58 const char *name;
59 struct _asn1_par_t *par;
60 struct _asn1_stack_frame_t *next;
61 } asn1_stack_frame_t;
63 #define ASN1_CTX_SIGNATURE 0x41435458 /* "ACTX" */
65 typedef struct _asn1_ctx_t {
66 uint32_t signature;
67 asn1_enc_e encoding;
68 bool aligned;
69 packet_info *pinfo;
70 proto_item *created_item;
71 struct _asn1_stack_frame_t *stack;
72 void *value_ptr;
73 void *private_data;
74 struct {
75 int hf_index;
76 bool data_value_descr_present;
77 bool direct_ref_present;
78 bool indirect_ref_present;
79 tvbuff_t *data_value_descriptor;
80 const char *direct_reference;
81 int32_t indirect_reference;
82 int encoding;
84 0 : single-ASN1-type,
85 1 : octet-aligned,
86 2 : arbitrary
88 tvbuff_t *single_asn1_type;
89 tvbuff_t *octet_aligned;
90 tvbuff_t *arbitrary;
91 union {
92 struct {
93 int (*ber_callback)(bool imp_tag, tvbuff_t *tvb, int offset, struct _asn1_ctx_t* ,proto_tree *tree, int hf_index );
94 } ber;
95 struct {
96 int (*type_cb)(tvbuff_t*, int, struct _asn1_ctx_t*, proto_tree*, int);
97 } per;
98 } u;
99 } external;
100 struct {
101 proto_tree *tree;
102 proto_tree *top_tree;
103 void* tree_ctx;
104 } subtree;
105 struct {
106 int hf_index;
107 bool data_value_descr_present;
108 tvbuff_t *data_value_descriptor;
109 int identification;
111 0 : syntaxes,
112 1 : syntax,
113 2 : presentation-context-id,
114 3 : context-negotiation,
115 4 : transfer-syntax,
116 5 : fixed
118 int32_t presentation_context_id;
119 const char *abstract_syntax;
120 const char *transfer_syntax;
121 tvbuff_t *data_value;
122 union {
123 struct {
124 int (*ber_callback)(bool imp_tag, tvbuff_t *tvb, int offset, struct _asn1_ctx_t* ,proto_tree *tree, int hf_index );
125 } ber;
126 struct {
127 int (*type_cb)(tvbuff_t*, int, struct _asn1_ctx_t*, proto_tree*, int);
128 } per;
129 } u;
130 } embedded_pdv;
131 struct _rose_ctx_t *rose_ctx;
132 } asn1_ctx_t;
134 #define ROSE_CTX_SIGNATURE 0x524F5345 /* "ROSE" */
136 typedef struct _rose_ctx_t {
137 uint32_t signature;
138 dissector_table_t arg_global_dissector_table;
139 dissector_table_t arg_local_dissector_table;
140 dissector_table_t res_global_dissector_table;
141 dissector_table_t res_local_dissector_table;
142 dissector_table_t err_global_dissector_table;
143 dissector_table_t err_local_dissector_table;
144 /* filling in description into tree, info column, any buffer */
145 int apdu_depth;
146 bool fillin_info;
147 char *fillin_ptr;
148 size_t fillin_buf_size;
149 struct { /* "dynamic" data */
150 int pdu;
152 1 : invoke,
153 2 : returnResult,
154 3 : returnError,
155 4 : reject
157 int code;
159 -1 : none (optional in ReturnResult)
160 0 : local,
161 1 : global
163 int32_t code_local;
164 const char *code_global;
165 proto_item *code_item;
166 } d;
167 void *private_data;
168 } rose_ctx_t;
170 WS_DLL_PUBLIC void asn1_ctx_init(asn1_ctx_t *actx, asn1_enc_e encoding, bool aligned, packet_info *pinfo);
171 extern bool asn1_ctx_check_signature(asn1_ctx_t *actx);
172 extern void asn1_ctx_clean_external(asn1_ctx_t *actx);
173 extern void asn1_ctx_clean_epdv(asn1_ctx_t *actx);
175 extern void asn1_stack_frame_push(asn1_ctx_t *actx, const char *name);
176 extern void asn1_stack_frame_pop(asn1_ctx_t *actx, const char *name);
177 extern void asn1_stack_frame_check(asn1_ctx_t *actx, const char *name, const asn1_par_def_t *par_def);
179 extern void asn1_param_push_boolean(asn1_ctx_t *actx, bool value);
180 extern void asn1_param_push_integer(asn1_ctx_t *actx, int32_t value);
181 extern bool asn1_param_get_boolean(asn1_ctx_t *actx, const char *name);
182 extern int32_t asn1_param_get_integer(asn1_ctx_t *actx, const char *name);
184 WS_DLL_PUBLIC void rose_ctx_init(rose_ctx_t *rctx);
185 extern bool rose_ctx_check_signature(rose_ctx_t *rctx);
186 WS_DLL_PUBLIC void rose_ctx_clean_data(rose_ctx_t *rctx);
188 WS_DLL_PUBLIC asn1_ctx_t *get_asn1_ctx(void *ptr);
189 WS_DLL_PUBLIC rose_ctx_t *get_rose_ctx(void *ptr);
191 extern double asn1_get_real(const uint8_t *real_ptr, int len);
193 /* flags */
194 #define ASN1_EXT_ROOT 0x01
195 #define ASN1_EXT_EXT 0x02
196 #define ASN1_OPT 0x04
197 #define ASN1_DFLT 0x08
199 #define ASN1_HAS_EXT(f) ((f)&(ASN1_EXT_ROOT|ASN1_EXT_EXT))
202 #endif /* __ASN1_H__ */