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

4
5
#include <stddef.h>

yoogx's avatar
yoogx committed
6
7
8
9
10
11
12
13
14
#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
15
16
17
18
19
20
21
22
23

#ifdef  __cplusplus
extern "C" {
#endif

#ifndef NULL
#define NULL	0
#endif

jdelange's avatar
jdelange committed
24
#ifndef TRUE
yoogx's avatar
yoogx committed
25
#define TRUE	true
jdelange's avatar
jdelange committed
26
#endif
27

jdelange's avatar
jdelange committed
28
#ifndef FALSE
yoogx's avatar
yoogx committed
29
#define FALSE	false
jdelange's avatar
jdelange committed
30
#endif
31
32
33
34
35

#ifndef WORD_SIZE
#define WORD_SIZE	8
#endif

36
37
38
39
40
41
42
43
44
#ifndef FP_WORD_SIZE
#define FP_WORD_SIZE	8
#endif

#define OBJECT_IDENTIFIER_MAX_LENGTH	20

typedef float asn1Real32;
typedef double asn1Real64;

yoogx's avatar
yoogx committed
45

46
47
48

typedef unsigned char byte;

49
50
typedef int asn1SccSint32;
typedef unsigned int asn1SccUint32;
51
52
53

typedef long long asn1SccSint64;
typedef unsigned long long asn1SccUint64;
54
55

#if WORD_SIZE==8
56
57
58
59
60
typedef asn1SccUint64 asn1SccUint;
typedef asn1SccSint64 asn1SccSint;
#else
typedef asn1SccUint32 asn1SccUint;
typedef asn1SccSint32 asn1SccSint;
61
#endif
62

63
64
65
66
#if FP_WORD_SIZE==8
typedef asn1Real64 asn1Real;
#else
typedef asn1Real32 asn1Real;
67
68
#endif

69

yoogx's avatar
yoogx committed
70
71
72
73
74
75
76
77
#ifdef _MSC_VER
#  ifndef INFINITY
#    define INFINITY (DBL_MAX+DBL_MAX)
#  endif
#  ifndef NAN
#    define NAN (INFINITY-INFINITY)
#  endif
#endif
78

yoogx's avatar
yoogx committed
79
typedef bool flag;
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

typedef char NullType;

typedef struct {
	byte* buf;
	long count;
	long currentByte;
	/* Next available bit for writting. Possible vallues 0..7, 0 is most significant bit of current byte*/
	int currentBit; 
} BitStream;

typedef struct {
	byte* buf;
	long count;
	long currentByte;
jdelange's avatar
jdelange committed
95
	flag EncodeWhiteSpace;
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
} 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;

113
114
115
116
typedef struct {
	int nCount;
	asn1SccUint values[OBJECT_IDENTIFIER_MAX_LENGTH];
} Asn1ObjectIdentifier;
117
118
119
120

#define ERR_INSUFFICIENT_DATA	101
#define ERR_INCORRECT_PER_STREAM	102
#define ERR_INVALID_CHOICE_ALTERNATIVE	103
yoogx's avatar
yoogx committed
121
#define ERR_INVALID_ENUM_VALUE	104
122
123
124
125
126
127
#define ERR_INVALID_XML_FILE	200
#define ERR_INVALID_BER_FILE	201
#define ERR_BER_LENGTH_MISMATCH	202



128
129
130
131
132
133
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);
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150


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







typedef asn1SccUint BerTag;






151
152
153
154
155
#if WORD_SIZE==8
extern const asn1SccUint64 ber_aux[];
#else
extern const asn1SccUint32 ber_aux[];
#endif
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173




#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