]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/crypto/sparse_array.h
Fix header file include guard names
[thirdparty/openssl.git] / include / crypto / sparse_array.h
CommitLineData
a40f0f64
P
1/*
2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
4 *
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
9 */
10
ae4186b0
DMSP
11#ifndef OSSL_CRYPTO_SPARSE_ARRAY_H
12# define OSSL_CRYPTO_SPARSE_ARRAY_H
a40f0f64 13
48fe4ce1
RL
14# include <openssl/e_os2.h>
15
a40f0f64
P
16# ifdef __cplusplus
17extern "C" {
18# endif
19
20# define SPARSE_ARRAY_OF(type) struct sparse_array_st_ ## type
21
ff62cad6 22# define DEFINE_SPARSE_ARRAY_OF_INTERNAL(type, ctype) \
a40f0f64 23 SPARSE_ARRAY_OF(type); \
48fe4ce1 24 static ossl_unused ossl_inline SPARSE_ARRAY_OF(type) * \
a40f0f64
P
25 ossl_sa_##type##_new(void) \
26 { \
27 return (SPARSE_ARRAY_OF(type) *)OPENSSL_SA_new(); \
28 } \
48fe4ce1 29 static ossl_unused ossl_inline void ossl_sa_##type##_free(SPARSE_ARRAY_OF(type) *sa) \
a40f0f64
P
30 { \
31 OPENSSL_SA_free((OPENSSL_SA *)sa); \
32 } \
48fe4ce1 33 static ossl_unused ossl_inline void ossl_sa_##type##_free_leaves(SPARSE_ARRAY_OF(type) *sa) \
a40f0f64
P
34 { \
35 OPENSSL_SA_free_leaves((OPENSSL_SA *)sa); \
36 } \
48fe4ce1 37 static ossl_unused ossl_inline size_t ossl_sa_##type##_num(const SPARSE_ARRAY_OF(type) *sa) \
a40f0f64
P
38 { \
39 return OPENSSL_SA_num((OPENSSL_SA *)sa); \
40 } \
48fe4ce1 41 static ossl_unused ossl_inline void ossl_sa_##type##_doall(const SPARSE_ARRAY_OF(type) *sa, \
8ab53b19
P
42 void (*leaf)(ossl_uintmax_t, \
43 type *)) \
a40f0f64 44 { \
8ab53b19 45 OPENSSL_SA_doall((OPENSSL_SA *)sa, (void (*)(ossl_uintmax_t, void *))leaf); \
a40f0f64 46 } \
48fe4ce1
RL
47 static ossl_unused ossl_inline \
48 void ossl_sa_##type##_doall_arg(const SPARSE_ARRAY_OF(type) *sa, \
8ab53b19 49 void (*leaf)(ossl_uintmax_t, type *, void *), \
48fe4ce1 50 void *arg) \
a40f0f64 51 { \
8ab53b19
P
52 OPENSSL_SA_doall_arg((OPENSSL_SA *)sa, (void (*)(ossl_uintmax_t, void *, \
53 void *))leaf, \
a40f0f64
P
54 arg); \
55 } \
ff62cad6 56 static ossl_unused ossl_inline ctype *ossl_sa_##type##_get(const SPARSE_ARRAY_OF(type) *sa, \
8ab53b19 57 ossl_uintmax_t n) \
a40f0f64
P
58 { \
59 return (type *)OPENSSL_SA_get((OPENSSL_SA *)sa, n); \
60 } \
48fe4ce1 61 static ossl_unused ossl_inline int ossl_sa_##type##_set(SPARSE_ARRAY_OF(type) *sa, \
ff62cad6 62 ossl_uintmax_t n, ctype *val) \
a40f0f64
P
63 { \
64 return OPENSSL_SA_set((OPENSSL_SA *)sa, n, (void *)val); \
65 } \
66 SPARSE_ARRAY_OF(type)
67
ff62cad6
P
68# define DEFINE_SPARSE_ARRAY_OF(type) \
69 DEFINE_SPARSE_ARRAY_OF_INTERNAL(type, type)
70# define DEFINE_SPARSE_ARRAY_OF_CONST(type) \
71 DEFINE_SPARSE_ARRAY_OF_INTERNAL(type, const type)
72
a40f0f64
P
73typedef struct sparse_array_st OPENSSL_SA;
74OPENSSL_SA *OPENSSL_SA_new(void);
75void OPENSSL_SA_free(OPENSSL_SA *sa);
76void OPENSSL_SA_free_leaves(OPENSSL_SA *sa);
77size_t OPENSSL_SA_num(const OPENSSL_SA *sa);
8ab53b19
P
78void OPENSSL_SA_doall(const OPENSSL_SA *sa,
79 void (*leaf)(ossl_uintmax_t, void *));
008b4ff9 80void OPENSSL_SA_doall_arg(const OPENSSL_SA *sa,
8ab53b19
P
81 void (*leaf)(ossl_uintmax_t, void *, void *), void *);
82void *OPENSSL_SA_get(const OPENSSL_SA *sa, ossl_uintmax_t n);
83int OPENSSL_SA_set(OPENSSL_SA *sa, ossl_uintmax_t n, void *val);
a40f0f64
P
84
85# ifdef __cplusplus
86}
87# endif
88#endif