2 * Definitions for ASN.1 BER dissection
4 * $Id: asn1.h,v 1.10 2002/08/28 21:00:05 jmayer Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
9 * Based on "g_asn1.h" from:
11 * GXSNMP -- An snmp mangament application
12 * Copyright (C) 1998 Gregory McLean & Jochen Friedrich
13 * Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP group
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #define ASN1_UNI 0 /* Universal */
34 #define ASN1_APL 1 /* Application */
35 #define ASN1_CTX 2 /* Context */
36 #define ASN1_PRV 3 /* Private */
39 #define ASN1_EOC 0 /* End Of Contents */
40 #define ASN1_BOL 1 /* Boolean */
41 #define ASN1_INT 2 /* Integer */
42 #define ASN1_BTS 3 /* Bit String */
43 #define ASN1_OTS 4 /* Octet String */
44 #define ASN1_NUL 5 /* Null */
45 #define ASN1_OJI 6 /* Object Identifier */
46 #define ASN1_OJD 7 /* Object Description */
47 #define ASN1_EXT 8 /* External */
48 #define ASN1_REAL 9 /* Real */
49 #define ASN1_ENUM 10 /* Enumerated */
50 #define ASN1_SEQ 16 /* Sequence */
51 #define ASN1_SET 17 /* Set */
52 #define ASN1_NUMSTR 18 /* Numerical String */
53 #define ASN1_PRNSTR 19 /* Printable String */
54 #define ASN1_TEXSTR 20 /* Teletext String */
55 #define ASN1_VIDSTR 21 /* Video String */
56 #define ASN1_IA5STR 22 /* IA5 String */
57 #define ASN1_UNITIM 23 /* Universal Time */
58 #define ASN1_GENTIM 24 /* General Time */
59 #define ASN1_GRASTR 25 /* Graphical String */
60 #define ASN1_VISSTR 26 /* Visible String */
61 #define ASN1_GENSTR 27 /* General String */
63 /* Primitive / Constructed */
64 #define ASN1_PRI 0 /* Primitive */
65 #define ASN1_CON 1 /* Constructed */
68 * Oh, this is hellish.
70 * The CMU SNMP library defines an OID as a sequence of "u_int"s,
71 * unless EIGHTBIT_SUBIDS is defined, in which case it defines
72 * an OID as a sequence of "u_char"s. None of its header files
73 * define EIGHTBIT_SUBIDS, and if a program defines it, that's
74 * not going to change the library to treat OIDs as sequences
75 * of "u_chars", so I'll assume that it'll be "u_int"s.
77 * The UCD SNMP library does the same, except it defines an OID
78 * as a sequence of "u_long"s, by default.
80 * "libsmi" defines it as a sequence of "unsigned int"s.
82 * I don't want to oblige all users of ASN.1 to include the SNMP
83 * library header files, so I'll assume none of the SNMP libraries
84 * will rudely surprise me by changing the definition; if they
85 * do, there will be compiler warnings, so we'll at least be able
88 * This requires that, if you're going to use "asn1_subid_decode()",
89 * "asn1_oid_value_decode()", or "asn1_oid_decode()", you include
90 * "config.h", to get the right #defines defined, so that we properly
93 #if defined(HAVE_UCD_SNMP)
94 typedef gulong subid_t; /* UCD SNMP */
96 typedef guint subid_t; /* CMU SNMP, libsmi, or nothing */
99 #define ASN1_ERR_NOERROR 0 /* no error */
100 #define ASN1_ERR_EOC_MISMATCH 1
101 #define ASN1_ERR_WRONG_TYPE 2 /* type not right */
102 #define ASN1_ERR_LENGTH_NOT_DEFINITE 3 /* length should be definite */
103 #define ASN1_ERR_LENGTH_MISMATCH 4
104 #define ASN1_ERR_WRONG_LENGTH_FOR_TYPE 5 /* length wrong for type */
106 typedef struct _ASN1_SCK ASN1_SCK;
110 tvbuff_t *tvb; /* Tvbuff whence the data comes */
111 int offset; /* Current offset in tvbuff */
114 void asn1_open (ASN1_SCK *asn1, tvbuff_t *tvb, int offset);
115 void asn1_close (ASN1_SCK *asn1, int *offset);
116 int asn1_octet_decode (ASN1_SCK *asn1, guchar *ch);
117 int asn1_tag_decode (ASN1_SCK *asn1, guint *tag);
118 int asn1_id_decode (ASN1_SCK *asn1, guint *cls, guint *con, guint *tag);
119 int asn1_length_decode (ASN1_SCK *asn1, gboolean *def, guint *len);
120 int asn1_header_decode(ASN1_SCK *asn1, guint *cls, guint *con, guint *tag,
121 gboolean *defp, guint *lenp);
122 int asn1_eoc (ASN1_SCK *asn1, int eoc);
123 int asn1_eoc_decode (ASN1_SCK *asn1, int eoc);
124 int asn1_null_decode (ASN1_SCK *asn1, int enc_len);
125 int asn1_bool_decode (ASN1_SCK *asn1, int enc_len, gboolean *boolean);
126 int asn1_int32_value_decode (ASN1_SCK *asn1, int enc_len, gint32 *integer);
127 int asn1_int32_decode (ASN1_SCK *asn1, gint32 *integer, guint *nbytes);
128 int asn1_uint32_value_decode (ASN1_SCK *asn1, int enc_len, guint *integer);
129 int asn1_uint32_decode (ASN1_SCK *asn1, guint32 *integer, guint *nbytes);
130 int asn1_bits_decode (ASN1_SCK *asn1, int eoc, guchar **bits,
131 guint *len, guchar *unused);
132 int asn1_string_value_decode (ASN1_SCK *asn1, int enc_len,
134 int asn1_string_decode (ASN1_SCK *asn1, guchar **octets, guint *str_len,
135 guint *nbytes, guint expected_tag);
136 int asn1_octet_string_decode (ASN1_SCK *asn1, guchar **octets, guint *str_len,
138 int asn1_subid_decode (ASN1_SCK *asn1, subid_t *subid);
139 int asn1_oid_value_decode (ASN1_SCK *asn1, int enc_len, subid_t **oid,
141 int asn1_oid_decode ( ASN1_SCK *asn1, subid_t **oid, guint *len, guint *nbytes);
142 int asn1_sequence_decode ( ASN1_SCK *asn1, guint *seq_len, guint *nbytes);
144 char *asn1_err_to_str (int err);