]>
Commit | Line | Data |
---|---|---|
21dcbebc | 1 | /* |
24c4ea95 MC |
2 | * {- join("\n * ", @autowarntext) -} |
3 | * | |
454afd98 | 4 | * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. |
f73e07cf | 5 | * |
48f4ad77 | 6 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
21dcbebc RS |
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 | |
f73e07cf BL |
10 | */ |
11 | ||
24c4ea95 MC |
12 | {- |
13 | use OpenSSL::stackhash qw(generate_stack_string_macros | |
14 | generate_stack_const_string_macros | |
15 | generate_stack_block_macros); | |
16 | -} | |
17 | ||
ae4186b0 DMSP |
18 | #ifndef OPENSSL_SAFESTACK_H |
19 | # define OPENSSL_SAFESTACK_H | |
d86167ec DMSP |
20 | # pragma once |
21 | ||
22 | # include <openssl/macros.h> | |
936c2b9e | 23 | # ifndef OPENSSL_NO_DEPRECATED_3_0 |
d86167ec DMSP |
24 | # define HEADER_SAFESTACK_H |
25 | # endif | |
f73e07cf | 26 | |
0f113f3e | 27 | # include <openssl/stack.h> |
411abf2d | 28 | # include <openssl/e_os2.h> |
f73e07cf | 29 | |
17e80c6b RS |
30 | #ifdef __cplusplus |
31 | extern "C" { | |
32 | #endif | |
33 | ||
0f113f3e | 34 | # define STACK_OF(type) struct stack_st_##type |
1d1a6465 | 35 | |
85885715 | 36 | # define SKM_DEFINE_STACK_OF(t1, t2, t3) \ |
411abf2d | 37 | STACK_OF(t1); \ |
739a1eb1 RS |
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); \ | |
48fe4ce1 | 41 | static ossl_unused ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \ |
411abf2d | 42 | { \ |
739a1eb1 | 43 | return OPENSSL_sk_num((const OPENSSL_STACK *)sk); \ |
411abf2d | 44 | } \ |
48fe4ce1 | 45 | static ossl_unused ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \ |
411abf2d | 46 | { \ |
739a1eb1 | 47 | return (t2 *)OPENSSL_sk_value((const OPENSSL_STACK *)sk, idx); \ |
411abf2d | 48 | } \ |
48fe4ce1 | 49 | static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \ |
411abf2d | 50 | { \ |
739a1eb1 | 51 | return (STACK_OF(t1) *)OPENSSL_sk_new((OPENSSL_sk_compfunc)compare); \ |
411abf2d | 52 | } \ |
48fe4ce1 | 53 | static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \ |
411abf2d | 54 | { \ |
739a1eb1 | 55 | return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \ |
411abf2d | 56 | } \ |
48fe4ce1 | 57 | static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_reserve(sk_##t1##_compfunc compare, int n) \ |
3ceab379 PY |
58 | { \ |
59 | return (STACK_OF(t1) *)OPENSSL_sk_new_reserve((OPENSSL_sk_compfunc)compare, n); \ | |
60 | } \ | |
48fe4ce1 | 61 | static ossl_unused ossl_inline int sk_##t1##_reserve(STACK_OF(t1) *sk, int n) \ |
1b3e2bbf P |
62 | { \ |
63 | return OPENSSL_sk_reserve((OPENSSL_STACK *)sk, n); \ | |
64 | } \ | |
48fe4ce1 | 65 | static ossl_unused ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \ |
411abf2d | 66 | { \ |
739a1eb1 | 67 | OPENSSL_sk_free((OPENSSL_STACK *)sk); \ |
411abf2d | 68 | } \ |
48fe4ce1 | 69 | static ossl_unused ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \ |
411abf2d | 70 | { \ |
739a1eb1 | 71 | OPENSSL_sk_zero((OPENSSL_STACK *)sk); \ |
411abf2d | 72 | } \ |
48fe4ce1 | 73 | static ossl_unused ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \ |
411abf2d | 74 | { \ |
739a1eb1 | 75 | return (t2 *)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); \ |
411abf2d | 76 | } \ |
48fe4ce1 | 77 | static ossl_unused ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \ |
411abf2d | 78 | { \ |
4591e5fb DSH |
79 | return (t2 *)OPENSSL_sk_delete_ptr((OPENSSL_STACK *)sk, \ |
80 | (const void *)ptr); \ | |
411abf2d | 81 | } \ |
48fe4ce1 | 82 | static ossl_unused ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \ |
411abf2d | 83 | { \ |
36639907 | 84 | return OPENSSL_sk_push((OPENSSL_STACK *)sk, (const void *)ptr); \ |
411abf2d | 85 | } \ |
48fe4ce1 | 86 | static ossl_unused ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \ |
411abf2d | 87 | { \ |
36639907 | 88 | return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (const void *)ptr); \ |
411abf2d | 89 | } \ |
48fe4ce1 | 90 | static ossl_unused ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \ |
411abf2d | 91 | { \ |
739a1eb1 | 92 | return (t2 *)OPENSSL_sk_pop((OPENSSL_STACK *)sk); \ |
411abf2d | 93 | } \ |
48fe4ce1 | 94 | static ossl_unused ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \ |
411abf2d | 95 | { \ |
739a1eb1 | 96 | return (t2 *)OPENSSL_sk_shift((OPENSSL_STACK *)sk); \ |
411abf2d | 97 | } \ |
48fe4ce1 | 98 | static ossl_unused ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \ |
411abf2d | 99 | { \ |
739a1eb1 | 100 | OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc)freefunc); \ |
411abf2d | 101 | } \ |
48fe4ce1 | 102 | static ossl_unused ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \ |
411abf2d | 103 | { \ |
36639907 | 104 | return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (const void *)ptr, idx); \ |
411abf2d | 105 | } \ |
48fe4ce1 | 106 | static ossl_unused ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \ |
411abf2d | 107 | { \ |
36639907 | 108 | return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr); \ |
411abf2d | 109 | } \ |
48fe4ce1 | 110 | static ossl_unused ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \ |
411abf2d | 111 | { \ |
4591e5fb | 112 | return OPENSSL_sk_find((OPENSSL_STACK *)sk, (const void *)ptr); \ |
411abf2d | 113 | } \ |
48fe4ce1 | 114 | static ossl_unused ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \ |
411abf2d | 115 | { \ |
4591e5fb | 116 | return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (const void *)ptr); \ |
411abf2d | 117 | } \ |
48fe4ce1 | 118 | static ossl_unused ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \ |
411abf2d | 119 | { \ |
739a1eb1 | 120 | OPENSSL_sk_sort((OPENSSL_STACK *)sk); \ |
411abf2d | 121 | } \ |
48fe4ce1 | 122 | static ossl_unused ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \ |
411abf2d | 123 | { \ |
739a1eb1 | 124 | return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \ |
411abf2d | 125 | } \ |
48fe4ce1 | 126 | static ossl_unused ossl_inline STACK_OF(t1) * sk_##t1##_dup(const STACK_OF(t1) *sk) \ |
411abf2d | 127 | { \ |
c0c9c0c0 | 128 | return (STACK_OF(t1) *)OPENSSL_sk_dup((const OPENSSL_STACK *)sk); \ |
411abf2d | 129 | } \ |
48fe4ce1 | 130 | static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \ |
739a1eb1 RS |
131 | sk_##t1##_copyfunc copyfunc, \ |
132 | sk_##t1##_freefunc freefunc) \ | |
411abf2d | 133 | { \ |
36639907 | 134 | return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((const OPENSSL_STACK *)sk, \ |
739a1eb1 RS |
135 | (OPENSSL_sk_copyfunc)copyfunc, \ |
136 | (OPENSSL_sk_freefunc)freefunc); \ | |
411abf2d | 137 | } \ |
48fe4ce1 | 138 | static ossl_unused ossl_inline sk_##t1##_compfunc sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, sk_##t1##_compfunc compare) \ |
411abf2d | 139 | { \ |
739a1eb1 | 140 | return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \ |
411abf2d DSH |
141 | } |
142 | ||
85885715 | 143 | # define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t) |
852c2ed2 RS |
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) | |
1dcb8ca2 MC |
146 | # define DEFINE_SPECIAL_STACK_OF_CONST(t1, t2) \ |
147 | SKM_DEFINE_STACK_OF(t1, const t2, t2) | |
1d1a6465 | 148 | |
1d97c843 TH |
149 | /*- |
150 | * Strings are special: normally an lhash entry will point to a single | |
5ce278a7 BL |
151 | * (somewhat) mutable object. In the case of strings: |
152 | * | |
153 | * a) Instead of a single char, there is an array of chars, NUL-terminated. | |
154 | * b) The string may have be immutable. | |
155 | * | |
156 | * So, they need their own declarations. Especially important for | |
157 | * type-checking tools, such as Deputy. | |
158 | * | |
1d97c843 | 159 | * In practice, however, it appears to be hard to have a const |
5ce278a7 BL |
160 | * string. For now, I'm settling for dealing with the fact it is a |
161 | * string at all. | |
162 | */ | |
c869da88 | 163 | typedef char *OPENSSL_STRING; |
c869da88 | 164 | typedef const char *OPENSSL_CSTRING; |
5ce278a7 | 165 | |
852c2ed2 RS |
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) | |
170 | ||
171 | /* | |
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. | |
177 | */ | |
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); | |
182 | #else | |
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() | |
186 | #endif | |
187 | ||
5b18d302 | 188 | /*- |
0f113f3e MC |
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. | |
5ce278a7 | 194 | */ |
24c4ea95 MC |
195 | {- |
196 | generate_stack_string_macros() | |
197 | .generate_stack_const_string_macros(); | |
198 | -} | |
5ce278a7 | 199 | |
852c2ed2 | 200 | #if !defined(OPENSSL_NO_DEPRECATED_3_0) |
0f113f3e | 201 | /* |
852c2ed2 | 202 | * This is not used by OpenSSL. A block of bytes, NOT nul-terminated. |
0f113f3e MC |
203 | * These should also be distinguished from "normal" stacks. |
204 | */ | |
512d359e | 205 | typedef void *OPENSSL_BLOCK; |
24c4ea95 MC |
206 | {- |
207 | generate_stack_block_macros(); | |
208 | -} | |
852c2ed2 | 209 | #endif |
5ce278a7 | 210 | |
6638b221 MK |
211 | /* |
212 | * If called without higher optimization (min. -xO3) the Oracle Developer | |
213 | * Studio compiler generates code for the defined (static inline) functions | |
214 | * above. | |
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). | |
218 | */ | |
219 | # ifdef __SUNPRO_C | |
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 */ | |
245 | ||
5b18d302 | 246 | # ifdef __cplusplus |
17e80c6b | 247 | } |
5b18d302 | 248 | # endif |
17e80c6b | 249 | #endif |