jpayne@69
|
1 /*
|
jpayne@69
|
2 * Copyright 1999-2019 The OpenSSL Project Authors. All Rights Reserved.
|
jpayne@69
|
3 *
|
jpayne@69
|
4 * Licensed under the OpenSSL license (the "License"). You may not use
|
jpayne@69
|
5 * this file except in compliance with the License. You can obtain a copy
|
jpayne@69
|
6 * in the file LICENSE in the source distribution or at
|
jpayne@69
|
7 * https://www.openssl.org/source/license.html
|
jpayne@69
|
8 */
|
jpayne@69
|
9
|
jpayne@69
|
10 #ifndef HEADER_SAFESTACK_H
|
jpayne@69
|
11 # define HEADER_SAFESTACK_H
|
jpayne@69
|
12
|
jpayne@69
|
13 # include <openssl/stack.h>
|
jpayne@69
|
14 # include <openssl/e_os2.h>
|
jpayne@69
|
15
|
jpayne@69
|
16 #ifdef __cplusplus
|
jpayne@69
|
17 extern "C" {
|
jpayne@69
|
18 #endif
|
jpayne@69
|
19
|
jpayne@69
|
20 # define STACK_OF(type) struct stack_st_##type
|
jpayne@69
|
21
|
jpayne@69
|
22 # define SKM_DEFINE_STACK_OF(t1, t2, t3) \
|
jpayne@69
|
23 STACK_OF(t1); \
|
jpayne@69
|
24 typedef int (*sk_##t1##_compfunc)(const t3 * const *a, const t3 *const *b); \
|
jpayne@69
|
25 typedef void (*sk_##t1##_freefunc)(t3 *a); \
|
jpayne@69
|
26 typedef t3 * (*sk_##t1##_copyfunc)(const t3 *a); \
|
jpayne@69
|
27 static ossl_unused ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \
|
jpayne@69
|
28 { \
|
jpayne@69
|
29 return OPENSSL_sk_num((const OPENSSL_STACK *)sk); \
|
jpayne@69
|
30 } \
|
jpayne@69
|
31 static ossl_unused ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \
|
jpayne@69
|
32 { \
|
jpayne@69
|
33 return (t2 *)OPENSSL_sk_value((const OPENSSL_STACK *)sk, idx); \
|
jpayne@69
|
34 } \
|
jpayne@69
|
35 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \
|
jpayne@69
|
36 { \
|
jpayne@69
|
37 return (STACK_OF(t1) *)OPENSSL_sk_new((OPENSSL_sk_compfunc)compare); \
|
jpayne@69
|
38 } \
|
jpayne@69
|
39 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \
|
jpayne@69
|
40 { \
|
jpayne@69
|
41 return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \
|
jpayne@69
|
42 } \
|
jpayne@69
|
43 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_reserve(sk_##t1##_compfunc compare, int n) \
|
jpayne@69
|
44 { \
|
jpayne@69
|
45 return (STACK_OF(t1) *)OPENSSL_sk_new_reserve((OPENSSL_sk_compfunc)compare, n); \
|
jpayne@69
|
46 } \
|
jpayne@69
|
47 static ossl_unused ossl_inline int sk_##t1##_reserve(STACK_OF(t1) *sk, int n) \
|
jpayne@69
|
48 { \
|
jpayne@69
|
49 return OPENSSL_sk_reserve((OPENSSL_STACK *)sk, n); \
|
jpayne@69
|
50 } \
|
jpayne@69
|
51 static ossl_unused ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \
|
jpayne@69
|
52 { \
|
jpayne@69
|
53 OPENSSL_sk_free((OPENSSL_STACK *)sk); \
|
jpayne@69
|
54 } \
|
jpayne@69
|
55 static ossl_unused ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \
|
jpayne@69
|
56 { \
|
jpayne@69
|
57 OPENSSL_sk_zero((OPENSSL_STACK *)sk); \
|
jpayne@69
|
58 } \
|
jpayne@69
|
59 static ossl_unused ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \
|
jpayne@69
|
60 { \
|
jpayne@69
|
61 return (t2 *)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); \
|
jpayne@69
|
62 } \
|
jpayne@69
|
63 static ossl_unused ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \
|
jpayne@69
|
64 { \
|
jpayne@69
|
65 return (t2 *)OPENSSL_sk_delete_ptr((OPENSSL_STACK *)sk, \
|
jpayne@69
|
66 (const void *)ptr); \
|
jpayne@69
|
67 } \
|
jpayne@69
|
68 static ossl_unused ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \
|
jpayne@69
|
69 { \
|
jpayne@69
|
70 return OPENSSL_sk_push((OPENSSL_STACK *)sk, (const void *)ptr); \
|
jpayne@69
|
71 } \
|
jpayne@69
|
72 static ossl_unused ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \
|
jpayne@69
|
73 { \
|
jpayne@69
|
74 return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (const void *)ptr); \
|
jpayne@69
|
75 } \
|
jpayne@69
|
76 static ossl_unused ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
|
jpayne@69
|
77 { \
|
jpayne@69
|
78 return (t2 *)OPENSSL_sk_pop((OPENSSL_STACK *)sk); \
|
jpayne@69
|
79 } \
|
jpayne@69
|
80 static ossl_unused ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \
|
jpayne@69
|
81 { \
|
jpayne@69
|
82 return (t2 *)OPENSSL_sk_shift((OPENSSL_STACK *)sk); \
|
jpayne@69
|
83 } \
|
jpayne@69
|
84 static ossl_unused ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \
|
jpayne@69
|
85 { \
|
jpayne@69
|
86 OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc)freefunc); \
|
jpayne@69
|
87 } \
|
jpayne@69
|
88 static ossl_unused ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \
|
jpayne@69
|
89 { \
|
jpayne@69
|
90 return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (const void *)ptr, idx); \
|
jpayne@69
|
91 } \
|
jpayne@69
|
92 static ossl_unused ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \
|
jpayne@69
|
93 { \
|
jpayne@69
|
94 return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr); \
|
jpayne@69
|
95 } \
|
jpayne@69
|
96 static ossl_unused ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
|
jpayne@69
|
97 { \
|
jpayne@69
|
98 return OPENSSL_sk_find((OPENSSL_STACK *)sk, (const void *)ptr); \
|
jpayne@69
|
99 } \
|
jpayne@69
|
100 static ossl_unused ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \
|
jpayne@69
|
101 { \
|
jpayne@69
|
102 return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (const void *)ptr); \
|
jpayne@69
|
103 } \
|
jpayne@69
|
104 static ossl_unused ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \
|
jpayne@69
|
105 { \
|
jpayne@69
|
106 OPENSSL_sk_sort((OPENSSL_STACK *)sk); \
|
jpayne@69
|
107 } \
|
jpayne@69
|
108 static ossl_unused ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \
|
jpayne@69
|
109 { \
|
jpayne@69
|
110 return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \
|
jpayne@69
|
111 } \
|
jpayne@69
|
112 static ossl_unused ossl_inline STACK_OF(t1) * sk_##t1##_dup(const STACK_OF(t1) *sk) \
|
jpayne@69
|
113 { \
|
jpayne@69
|
114 return (STACK_OF(t1) *)OPENSSL_sk_dup((const OPENSSL_STACK *)sk); \
|
jpayne@69
|
115 } \
|
jpayne@69
|
116 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \
|
jpayne@69
|
117 sk_##t1##_copyfunc copyfunc, \
|
jpayne@69
|
118 sk_##t1##_freefunc freefunc) \
|
jpayne@69
|
119 { \
|
jpayne@69
|
120 return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((const OPENSSL_STACK *)sk, \
|
jpayne@69
|
121 (OPENSSL_sk_copyfunc)copyfunc, \
|
jpayne@69
|
122 (OPENSSL_sk_freefunc)freefunc); \
|
jpayne@69
|
123 } \
|
jpayne@69
|
124 static ossl_unused ossl_inline sk_##t1##_compfunc sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, sk_##t1##_compfunc compare) \
|
jpayne@69
|
125 { \
|
jpayne@69
|
126 return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \
|
jpayne@69
|
127 }
|
jpayne@69
|
128
|
jpayne@69
|
129 # define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2)
|
jpayne@69
|
130 # define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t)
|
jpayne@69
|
131 # define DEFINE_SPECIAL_STACK_OF_CONST(t1, t2) \
|
jpayne@69
|
132 SKM_DEFINE_STACK_OF(t1, const t2, t2)
|
jpayne@69
|
133 # define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t)
|
jpayne@69
|
134
|
jpayne@69
|
135 /*-
|
jpayne@69
|
136 * Strings are special: normally an lhash entry will point to a single
|
jpayne@69
|
137 * (somewhat) mutable object. In the case of strings:
|
jpayne@69
|
138 *
|
jpayne@69
|
139 * a) Instead of a single char, there is an array of chars, NUL-terminated.
|
jpayne@69
|
140 * b) The string may have be immutable.
|
jpayne@69
|
141 *
|
jpayne@69
|
142 * So, they need their own declarations. Especially important for
|
jpayne@69
|
143 * type-checking tools, such as Deputy.
|
jpayne@69
|
144 *
|
jpayne@69
|
145 * In practice, however, it appears to be hard to have a const
|
jpayne@69
|
146 * string. For now, I'm settling for dealing with the fact it is a
|
jpayne@69
|
147 * string at all.
|
jpayne@69
|
148 */
|
jpayne@69
|
149 typedef char *OPENSSL_STRING;
|
jpayne@69
|
150 typedef const char *OPENSSL_CSTRING;
|
jpayne@69
|
151
|
jpayne@69
|
152 /*-
|
jpayne@69
|
153 * Confusingly, LHASH_OF(STRING) deals with char ** throughout, but
|
jpayne@69
|
154 * STACK_OF(STRING) is really more like STACK_OF(char), only, as mentioned
|
jpayne@69
|
155 * above, instead of a single char each entry is a NUL-terminated array of
|
jpayne@69
|
156 * chars. So, we have to implement STRING specially for STACK_OF. This is
|
jpayne@69
|
157 * dealt with in the autogenerated macros below.
|
jpayne@69
|
158 */
|
jpayne@69
|
159 DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
|
jpayne@69
|
160 DEFINE_SPECIAL_STACK_OF_CONST(OPENSSL_CSTRING, char)
|
jpayne@69
|
161
|
jpayne@69
|
162 /*
|
jpayne@69
|
163 * Similarly, we sometimes use a block of characters, NOT nul-terminated.
|
jpayne@69
|
164 * These should also be distinguished from "normal" stacks.
|
jpayne@69
|
165 */
|
jpayne@69
|
166 typedef void *OPENSSL_BLOCK;
|
jpayne@69
|
167 DEFINE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
|
jpayne@69
|
168
|
jpayne@69
|
169 /*
|
jpayne@69
|
170 * If called without higher optimization (min. -xO3) the Oracle Developer
|
jpayne@69
|
171 * Studio compiler generates code for the defined (static inline) functions
|
jpayne@69
|
172 * above.
|
jpayne@69
|
173 * This would later lead to the linker complaining about missing symbols when
|
jpayne@69
|
174 * this header file is included but the resulting object is not linked against
|
jpayne@69
|
175 * the Crypto library (openssl#6912).
|
jpayne@69
|
176 */
|
jpayne@69
|
177 # ifdef __SUNPRO_C
|
jpayne@69
|
178 # pragma weak OPENSSL_sk_num
|
jpayne@69
|
179 # pragma weak OPENSSL_sk_value
|
jpayne@69
|
180 # pragma weak OPENSSL_sk_new
|
jpayne@69
|
181 # pragma weak OPENSSL_sk_new_null
|
jpayne@69
|
182 # pragma weak OPENSSL_sk_new_reserve
|
jpayne@69
|
183 # pragma weak OPENSSL_sk_reserve
|
jpayne@69
|
184 # pragma weak OPENSSL_sk_free
|
jpayne@69
|
185 # pragma weak OPENSSL_sk_zero
|
jpayne@69
|
186 # pragma weak OPENSSL_sk_delete
|
jpayne@69
|
187 # pragma weak OPENSSL_sk_delete_ptr
|
jpayne@69
|
188 # pragma weak OPENSSL_sk_push
|
jpayne@69
|
189 # pragma weak OPENSSL_sk_unshift
|
jpayne@69
|
190 # pragma weak OPENSSL_sk_pop
|
jpayne@69
|
191 # pragma weak OPENSSL_sk_shift
|
jpayne@69
|
192 # pragma weak OPENSSL_sk_pop_free
|
jpayne@69
|
193 # pragma weak OPENSSL_sk_insert
|
jpayne@69
|
194 # pragma weak OPENSSL_sk_set
|
jpayne@69
|
195 # pragma weak OPENSSL_sk_find
|
jpayne@69
|
196 # pragma weak OPENSSL_sk_find_ex
|
jpayne@69
|
197 # pragma weak OPENSSL_sk_sort
|
jpayne@69
|
198 # pragma weak OPENSSL_sk_is_sorted
|
jpayne@69
|
199 # pragma weak OPENSSL_sk_dup
|
jpayne@69
|
200 # pragma weak OPENSSL_sk_deep_copy
|
jpayne@69
|
201 # pragma weak OPENSSL_sk_set_cmp_func
|
jpayne@69
|
202 # endif /* __SUNPRO_C */
|
jpayne@69
|
203
|
jpayne@69
|
204 # ifdef __cplusplus
|
jpayne@69
|
205 }
|
jpayne@69
|
206 # endif
|
jpayne@69
|
207 #endif
|