]> git.ipfire.org Git - thirdparty/squid.git/blob - include/asn1.h
fix some int/long problems for 64bit systems
[thirdparty/squid.git] / include / asn1.h
1 /*
2 * Definitions for Abstract Syntax Notation One, ASN.1
3 * As defined in ISO/IS 8824 and ISO/IS 8825
4 *
5 *
6 */
7 /***********************************************************
8 Copyright 1988, 1989 by Carnegie Mellon University
9
10 All Rights Reserved
11
12 Permission to use, copy, modify, and distribute this software and its
13 documentation for any purpose and without fee is hereby granted,
14 provided that the above copyright notice appear in all copies and that
15 both that copyright notice and this permission notice appear in
16 supporting documentation, and that the name of CMU not be
17 used in advertising or publicity pertaining to distribution of the
18 software without specific, written prior permission.
19
20 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
21 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
22 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
23 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
24 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
25 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
26 SOFTWARE.
27 ******************************************************************/
28
29 #ifndef ASN1_H
30 #define ASN1_H
31
32 /* assume someone else includes "config.h" for us */
33 #if HAVE_SYS_TYPES_H
34 #include <sys/types.h>
35 #endif
36
37 #ifndef EIGHTBIT_SUBIDS
38 typedef u_long oid;
39 #define MAX_SUBID 0xFFFFFFFF
40 #else
41 typedef u_char oid;
42 #define MAX_SUBID 0xFF
43 #endif
44
45 #define MAX_OID_LEN 64 /* max subid's in an oid */
46
47 #define ASN_BOOLEAN (0x01)
48 #define ASN_INTEGER (0x02)
49 #define ASN_BIT_STR (0x03)
50 #define ASN_OCTET_STR (0x04)
51 #define ASN_NULL (0x05)
52 #define ASN_OBJECT_ID (0x06)
53 #define ASN_SEQUENCE (0x10)
54 #define ASN_SET (0x11)
55
56 #define ASN_UNIVERSAL (0x00)
57 #define ASN_APPLICATION (0x40)
58 #define ASN_CONTEXT (0x80)
59 #define ASN_PRIVATE (0xC0)
60
61 #define ASN_PRIMITIVE (0x00)
62 #define ASN_CONSTRUCTOR (0x20)
63
64 #define ASN_LONG_LEN (0x80)
65 #define ASN_EXTENSION_ID (0x1F)
66 #define ASN_BIT8 (0x80)
67
68 #define IS_CONSTRUCTOR(byte) ((byte) & ASN_CONSTRUCTOR)
69 #define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) == ASN_EXTENSION_ID)
70
71 /* 32 bit integer compatability hack */
72 #if SIZEOF_INT == 4
73 typedef int num32;
74 typedef unsigned int u_num32;
75 #elif SIZEOF_LONG == 4
76 typedef long num32;
77 typedef unsigned long u_num32;
78 #else
79 typedef long num32; /* assume that long's are 32bit */
80 typedef unsigned long u_num32;
81 #endif
82 #define NUM32LEN sizeof(num32) /* this should always be 4 */
83
84 /*
85 * internal 64 bit representation:
86 */
87 struct counter64 {
88 u_num32 high;
89 u_num32 low;
90 };
91
92 extern u_char *asn_parse_int (u_char * data,
93 int *datalength,
94 u_char * type,
95 long *intp,
96 int intsize);
97
98 extern u_char *asn_build_int (u_char * data,
99 int *datalength,
100 u_char type,
101 long *intp,
102 int intsize);
103
104 extern u_char *asn_parse_unsigned_int (u_char * data,
105 int *datalength,
106 u_char * type,
107 u_long * intp,
108 int intsize);
109
110 extern u_char *asn_build_unsigned_int (u_char * data,
111 int *datalength,
112 u_char type,
113 u_long * intp,
114 int intsize);
115
116 extern u_char *asn_parse_string (u_char * data,
117 int *datalength,
118 u_char * type,
119 u_char * string,
120 int *len);
121
122 extern u_char *asn_build_string (u_char * data,
123 int *datalength,
124 u_char type,
125 u_char * str,
126 int len);
127
128 extern u_char *asn_parse_header (u_char * data,
129 int *datalength,
130 u_char * type);
131
132 extern u_char *asn_build_header (u_char * data,
133 int *datalength,
134 u_char type,
135 int len);
136
137 extern u_char *asn_build_sequence (u_char * data,
138 int *datalength,
139 u_char type,
140 int len);
141
142 extern u_char *asn_parse_length (u_char * data,
143 u_long * eln);
144
145 extern u_char *asn_build_length (u_char * data,
146 int *datalength,
147 int len);
148
149 extern u_char *asn_parse_objid (
150 u_char * data,
151 int *datalength,
152 u_char * type,
153 oid * objid,
154 int *objidlength);
155
156 extern u_char *asn_build_objid (u_char * data,
157 int *datalength,
158 u_char type,
159 oid * objid,
160 int objidlength);
161
162 extern u_char *asn_parse_null (u_char * data,
163 int *datalength,
164 u_char * type);
165
166 extern u_char *asn_build_null (u_char * data,
167 int *datalength,
168 u_char type);
169 extern u_char *asn_parse_bitstring (u_char * data,
170 int *datalength,
171 u_char * type,
172 u_char * str,
173 int *len);
174
175 extern u_char *asn_build_bitstring (u_char * data,
176 int *datalength,
177 u_char type,
178 u_char * str,
179 int len);
180
181 extern u_char *asn_parse_unsigned_int64 (u_char * data,
182 int *datalength,
183 u_char * type,
184 struct counter64 * cp,
185 int cp_size);
186
187 extern u_char *asn_build_unsigned_int64 (u_char * data,
188 int *datalength,
189 u_char type,
190 struct counter64 * cp,
191 int cp_size);
192
193 #endif