asn1crt.h 6.27 KB
Newer Older
yoogx's avatar
yoogx committed
1
2
#ifndef ASN1SCC_ASN1CRT_H_
#define ASN1SCC_ASN1CRT_H_
3

Maxime Perrotin's avatar
Maxime Perrotin committed
4
5
#include <stddef.h>

6
7
<<<<<<< HEAD
=======
yoogx's avatar
yoogx committed
8
9
10
11
12
13
14
15
16
#if (!defined(_MSC_VER) || _MSC_VER >= 1800)
#  ifndef SWIG
#    include <stdbool.h>
#  endif
#else
typedef unsigned char bool;
#define true 1
#define false 0
#endif
17
>>>>>>> 0e86b129902a792f4ae0c4a6bacb781c57331060
18
19
20

#ifdef  __cplusplus
extern "C" {
Maxime Perrotin's avatar
Maxime Perrotin committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <cstdint>
#else
// C99 check
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#  include <stdbool.h>
#  include <stdint.h>
#else

typedef unsigned char bool;
#  define true 1
#  define false 0

typedef unsigned char uint8_t;

typedef int int32_t;
typedef unsigned int uint32_t;

typedef long long int64_t;
typedef unsigned long long uint64_t;

41
#endif
Maxime Perrotin's avatar
Maxime Perrotin committed
42
#endif	/* __cplusplus */
43
44
45
46
47

#ifndef NULL
#define NULL	0
#endif

jdelange's avatar
jdelange committed
48
#ifndef TRUE
yoogx's avatar
yoogx committed
49
#define TRUE	true
jdelange's avatar
jdelange committed
50
#endif
51

jdelange's avatar
jdelange committed
52
#ifndef FALSE
yoogx's avatar
yoogx committed
53
#define FALSE	false
jdelange's avatar
jdelange committed
54
#endif
55
56
57
58
59

#ifndef WORD_SIZE
#define WORD_SIZE	8
#endif

60
61
62
#ifndef FP_WORD_SIZE
#define FP_WORD_SIZE	8
#endif
63
<<<<<<< HEAD
64

Maxime Perrotin's avatar
Maxime Perrotin committed
65
#define OBJECT_IDENTIFIER_MAX_LENGTH	20
66
=======
67

68
#define OBJECT_IDENTIFIER_MAX_LENGTH	20
69
70
71
72

typedef float asn1Real32;
typedef double asn1Real64;

73

74
75
76
77
>>>>>>> 0e86b129902a792f4ae0c4a6bacb781c57331060


<<<<<<< HEAD
78
79
80
typedef float asn1Real32;
typedef double asn1Real64;

Maxime Perrotin's avatar
Maxime Perrotin committed
81
typedef uint8_t byte;
yoogx's avatar
yoogx committed
82

Maxime Perrotin's avatar
Maxime Perrotin committed
83
84
typedef int32_t asn1SccSint32;
typedef uint32_t asn1SccUint32;
85

Maxime Perrotin's avatar
Maxime Perrotin committed
86
87
typedef int64_t asn1SccSint64;
typedef uint64_t asn1SccUint64;
88

89
=======
90
91
typedef int asn1SccSint32;
typedef unsigned int asn1SccUint32;
92
93
94

typedef long long asn1SccSint64;
typedef unsigned long long asn1SccUint64;
95

96
>>>>>>> 0e86b129902a792f4ae0c4a6bacb781c57331060
97
#if WORD_SIZE==8
98
99
100
101
102
typedef asn1SccUint64 asn1SccUint;
typedef asn1SccSint64 asn1SccSint;
#else
typedef asn1SccUint32 asn1SccUint;
typedef asn1SccSint32 asn1SccSint;
103
#endif
104

105
<<<<<<< HEAD
Maxime Perrotin's avatar
Maxime Perrotin committed
106
107
108
asn1SccUint int2uint(asn1SccSint v);
asn1SccSint uint2int(asn1SccUint v, int uintSizeInBytes);

109
110
=======
>>>>>>> 0e86b129902a792f4ae0c4a6bacb781c57331060
111
112
113
114
#if FP_WORD_SIZE==8
typedef asn1Real64 asn1Real;
#else
typedef asn1Real32 asn1Real;
115
116
#endif

117

yoogx's avatar
yoogx committed
118
119
120
121
122
123
124
125
#ifdef _MSC_VER
#  ifndef INFINITY
#    define INFINITY (DBL_MAX+DBL_MAX)
#  endif
#  ifndef NAN
#    define NAN (INFINITY-INFINITY)
#  endif
#endif
126

yoogx's avatar
yoogx committed
127
typedef bool flag;
128
129
130

typedef char NullType;

Maxime Perrotin's avatar
Maxime Perrotin committed
131
132
133
134
135
136
struct BitStream_t;

typedef void(*PushDataFnc)(struct BitStream_t* pThis, void* pushDataPrm);
typedef void(*FetchDataFnc)(struct BitStream_t* pThis, void* fetchDataPrm);

typedef struct BitStream_t {
137
138
139
	byte* buf;
	long count;
	long currentByte;
Maxime Perrotin's avatar
Maxime Perrotin committed
140
141
142
	/* Next available bit for writting. 
	Possible vallues 0..7, 0 is most significant 
	bit of current byte*/
143
	int currentBit; 
Maxime Perrotin's avatar
Maxime Perrotin committed
144
145
146
147
	PushDataFnc pushData;
	void* pushDataPrm;
	FetchDataFnc fetchData;
	void* fetchDataPrm;
148
149
} BitStream;

Maxime Perrotin's avatar
Maxime Perrotin committed
150
151
152
153




154
155
156
157
typedef struct {
	byte* buf;
	long count;
	long currentByte;
jdelange's avatar
jdelange committed
158
	flag EncodeWhiteSpace;
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
} ByteStream;

typedef struct {
	int TokenID;
	char Value[100];
} Token;

typedef struct {
	char Name[50];
	char Value[100];
} XmlAttribute;

typedef struct {
	XmlAttribute attrs[20];
	int nCount;
} XmlAttributeArray;

Maxime Perrotin's avatar
Maxime Perrotin committed
176
177
178
179
typedef struct {
	int nCount;
	asn1SccUint values[OBJECT_IDENTIFIER_MAX_LENGTH];
} Asn1ObjectIdentifier;
180
181
182
183

#define ERR_INSUFFICIENT_DATA	101
#define ERR_INCORRECT_PER_STREAM	102
#define ERR_INVALID_CHOICE_ALTERNATIVE	103
yoogx's avatar
yoogx committed
184
#define ERR_INVALID_ENUM_VALUE	104
185
186
187
188
#define ERR_INVALID_XML_FILE	200
#define ERR_INVALID_BER_FILE	201
#define ERR_BER_LENGTH_MISMATCH	202

189
<<<<<<< HEAD
190
191
int GetCharIndex(char ch, byte allowedCharSet[], int setLen);

Maxime Perrotin's avatar
Maxime Perrotin committed
192
193
194
195
196
197
198
199
200
201
202
203
204
void ObjectIdentifier_Init(Asn1ObjectIdentifier *pVal);
flag ObjectIdentifier_equal(const Asn1ObjectIdentifier *pVal1, const Asn1ObjectIdentifier *pVal2);
flag ObjectIdentifier_isValid(const Asn1ObjectIdentifier *pVal);
flag RelativeOID_isValid(const Asn1ObjectIdentifier *pVal);

/* Time Classes
	Asn1LocalTime,					// TIME-OF-DAY  ::= TIME(SETTINGS "Basic=Time Time=HMS Local-or-UTC=L")
	Asn1UtcTime,					//                  TIME(SETTINGS "Basic=Time Time=HMS Local-or-UTC=Z")
	Asn1LocalTimeWithTimeZone,		//                  TIME(SETTINGS "Basic=Time Time=HMS Local-or-UTC=LD")
	Asn1Date,						//  DATE ::=        TIME(SETTINGS "Basic=Date Date=YMD Year=Basic")
	Asn1Date_LocalTime,				//  DATE-TIME   ::= TIME(SETTINGS "Basic=Date-Time Date=YMD Year=Basic Time=HMS Local-or-UTC=L")
	Asn1Date_UtcTime,				// 			        TIME(SETTINGS "Basic=Date-Time Date=YMD Year=Basic Time=HMS Local-or-UTC=Z")
	Asn1Date_LocalTimeWithTimeZone	//                  TIME(SETTINGS "Basic=Date-Time Date=YMD Year=Basic Time=HMS Local-or-UTC=LD")
205
*/
Maxime Perrotin's avatar
Maxime Perrotin committed
206
207
208
209
210
typedef struct {
	int sign;		//-1 or +1
	int hours;
	int mins;
} Asn1TimeZone;
211

Maxime Perrotin's avatar
Maxime Perrotin committed
212
213
214
215
216
217
218
typedef struct {
	int hours;
	int mins;
	int secs;
	int fraction;
	Asn1TimeZone tz;
} Asn1TimeWithTimeZone;
219

Maxime Perrotin's avatar
Maxime Perrotin committed
220
221
222
223
224
225
typedef struct {
	int hours;
	int mins;
	int secs;
	int fraction;
} Asn1UtcTime;
226

Maxime Perrotin's avatar
Maxime Perrotin committed
227
228
229
230
231
232
typedef struct {
	int hours;
	int mins;
	int secs;
	int fraction;
} Asn1LocalTime;
233

Maxime Perrotin's avatar
Maxime Perrotin committed
234
235
236
237
238
typedef struct {
	int years;
	int months;
	int days;
} Asn1Date;
239

Maxime Perrotin's avatar
Maxime Perrotin committed
240
241
242
243
typedef struct {
	Asn1Date	   date;
	Asn1LocalTime  time;
} Asn1DateLocalTime;
244
=======
245
246


247
248
249
250
251
252
flag OctetString_equal(int len1, int len2, const byte arr1[], const byte arr2[]);
flag BitString_equal(int nBitsLength1, int nBitsLength2, const byte arr1[], const byte arr2[]);
void ObjectIdentifier_Init(Asn1ObjectIdentifier *pVal);
flag ObjectIdentifier_equal(const Asn1ObjectIdentifier *pVal1, const Asn1ObjectIdentifier *pVal2);
flag ObjectIdentifier_isValid(const Asn1ObjectIdentifier *pVal);
flag RelativeOID_isValid(const Asn1ObjectIdentifier *pVal);
253
254
255
256
257
258


int GetCharIndex(char ch, byte allowedCharSet[], int setLen);



259
>>>>>>> 0e86b129902a792f4ae0c4a6bacb781c57331060
260

Maxime Perrotin's avatar
Maxime Perrotin committed
261
262
263
264
typedef struct {
	Asn1Date	 date;
	Asn1UtcTime  time;
} Asn1DateUtcTime;
265

Maxime Perrotin's avatar
Maxime Perrotin committed
266
267
268
269
typedef struct {
	Asn1Date	 date;
	Asn1TimeWithTimeZone  time;
} Asn1DateTimeWithTimeZone;
270

Maxime Perrotin's avatar
Maxime Perrotin committed
271
272
273
274
275
typedef enum {
	Asn1TC_LocalTimeStamp,
	Asn1TC_UtcTimeStamp,
	Asn1TC_LocalTimeTZStamp
} Asn1TimeZoneClass;
276
277
278

typedef asn1SccUint BerTag;

279
280
<<<<<<< HEAD
=======
281
282
283
284
285





286
>>>>>>> 0e86b129902a792f4ae0c4a6bacb781c57331060
287
288
289
290
291
#if WORD_SIZE==8
extern const asn1SccUint64 ber_aux[];
#else
extern const asn1SccUint32 ber_aux[];
#endif
292
293
<<<<<<< HEAD
=======
294
295
296



297
>>>>>>> 0e86b129902a792f4ae0c4a6bacb781c57331060
298

299
300
301
302
303
304
305
306
307
308
309
310
311
312
#define CHECK_BIT_STREAM(pBitStrm)	assert((pBitStrm)->currentByte*8+(pBitStrm)->currentBit<=(pBitStrm)->count*8)

#ifdef _MSC_VER
#pragma warning( disable : 4127)
#endif

#define ASSERT_OR_RETURN_FALSE(_Expression) do { assert(_Expression); if (!(_Expression)) return FALSE;} while(0)

#ifdef  __cplusplus
}
#endif


#endif