Always declare, and define, "file_seek()" to return a "long", as it's
[obnox/wireshark/wip.git] / asn1.h
1 /* asn1.h
2  * Definitions for ASN.1 BER dissection
3  *
4  * $Id: asn1.h,v 1.2 1999/12/10 09:49:29 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  *
9  * Based on "g_asn1.h" from:
10  *
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
14  *
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.
19  *
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.
24  *
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.
28  *
29  */
30 #ifndef __ASN1_H__
31 #define __ASN1_H__
32
33 #define ASN1_UNI       0     /* Universal   */
34 #define ASN1_APL       1     /* Application */
35 #define ASN1_CTX       2     /* Context     */
36 #define ASN1_PRV       3     /* Private     */
37
38                              /* Tag                */
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_SEQ       16    /* Sequence           */
49 #define ASN1_SET       17    /* Set                */
50 #define ASN1_NUMSTR    18    /* Numerical String   */
51 #define ASN1_PRNSTR    19    /* Printable String   */
52 #define ASN1_TEXSTR    20    /* Teletext String    */
53 #define ASN1_VIDSTR    21    /* Video String       */
54 #define ASN1_IA5STR    22    /* IA5 String         */
55 #define ASN1_UNITIM    23    /* Universal Time     */
56 #define ASN1_GENTIM    24    /* General Time       */
57 #define ASN1_GRASTR    25    /* Graphical String   */
58 #define ASN1_VISSTR    26    /* Visible String     */
59 #define ASN1_GENSTR    27    /* General String     */
60
61                              /* Primitive / Constructed */
62 #define ASN1_PRI     0       /* Primitive               */
63 #define ASN1_CON     1       /* Constructed             */
64
65 /*
66  * Oh, this is hellish.
67  *
68  * The CMU SNMP library defines an OID as a sequence of "u_int"s,
69  * unless EIGHTBIT_SUBIDS is defined, in which case it defines
70  * an OID as a sequence of "u_char"s.  None of its header files
71  * define EIGHTBIT_SUBIDS, and if a program defines it, that's
72  * not going to change the library to treat OIDs as sequences
73  * of "u_chars", so I'll assume that it'll be "u_int"s.
74  *
75  * The UCD SNMP library does the same, except it defines an OID
76  * as a sequence of "u_long"s, by default.
77  *
78  * "libsmi" defines it as a sequence of "unsigned int"s.
79  *
80  * I don't want to oblige all users of ASN.1 to include the SNMP
81  * library header files, so I'll assume none of the SNMP libraries
82  * will rudely surprise me by changing the definition; if they
83  * do, there will be compiler warnings, so we'll at least be able
84  * to catch it.
85  *
86  * This requires that, if you're going to use "asn1_subid_decode()",
87  * "asn1_oid_value_decode()", or "asn1_oid_decode()", you include
88  * "config.h", to get the right #defines defined, so that we properly
89  * typedef "subid_t".
90  */
91 #if defined(HAVE_UCD_SNMP_SNMP_H)
92 typedef u_long  subid_t;        /* UCD SNMP */
93 #else
94 typedef u_int   subid_t;        /* CMU SNMP, libsmi, or nothing */
95 #endif
96
97 #define ASN1_ERR_NOERROR                0       /* no error */
98 #define ASN1_ERR_EMPTY                  1       /* ran out of data */
99 #define ASN1_ERR_EOC_MISMATCH           2
100 #define ASN1_ERR_WRONG_TYPE             3       /* type not right */
101 #define ASN1_ERR_LENGTH_NOT_DEFINITE    4       /* length should be definite */
102 #define ASN1_ERR_LENGTH_MISMATCH        5
103 #define ASN1_ERR_WRONG_LENGTH_FOR_TYPE  6       /* length wrong for type */
104
105 typedef struct _ASN1_SCK ASN1_SCK;
106
107 struct _ASN1_SCK
108 {                           /* ASN1 socket                         */
109     const guchar *pointer;  /* Octet just encoded or to be decoded */
110     const guchar *begin;    /* First octet                         */
111     const guchar *end;      /* Octet after last octet              */
112 };
113
114 void asn1_open (ASN1_SCK *asn1, const guchar *buf, guint len);
115 void asn1_close (ASN1_SCK *asn1, const guchar **buf, guint *len);
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, const guchar *eoc);
123 int asn1_eoc_decode (ASN1_SCK *asn1, const guchar *eoc);
124 int asn1_null_decode (ASN1_SCK *asn1, int enc_len);
125 int asn1_bool_decode (ASN1_SCK *asn1, int enc_len, gboolean *bool);
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, const guchar *eoc, guchar **bits, 
131                              guint *len, guchar *unused);
132 int asn1_octet_string_value_decode (ASN1_SCK *asn1, int enc_len,
133                         guchar **octets);
134 int asn1_octet_string_decode (ASN1_SCK *asn1, guchar **octets, guint *str_len,
135                         guint *nbytes);
136 int asn1_subid_decode (ASN1_SCK *asn1, subid_t *subid);
137 int asn1_oid_value_decode (ASN1_SCK *asn1, int enc_len, subid_t **oid,
138                         guint *len);
139 int asn1_oid_decode ( ASN1_SCK *asn1, subid_t **oid, guint *len, guint *nbytes);
140 int asn1_sequence_decode ( ASN1_SCK *asn1, guint *seq_len, guint *nbytes);
141 #endif