xref: /freebsd/crypto/heimdal/lib/asn1/asn1-common.h (revision 193d9e768ba63fcfb187cfd17f461f7d41345048)
1 /* $Id$ */
2 
3 #include <stddef.h>
4 #include <time.h>
5 #include <krb5-types.h>
6 
7 #ifndef __asn1_common_definitions__
8 #define __asn1_common_definitions__
9 
10 typedef struct heim_integer {
11     size_t length;
12     void *data;
13     int negative;
14 } heim_integer;
15 
16 typedef struct heim_octet_string {
17     size_t length;
18     void *data;
19 } heim_octet_string;
20 
21 typedef char *heim_general_string;
22 typedef char *heim_utf8_string;
23 typedef struct heim_octet_string heim_printable_string;
24 typedef struct heim_octet_string heim_ia5_string;
25 
26 typedef struct heim_bmp_string {
27     size_t length;
28     uint16_t *data;
29 } heim_bmp_string;
30 
31 typedef struct heim_universal_string {
32     size_t length;
33     uint32_t *data;
34 } heim_universal_string;
35 
36 typedef char *heim_visible_string;
37 
38 typedef struct heim_oid {
39     size_t length;
40     unsigned *components;
41 } heim_oid;
42 
43 typedef struct heim_bit_string {
44     size_t length;
45     void *data;
46 } heim_bit_string;
47 
48 typedef struct heim_octet_string heim_any;
49 typedef struct heim_octet_string heim_any_set;
50 
51 #define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R)                  \
52   do {                                                         \
53     (BL) = length_##T((S));                                    \
54     (B) = malloc((BL));                                        \
55     if((B) == NULL) {                                          \
56       (R) = ENOMEM;                                            \
57     } else {                                                   \
58       (R) = encode_##T(((unsigned char*)(B)) + (BL) - 1, (BL), \
59                        (S), (L));                              \
60       if((R) != 0) {                                           \
61         free((B));                                             \
62         (B) = NULL;                                            \
63       }                                                        \
64     }                                                          \
65   } while (0)
66 
67 #ifdef _WIN32
68 #ifndef ASN1_LIB
69 #define ASN1EXP  __declspec(dllimport)
70 #else
71 #define ASN1EXP
72 #endif
73 #define ASN1CALL __stdcall
74 #else
75 #define ASN1EXP
76 #define ASN1CALL
77 #endif
78 
79 #endif
80