2 * {- join("\n * ", @autowarntext) -}
4 * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved.
6 * Licensed under the Apache License 2.0 (the "License"). You may not use
7 * this file except in compliance with the License. You can obtain a copy
8 * in the file LICENSE in the source distribution or at
9 * https://www.openssl.org/source/license.html
13 use
OpenSSL::stackhash
qw(generate_stack_string_macros
14 generate_stack_const_string_macros
15 generate_stack_block_macros
);
18 #ifndef OPENSSL_SAFESTACK_H
19 # define OPENSSL_SAFESTACK_H
22 # include <openssl/macros.h>
23 # ifndef OPENSSL_NO_DEPRECATED_3_0
24 # define HEADER_SAFESTACK_H
27 # include <openssl/stack.h>
28 # include <openssl/e_os2.h>
34 # define STACK_OF(type) struct stack_st_##type
36 # define SKM_DEFINE_STACK_OF(t1, t2, t3) \
38 typedef int (*sk_##t1##_compfunc)(const t3 * const *a, const t3 *const *b); \
39 typedef void (*sk_##t1##_freefunc)(t3 *a); \
40 typedef t3 * (*sk_##t1##_copyfunc)(const t3 *a); \
41 static ossl_unused ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \
43 return OPENSSL_sk_num((const OPENSSL_STACK *)sk); \
45 static ossl_unused ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \
47 return (t2 *)OPENSSL_sk_value((const OPENSSL_STACK *)sk, idx); \
49 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \
51 return (STACK_OF(t1) *)OPENSSL_sk_new((OPENSSL_sk_compfunc)compare); \
53 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \
55 return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \
57 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_reserve(sk_##t1##_compfunc compare, int n) \
59 return (STACK_OF(t1) *)OPENSSL_sk_new_reserve((OPENSSL_sk_compfunc)compare, n); \
61 static ossl_unused ossl_inline int sk_##t1##_reserve(STACK_OF(t1) *sk, int n) \
63 return OPENSSL_sk_reserve((OPENSSL_STACK *)sk, n); \
65 static ossl_unused ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \
67 OPENSSL_sk_free((OPENSSL_STACK *)sk); \
69 static ossl_unused ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \
71 OPENSSL_sk_zero((OPENSSL_STACK *)sk); \
73 static ossl_unused ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \
75 return (t2 *)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); \
77 static ossl_unused ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \
79 return (t2 *)OPENSSL_sk_delete_ptr((OPENSSL_STACK *)sk, \
82 static ossl_unused ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \
84 return OPENSSL_sk_push((OPENSSL_STACK *)sk, (const void *)ptr); \
86 static ossl_unused ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \
88 return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (const void *)ptr); \
90 static ossl_unused ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
92 return (t2 *)OPENSSL_sk_pop((OPENSSL_STACK *)sk); \
94 static ossl_unused ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \
96 return (t2 *)OPENSSL_sk_shift((OPENSSL_STACK *)sk); \
98 static ossl_unused ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \
100 OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc)freefunc); \
102 static ossl_unused ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \
104 return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (const void *)ptr, idx); \
106 static ossl_unused ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \
108 return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr); \
110 static ossl_unused ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
112 return OPENSSL_sk_find((OPENSSL_STACK *)sk, (const void *)ptr); \
114 static ossl_unused ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \
116 return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (const void *)ptr); \
118 static ossl_unused ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \
120 OPENSSL_sk_sort((OPENSSL_STACK *)sk); \
122 static ossl_unused ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \
124 return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \
126 static ossl_unused ossl_inline STACK_OF(t1) * sk_##t1##_dup(const STACK_OF(t1) *sk) \
128 return (STACK_OF(t1) *)OPENSSL_sk_dup((const OPENSSL_STACK *)sk); \
130 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \
131 sk_##t1##_copyfunc copyfunc, \
132 sk_##t1##_freefunc freefunc) \
134 return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((const OPENSSL_STACK *)sk, \
135 (OPENSSL_sk_copyfunc)copyfunc, \
136 (OPENSSL_sk_freefunc)freefunc); \
138 static ossl_unused ossl_inline sk_##t1##_compfunc sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, sk_##t1##_compfunc compare) \
140 return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \
143 # define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t)
144 # define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t)
145 # define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2)
146 # define DEFINE_SPECIAL_STACK_OF_CONST(t1, t2) \
147 SKM_DEFINE_STACK_OF(t1, const t2, t2)
150 * Strings are special: normally an lhash entry will point to a single
151 * (somewhat) mutable object. In the case of strings:
153 * a) Instead of a single char, there is an array of chars, NUL-terminated.
154 * b) The string may have be immutable.
156 * So, they need their own declarations. Especially important for
157 * type-checking tools, such as Deputy.
159 * In practice, however, it appears to be hard to have a const
160 * string. For now, I'm settling for dealing with the fact it is a
163 typedef char *OPENSSL_STRING
;
164 typedef const char *OPENSSL_CSTRING
;
166 # define DEFINE_STACK_OF_STRING() \
167 DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
168 # define DEFINE_STACK_OF_CSTRING() \
169 DEFINE_SPECIAL_STACK_OF_CONST(OPENSSL_CSTRING, char)
172 * If we're building OpenSSL, or we have no-deprecated configured,
173 * then we don't define the inline functions (see |SKM_DEFINE_STACK_OF|,
174 * above), we just declare the stack datatypes. Otherwise, for compatibility
175 * and to not remove the API's, we define the functions. We have the
176 * trailing semicolon so that uses of this never need it.
178 #if defined(OPENSSL_BUILDING_OPENSSL) || defined(OPENSSL_NO_DEPRECATED_3_0)
179 # define DEFINE_OR_DECLARE_STACK_OF(s) STACK_OF(s);
180 # define DEFINE_OR_DECLARE_STACK_OF_STRING() STACK_OF(OPENSSL_STRING);
181 # define DEFINE_OR_DECLARE_STACK_OF_CSTRING() STACK_OF(OPENSSL_CSTRING);
183 # define DEFINE_OR_DECLARE_STACK_OF(s) DEFINE_STACK_OF(s)
184 # define DEFINE_OR_DECLARE_STACK_OF_STRING() DEFINE_STACK_OF_STRING()
185 # define DEFINE_OR_DECLARE_STACK_OF_CSTRING() DEFINE_STACK_OF_CSTRING()
189 * Confusingly, LHASH_OF(STRING) deals with char ** throughout, but
190 * STACK_OF(STRING) is really more like STACK_OF(char), only, as mentioned
191 * above, instead of a single char each entry is a NUL-terminated array of
192 * chars. So, we have to implement STRING specially for STACK_OF. This is
193 * dealt with in the autogenerated macros below.
196 generate_stack_string_macros()
197 .generate_stack_const_string_macros();
200 #if !defined(OPENSSL_NO_DEPRECATED_3_0)
202 * This is not used by OpenSSL. A block of bytes, NOT nul-terminated.
203 * These should also be distinguished from "normal" stacks.
205 typedef void *OPENSSL_BLOCK
;
207 generate_stack_block_macros();
212 * If called without higher optimization (min. -xO3) the Oracle Developer
213 * Studio compiler generates code for the defined (static inline) functions
215 * This would later lead to the linker complaining about missing symbols when
216 * this header file is included but the resulting object is not linked against
217 * the Crypto library (openssl#6912).
220 # pragma weak OPENSSL_sk_num
221 # pragma weak OPENSSL_sk_value
222 # pragma weak OPENSSL_sk_new
223 # pragma weak OPENSSL_sk_new_null
224 # pragma weak OPENSSL_sk_new_reserve
225 # pragma weak OPENSSL_sk_reserve
226 # pragma weak OPENSSL_sk_free
227 # pragma weak OPENSSL_sk_zero
228 # pragma weak OPENSSL_sk_delete
229 # pragma weak OPENSSL_sk_delete_ptr
230 # pragma weak OPENSSL_sk_push
231 # pragma weak OPENSSL_sk_unshift
232 # pragma weak OPENSSL_sk_pop
233 # pragma weak OPENSSL_sk_shift
234 # pragma weak OPENSSL_sk_pop_free
235 # pragma weak OPENSSL_sk_insert
236 # pragma weak OPENSSL_sk_set
237 # pragma weak OPENSSL_sk_find
238 # pragma weak OPENSSL_sk_find_ex
239 # pragma weak OPENSSL_sk_sort
240 # pragma weak OPENSSL_sk_is_sorted
241 # pragma weak OPENSSL_sk_dup
242 # pragma weak OPENSSL_sk_deep_copy
243 # pragma weak OPENSSL_sk_set_cmp_func
244 # endif /* __SUNPRO_C */