]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/safestack.h.in
Fix typo in CONTRIBUTING.md
[thirdparty/openssl.git] / include / openssl / safestack.h.in
CommitLineData
21dcbebc 1/*
24c4ea95
MC
2 * {- join("\n * ", @autowarntext) -}
3 *
aff636a4 4 * Copyright 1999-2021 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{-
13use 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
31extern "C" {
32#endif
33
0f113f3e 34# define STACK_OF(type) struct stack_st_##type
1d1a6465 35
c6029dea
MC
36/* Helper macro for internal use */
37# define SKM_DEFINE_STACK_OF_INTERNAL(t1, t2, t3) \
38 STACK_OF(t1); \
39 typedef int (*sk_##t1##_compfunc)(const t3 * const *a, const t3 *const *b); \
40 typedef void (*sk_##t1##_freefunc)(t3 *a); \
41 typedef t3 * (*sk_##t1##_copyfunc)(const t3 *a); \
42 static ossl_unused ossl_inline t2 *ossl_check_##t1##_type(t2 *ptr) \
43 { \
44 return ptr; \
45 } \
46 static ossl_unused ossl_inline const OPENSSL_STACK *ossl_check_const_##t1##_sk_type(const STACK_OF(t1) *sk) \
47 { \
48 return (const OPENSSL_STACK *)sk; \
49 } \
50 static ossl_unused ossl_inline OPENSSL_STACK *ossl_check_##t1##_sk_type(STACK_OF(t1) *sk) \
51 { \
52 return (OPENSSL_STACK *)sk; \
53 } \
54 static ossl_unused ossl_inline OPENSSL_sk_compfunc ossl_check_##t1##_compfunc_type(sk_##t1##_compfunc cmp) \
55 { \
56 return (OPENSSL_sk_compfunc)cmp; \
57 } \
58 static ossl_unused ossl_inline OPENSSL_sk_copyfunc ossl_check_##t1##_copyfunc_type(sk_##t1##_copyfunc cpy) \
59 { \
60 return (OPENSSL_sk_copyfunc)cpy; \
61 } \
62 static ossl_unused ossl_inline OPENSSL_sk_freefunc ossl_check_##t1##_freefunc_type(sk_##t1##_freefunc fr) \
63 { \
64 return (OPENSSL_sk_freefunc)fr; \
65 }
66
85885715 67# define SKM_DEFINE_STACK_OF(t1, t2, t3) \
411abf2d 68 STACK_OF(t1); \
739a1eb1
RS
69 typedef int (*sk_##t1##_compfunc)(const t3 * const *a, const t3 *const *b); \
70 typedef void (*sk_##t1##_freefunc)(t3 *a); \
71 typedef t3 * (*sk_##t1##_copyfunc)(const t3 *a); \
48fe4ce1 72 static ossl_unused ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \
411abf2d 73 { \
739a1eb1 74 return OPENSSL_sk_num((const OPENSSL_STACK *)sk); \
411abf2d 75 } \
48fe4ce1 76 static ossl_unused ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \
411abf2d 77 { \
739a1eb1 78 return (t2 *)OPENSSL_sk_value((const OPENSSL_STACK *)sk, idx); \
411abf2d 79 } \
48fe4ce1 80 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \
411abf2d 81 { \
739a1eb1 82 return (STACK_OF(t1) *)OPENSSL_sk_new((OPENSSL_sk_compfunc)compare); \
411abf2d 83 } \
48fe4ce1 84 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \
411abf2d 85 { \
739a1eb1 86 return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \
411abf2d 87 } \
48fe4ce1 88 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_reserve(sk_##t1##_compfunc compare, int n) \
3ceab379
PY
89 { \
90 return (STACK_OF(t1) *)OPENSSL_sk_new_reserve((OPENSSL_sk_compfunc)compare, n); \
91 } \
48fe4ce1 92 static ossl_unused ossl_inline int sk_##t1##_reserve(STACK_OF(t1) *sk, int n) \
1b3e2bbf
P
93 { \
94 return OPENSSL_sk_reserve((OPENSSL_STACK *)sk, n); \
95 } \
48fe4ce1 96 static ossl_unused ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \
411abf2d 97 { \
739a1eb1 98 OPENSSL_sk_free((OPENSSL_STACK *)sk); \
411abf2d 99 } \
48fe4ce1 100 static ossl_unused ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \
411abf2d 101 { \
739a1eb1 102 OPENSSL_sk_zero((OPENSSL_STACK *)sk); \
411abf2d 103 } \
48fe4ce1 104 static ossl_unused ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \
411abf2d 105 { \
739a1eb1 106 return (t2 *)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); \
411abf2d 107 } \
48fe4ce1 108 static ossl_unused ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \
411abf2d 109 { \
4591e5fb
DSH
110 return (t2 *)OPENSSL_sk_delete_ptr((OPENSSL_STACK *)sk, \
111 (const void *)ptr); \
411abf2d 112 } \
48fe4ce1 113 static ossl_unused ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \
411abf2d 114 { \
36639907 115 return OPENSSL_sk_push((OPENSSL_STACK *)sk, (const void *)ptr); \
411abf2d 116 } \
48fe4ce1 117 static ossl_unused ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \
411abf2d 118 { \
36639907 119 return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (const void *)ptr); \
411abf2d 120 } \
48fe4ce1 121 static ossl_unused ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
411abf2d 122 { \
739a1eb1 123 return (t2 *)OPENSSL_sk_pop((OPENSSL_STACK *)sk); \
411abf2d 124 } \
48fe4ce1 125 static ossl_unused ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \
411abf2d 126 { \
739a1eb1 127 return (t2 *)OPENSSL_sk_shift((OPENSSL_STACK *)sk); \
411abf2d 128 } \
48fe4ce1 129 static ossl_unused ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \
411abf2d 130 { \
739a1eb1 131 OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc)freefunc); \
411abf2d 132 } \
48fe4ce1 133 static ossl_unused ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \
411abf2d 134 { \
36639907 135 return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (const void *)ptr, idx); \
411abf2d 136 } \
48fe4ce1 137 static ossl_unused ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \
411abf2d 138 { \
36639907 139 return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr); \
411abf2d 140 } \
48fe4ce1 141 static ossl_unused ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
411abf2d 142 { \
4591e5fb 143 return OPENSSL_sk_find((OPENSSL_STACK *)sk, (const void *)ptr); \
411abf2d 144 } \
48fe4ce1 145 static ossl_unused ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \
411abf2d 146 { \
4591e5fb 147 return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (const void *)ptr); \
411abf2d 148 } \
5fd7eb5c
TM
149 static ossl_unused ossl_inline int sk_##t1##_find_all(STACK_OF(t1) *sk, t2 *ptr, int *pnum) \
150 { \
151 return OPENSSL_sk_find_all((OPENSSL_STACK *)sk, (const void *)ptr, pnum); \
152 } \
48fe4ce1 153 static ossl_unused ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \
411abf2d 154 { \
739a1eb1 155 OPENSSL_sk_sort((OPENSSL_STACK *)sk); \
411abf2d 156 } \
48fe4ce1 157 static ossl_unused ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \
411abf2d 158 { \
739a1eb1 159 return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \
411abf2d 160 } \
48fe4ce1 161 static ossl_unused ossl_inline STACK_OF(t1) * sk_##t1##_dup(const STACK_OF(t1) *sk) \
411abf2d 162 { \
c0c9c0c0 163 return (STACK_OF(t1) *)OPENSSL_sk_dup((const OPENSSL_STACK *)sk); \
411abf2d 164 } \
48fe4ce1 165 static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \
739a1eb1
RS
166 sk_##t1##_copyfunc copyfunc, \
167 sk_##t1##_freefunc freefunc) \
411abf2d 168 { \
36639907 169 return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((const OPENSSL_STACK *)sk, \
739a1eb1
RS
170 (OPENSSL_sk_copyfunc)copyfunc, \
171 (OPENSSL_sk_freefunc)freefunc); \
411abf2d 172 } \
48fe4ce1 173 static ossl_unused ossl_inline sk_##t1##_compfunc sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, sk_##t1##_compfunc compare) \
411abf2d 174 { \
739a1eb1 175 return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \
411abf2d
DSH
176 }
177
85885715 178# define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t)
852c2ed2
RS
179# define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t)
180# define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2)
1dcb8ca2
MC
181# define DEFINE_SPECIAL_STACK_OF_CONST(t1, t2) \
182 SKM_DEFINE_STACK_OF(t1, const t2, t2)
1d1a6465 183
1d97c843
TH
184/*-
185 * Strings are special: normally an lhash entry will point to a single
5ce278a7
BL
186 * (somewhat) mutable object. In the case of strings:
187 *
188 * a) Instead of a single char, there is an array of chars, NUL-terminated.
189 * b) The string may have be immutable.
190 *
191 * So, they need their own declarations. Especially important for
192 * type-checking tools, such as Deputy.
193 *
1d97c843 194 * In practice, however, it appears to be hard to have a const
5ce278a7
BL
195 * string. For now, I'm settling for dealing with the fact it is a
196 * string at all.
197 */
c869da88 198typedef char *OPENSSL_STRING;
c869da88 199typedef const char *OPENSSL_CSTRING;
5ce278a7 200
5b18d302 201/*-
0f113f3e
MC
202 * Confusingly, LHASH_OF(STRING) deals with char ** throughout, but
203 * STACK_OF(STRING) is really more like STACK_OF(char), only, as mentioned
204 * above, instead of a single char each entry is a NUL-terminated array of
205 * chars. So, we have to implement STRING specially for STACK_OF. This is
206 * dealt with in the autogenerated macros below.
5ce278a7 207 */
24c4ea95
MC
208{-
209 generate_stack_string_macros()
210 .generate_stack_const_string_macros();
211-}
5ce278a7 212
852c2ed2 213#if !defined(OPENSSL_NO_DEPRECATED_3_0)
0f113f3e 214/*
852c2ed2 215 * This is not used by OpenSSL. A block of bytes, NOT nul-terminated.
0f113f3e
MC
216 * These should also be distinguished from "normal" stacks.
217 */
512d359e 218typedef void *OPENSSL_BLOCK;
24c4ea95
MC
219{-
220 generate_stack_block_macros();
221-}
852c2ed2 222#endif
5ce278a7 223
5b18d302 224# ifdef __cplusplus
17e80c6b 225}
5b18d302 226# endif
17e80c6b 227#endif