libtommath: Fix possible integer overflow CVE-2023-36328
[heimdal.git] / lib / asn1 / asn1-common.h
blob7797eed49b64f16501677159cd5af9a3468f441f
1 /* $Id$ */
3 #include <stddef.h>
4 #include <time.h>
5 #include <krb5-types.h>
7 #ifndef __asn1_common_definitions__
8 #define __asn1_common_definitions__
10 #ifndef __HEIM_BASE_DATA__
11 #define __HEIM_BASE_DATA__ 1
12 struct heim_base_data {
13 size_t length;
14 void *data;
16 #endif
18 typedef struct heim_integer {
19 size_t length;
20 void *data;
21 int negative;
22 } heim_integer;
24 typedef struct heim_base_data heim_octet_string;
26 typedef char *heim_general_string;
27 typedef char *heim_utf8_string;
28 typedef struct heim_base_data heim_printable_string;
29 typedef struct heim_base_data heim_ia5_string;
31 typedef struct heim_bmp_string {
32 size_t length;
33 uint16_t *data;
34 } heim_bmp_string;
36 typedef struct heim_universal_string {
37 size_t length;
38 uint32_t *data;
39 } heim_universal_string;
41 typedef char *heim_visible_string;
43 typedef struct heim_oid {
44 size_t length;
45 unsigned *components;
46 } heim_oid;
48 typedef struct heim_bit_string {
49 size_t length;
50 void *data;
51 } heim_bit_string;
53 typedef struct heim_base_data heim_any;
54 typedef struct heim_base_data heim_any_set;
55 typedef struct heim_base_data HEIM_ANY;
56 typedef struct heim_base_data HEIM_ANY_SET;
58 enum asn1_print_flags {
59 ASN1_PRINT_INDENT = 1,
62 #define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R) \
63 do { \
64 (BL) = length_##T((S)); \
65 (B) = malloc((BL)); \
66 if((B) == NULL) { \
67 (R) = ENOMEM; \
68 } else { \
69 (R) = encode_##T(((unsigned char*)(B)) + (BL) - 1, (BL), \
70 (S), (L)); \
71 if((R) != 0) { \
72 free((B)); \
73 (B) = NULL; \
74 } \
75 } \
76 } while (0)
78 #ifdef _WIN32
79 #ifndef ASN1_LIB
80 #define ASN1EXP __declspec(dllimport)
81 #else
82 #define ASN1EXP
83 #endif
84 #define ASN1CALL __stdcall
85 #else
86 #define ASN1EXP
87 #define ASN1CALL
88 #endif
90 #endif